-
Notifications
You must be signed in to change notification settings - Fork 7
/
cruftless.d.ts
73 lines (64 loc) · 2.09 KB
/
cruftless.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
declare module "cruftless" {
export type CruftlessTypes = Record<string, CruftlessType<any>>;
/**
* For primitives, you can register type definitions that are able to convert
* between the encoded representation and the data representation used in the
* data model.
*/
export interface CruftlessType<T> {
/**
* How the type is referenced in your template.
*/
type: string;
/**
* How the type converted from its encoded representation to in memory representation.
*/
from: (str: string) => T;
/**
* How it's converted from the in-memory representation to its XML representation.
*/
to: (value: T) => string;
/**
* A snippet of RelaxNG describing the type.
*/
relaxng: (...args: any[]) => Template<unknown>;
}
export interface CruftlessOpts {
types: CruftlessTypes;
/**
* The name of the property that holds the name of the polymorphic variant
* of a content model. Used in case of xsi:type.
*/
kindProperty?: string;
/**
* Prefix mapping for namespaces. Prefixes are the keys, namespaces are the values.
* Used for xsi:type canonicalization.
*/
prefixes?: Record<string, string>;
}
export interface Cruftless {
parse: ParseFn;
element: ElementFn;
attr: AttrFn;
relaxng: RelaxNGFn;
text: TextFn;
}
export interface Template<T> {
toXML: (...args: any[]) => string;
fromXML: (xml: string, raw?: boolean) => T;
toDOM: (...args: any[]) => Document;
fromDOM: (dom: Document, raw?: boolean) => T;
name: () => string;
}
export type ParseFn = <T>(xml: string, resolve?: ResolveFn) => Template<T>;
export type ElementFn = (name: string) => Element;
export type AttrFn = (name: string) => Attr;
export type RelaxNGFn = <T>(template: Template<T>, ...args: any[]) => string;
export type TextFn = () => Text;
export type ResolveFn = (href: string) => [string, ResolveFn];
export type Element = any;
export type Attr = any;
export type Text = any;
function cruftless(opts: CruftlessOpts): Cruftless;
export default cruftless;
}