corrade-nucleus-nucleons – Blame information for rev 37
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
37 | office | 1 | /** |
2 | * Transforms between XML string and JavaScript object trees. |
||
3 | * |
||
4 | * @class X2JS |
||
5 | */ |
||
6 | declare class X2JS { |
||
7 | |||
8 | /** |
||
9 | * Creates an instance of X2JS. |
||
10 | * |
||
11 | * @param {X2JS.Options} [config] |
||
12 | * |
||
13 | * @memberOf X2JS |
||
14 | */ |
||
15 | constructor(config?: X2JS.Options); |
||
16 | |||
17 | /** |
||
18 | * Converts the provided property into an array. If the property is already an Array then it will return unchanged. |
||
19 | * |
||
20 | * @template T |
||
21 | * @param {(T | Array<T>)} prop |
||
22 | * @returns {Array<T>} |
||
23 | * |
||
24 | * @memberOf X2JS |
||
25 | */ |
||
26 | asArray<T>(prop: T | Array<T>): Array<T>; |
||
27 | |||
28 | /** |
||
29 | * Converts the provided date value to a valid XML string. |
||
30 | * |
||
31 | * @param {(Date | number)} dt |
||
32 | * @returns {string} |
||
33 | * |
||
34 | * @memberOf X2JS |
||
35 | */ |
||
36 | toXmlDateTime(dt: Date | number): string; |
||
37 | |||
38 | /** |
||
39 | * Converts the provided date string into a javascript Date instance. |
||
40 | * |
||
41 | * @param {string} prop |
||
42 | * @returns {Date} |
||
43 | * |
||
44 | * @memberOf X2JS |
||
45 | */ |
||
46 | asDateTime(prop: string): Date; |
||
47 | |||
48 | /** |
||
49 | * Transformns an XML string into DOM-tree |
||
50 | * |
||
51 | * @param {string} xml |
||
52 | * @returns {Node} |
||
53 | * |
||
54 | * @memberOf X2JS |
||
55 | */ |
||
56 | xml2dom(xml: string): Document; |
||
57 | |||
58 | |||
59 | /** |
||
60 | * Transforms a DOM tree to JavaScript objects. |
||
61 | * |
||
62 | * @template T |
||
63 | * @param {Node} domNode |
||
64 | * @returns {T} |
||
65 | * |
||
66 | * @memberOf X2JS |
||
67 | */ |
||
68 | dom2js<T>(domNode: Document): T; |
||
69 | |||
70 | /** |
||
71 | * |
||
72 | * |
||
73 | * @template T |
||
74 | * @param {T} jsObject |
||
75 | * @returns {Node} |
||
76 | * |
||
77 | * @memberOf X2JS |
||
78 | */ |
||
79 | js2dom<T>(jsObject: T): Document; |
||
80 | |||
81 | /** |
||
82 | * Transformns an XML string into JavaScript objects. |
||
83 | * |
||
84 | * @template T |
||
85 | * @param {string} xml |
||
86 | * @returns {T} |
||
87 | * |
||
88 | * @memberOf X2JS |
||
89 | */ |
||
90 | xml2js<T>(xml: string): T; |
||
91 | |||
92 | /** |
||
93 | * Transforms JavaScript objects into an XML string. |
||
94 | * |
||
95 | * @template T |
||
96 | * @param {T} json |
||
97 | * @returns {string} |
||
98 | * |
||
99 | * @memberOf X2JS |
||
100 | */ |
||
101 | js2xml<T>(json: T): string; |
||
102 | |||
103 | /** |
||
104 | * Gets the current version of x2js. |
||
105 | * |
||
106 | * @returns {string} |
||
107 | * |
||
108 | * @memberOf X2JS |
||
109 | */ |
||
110 | getVersion(): string; |
||
111 | } |
||
112 | |||
113 | declare namespace X2JS { |
||
114 | export interface Options { |
||
115 | /** |
||
116 | * If set to "property" then <element>_asArray will be created to allow you to access any element as an array (even if there is only one of it). |
||
117 | * |
||
118 | * @type {('property' | 'none')} |
||
119 | * @memberOf X2JS.Options |
||
120 | */ |
||
121 | arrayAccessForm?: 'property' | 'none'; |
||
122 | |||
123 | /** |
||
124 | * If "text" then <empty></empty> will be transformed to "". If "object" then <empty></empty> will be transformed to {}. |
||
125 | * |
||
126 | * @type {('object' | 'text')} |
||
127 | * @memberOf X2JS.Options |
||
128 | */ |
||
129 | emptyNodeForm?: 'object' | 'text'; |
||
130 | |||
131 | /** |
||
132 | * Allows attribute values to be converted on the fly during parsing to objects. |
||
133 | * |
||
134 | * @type {Array<X2JS.AttributeConverter>} |
||
135 | * @memberOf X2JS.Options |
||
136 | */ |
||
137 | attributeConverters?: Array<AttributeConverter>; |
||
138 | |||
139 | /** |
||
140 | * Any elements that match the paths here will have their text parsed as an XML datetime value (2011-11-12T13:00:00-07:00 style). The path can be a plain string (parent.child1.child2), a regex (/.*\.child2/) or function(elementPath). |
||
141 | * |
||
142 | * @type {(Array<string | RegExp | ((elementPath: string) => boolean)>)} |
||
143 | * @memberOf X2JS.Options |
||
144 | */ |
||
145 | datetimeAccessFormPaths?: Array<string | RegExp | ((elementPath: string) => boolean)>; |
||
146 | |||
147 | /** |
||
148 | * Any elements that match the paths listed here will be stored in JavaScript objects as arrays even if there is only one of them. The path can be a plain string (parent.child1.child2), a regex (/.*\.child2/) or function(elementName, elementPath). |
||
149 | * |
||
150 | * @type {(Array<string | RegExp | ((elementName: string, elementPath: string) => boolean)>)} |
||
151 | * @memberOf X2JS.Options |
||
152 | */ |
||
153 | arrayAccessFormPaths?: Array<string | RegExp | ((elementName: string, elementPath: string) => boolean)>; |
||
154 | |||
155 | /** |
||
156 | * If true, a toString function is generated to print nodes containing text or cdata. Useful if you want to accept both plain text and CData as equivalent inputs. |
||
157 | * |
||
158 | * @type {boolean} |
||
159 | * @memberOf X2JS.Options |
||
160 | */ |
||
161 | enableToStringFunc?: boolean; |
||
162 | |||
163 | /** |
||
164 | * If true, empty text tags are ignored for elements with child nodes. |
||
165 | * |
||
166 | * @type {boolean} |
||
167 | * @memberOf X2JS.Options |
||
168 | */ |
||
169 | skipEmptyTextNodesForObj?: boolean; |
||
170 | |||
171 | /** |
||
172 | * If true, whitespace is trimmed from text nodes. |
||
173 | * |
||
174 | * @type {boolean} |
||
175 | * @memberOf X2JS.Options |
||
176 | */ |
||
177 | stripWhitespaces?: boolean; |
||
178 | |||
179 | /** |
||
180 | * If true, double quotes are used in generated XML. |
||
181 | * |
||
182 | * @type {boolean} |
||
183 | * @memberOf X2JS.Options |
||
184 | */ |
||
185 | useDoubleQuotes?: boolean; |
||
186 | |||
187 | /** |
||
188 | * If true, the root element of the XML document is ignored when converting to objects. The result will directly have the root element's children as its own properties. |
||
189 | * |
||
190 | * @type {boolean} |
||
191 | * @memberOf X2JS.Options |
||
192 | */ |
||
193 | ignoreRoot?: boolean; |
||
194 | |||
195 | /** |
||
196 | * Whether XML characters in text are escaped when reading/writing XML. |
||
197 | * |
||
198 | * @type {boolean} |
||
199 | * @memberOf X2JS.Options |
||
200 | */ |
||
201 | escapeMode?: boolean; |
||
202 | |||
203 | /** |
||
204 | * Prefix to use for properties that are created to represent XML attributes. |
||
205 | * |
||
206 | * @type {string} |
||
207 | * @memberOf X2JS.Options |
||
208 | */ |
||
209 | attributePrefix?: string; |
||
210 | |||
211 | /** |
||
212 | * If true, empty elements will created as self closing elements (<element />). If false, empty elements will be created with start and end tags (<element></element>). |
||
213 | * |
||
214 | * @type {boolean} |
||
215 | * @memberOf X2JS.Options |
||
216 | */ |
||
217 | selfClosingElements?: boolean; |
||
218 | |||
219 | /** |
||
220 | * If this property defined as false and an XML element has CData node ONLY, it will be converted to text without additional property "__cdata". |
||
221 | * |
||
222 | * @type {boolean} |
||
223 | * @memberOf X2JS.Options |
||
224 | */ |
||
225 | keepCData?: boolean; |
||
226 | } |
||
227 | |||
228 | export interface AttributeConverter { |
||
229 | /** |
||
230 | * Indicates whether an attribute should be converted. |
||
231 | * |
||
232 | * @param {string} name |
||
233 | * @param {*} value |
||
234 | * @returns {boolean} |
||
235 | * |
||
236 | * @memberOf X2JS.AttributeConverter |
||
237 | */ |
||
238 | test(name: string, value: any): boolean; |
||
239 | |||
240 | /** |
||
241 | * Will be called for every attribute where test() returns true, replacing the original value of the attribute. |
||
242 | * |
||
243 | * @param {string} name |
||
244 | * @param {*} value |
||
245 | * @returns {string} |
||
246 | * |
||
247 | * @memberOf X2JS.AttributeConverter |
||
248 | */ |
||
249 | convert(name: string, value: any): string; |
||
250 | } |
||
251 | } |
||
252 | |||
253 | export = X2JS; |