-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.d.ts
149 lines (142 loc) · 5.46 KB
/
types.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
export type StanzaClass = any;
export type Stanza = any;
export type XML = any;
export interface JXTUtils {
parse(str: string): XML;
createElement(namespace: string, name: string, parentNamespace?: string): XML;
find(xml: XML, namespace: string, selector: string): XML[];
findOrCreate(xml: XML, namespace: string, selector: string): XML;
getAttribute(xml: XML, name: string, defaultValue?: string): string;
getAttributeNS(xml: XML, namespace: string, name: string, defaultValue?: string): string;
setAttribute(xml: XML, name: string, value: any, force?: boolean): void;
setAttributeNS(xml: XML, namespace: string, name: string, value: any, force?: boolean): void;
getBoolAttribute(xml: XML, name: string, defaultValue?: boolean): boolean;
setBoolAttribute(xml: XML, name: string, value: boolean): void;
getSubAttribute(
xml: XML,
namespace: string,
element: string,
name: string,
defaultValue?: string
): string;
setSubAttribute(
xml: XML,
namespace: string,
element: string,
name: string,
value: string
): void;
getBoolSubAttribute(
xml: XML,
namespace: string,
element: string,
name: string,
defaultValue?: boolean
): boolean;
setBoolSubAttribute(
xml: XML,
namespace: string,
element: string,
name: string,
value: boolean
): void;
getText(xml: XML): string;
setText(xml: XML, text: string): void;
getSubText(xml: XML, namespace: string, element: string, defaultValue?: string): string;
setSubText(xml: XML, namespace: string, element: string, value: string): void;
getMultiSubText(
xml: XML,
namespace: string,
element: string,
extractor?: (xml: XML) => string
): string[];
setMultiSubText(
xml: XML,
namespace: string,
element: string,
value: string | string[],
builder?: (xml: XML, value: string) => void
): void;
getMultiSubAttribute(xml: XML, namespace: string, element: string, name: string): string[];
setMultiSubAttribute(
xml: XML,
namespace: string,
element: string,
name: string,
value: string[]
): void;
getSubLangText(xml: XML, namespace: string, element: string, defaultLang?: string): string;
setSubLangText(
xml: XML,
namespace: string,
element: string,
value: string,
defaultLang?: string
): void;
getBoolSub(xml: XML, namespace: string, element: string): boolean;
setBoolSub(xml: XML, namespace: string, element: string, value: boolean): void;
field(getter: Function, setter: Function): Field;
boolAttribute(name: string): Field;
subAttribute(namespace: string, element: string, name: string): Field;
boolSubAttribute(namespace: string, element: string, name: string): Field;
text(): Field;
textSub(namespace: string, element: string): Field;
multiTextSub(namespace: string, element: string): Field;
multiSubAttribute(namespace: string, element: string, name: string): Field;
langTextSub(namespace: string, element: string, defaultValue?: string): Field;
boolSub(namespace: string, element: string): Field;
langAttribute(): Field;
b64Text(): Field;
dateAttribute(name: string, now?: boolean): Field;
dateSub(namespace: string, element: string, now?: boolean): Field;
dateSubAttribute(namespace: string, element: string, name: string, now?: boolean): Field;
numberAttribute(name: string, isFloat?: boolean, defaultVlaue?: number): Field;
numberSub(namespace: string, element: string, isFloat?: boolean, defaultValue?: number): Field;
attribute(name: string, defaultValue?: string): Field;
attributeNS(namespace: string, name: string, defaultValue?: string): Field;
extension(stanza: StanzaClass): Field;
multiExtension(stanza: StanzaClass): Field;
enumSub(namespace: string, values: string[]): Field;
subExtension(name: string, namespace: string, element: string, stanza: StanzaClass): Field;
subMultiExtension(namespace: string, element: string, stanza: StanzaClass): Field;
}
export interface Field {
get?: () => any;
set?: (value: any) => void;
value?: any;
}
export default class JXT {
public utils: JXTUtils;
public static createRegistry(): JXT;
public use(init: (jxt: JXT) => void): void;
public getDefinition(element: string, namespace: string, required?: boolean): StanzaClass;
public getExtensions(element: string, namespace: string): StanzaClass[];
public withDefinition(
element: string,
namespace: string,
handler: (stanza: Stanza) => void
): void;
public withTag(tag: string, handler: (stanza: Stanza) => void): void;
public tagged(tag: string): Stanza[];
public build(xml: XML): Stanza;
public parse(str: string): XML;
public extend(
parentJXT: StanzaClass,
childJXT: StanzaClass,
multiName?: string,
hideSingle?: boolean
): void;
public add(parentJXT: StanzaClass, fieldName: string, field: any): void;
public define(opts: {
name: string;
namespace: string;
element?: string;
prefixes?: { [key: string]: string };
tags?: string[];
topLevel?: boolean;
eventName?: string;
init?: (self: Stanza, data: any) => void;
fields?: { [key: string]: Field };
}): StanzaClass;
}
export function createRegistry(): JXT;