@depup/fast-xml-parser 5.5.6-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +752 -0
  2. package/LICENSE +21 -0
  3. package/README.md +31 -0
  4. package/changes.json +10 -0
  5. package/lib/fxbuilder.min.js +2 -0
  6. package/lib/fxbuilder.min.js.map +1 -0
  7. package/lib/fxp.cjs +1 -0
  8. package/lib/fxp.d.cts +595 -0
  9. package/lib/fxp.min.js +2 -0
  10. package/lib/fxp.min.js.map +1 -0
  11. package/lib/fxparser.min.js +2 -0
  12. package/lib/fxparser.min.js.map +1 -0
  13. package/lib/fxvalidator.min.js +2 -0
  14. package/lib/fxvalidator.min.js.map +1 -0
  15. package/package.json +112 -0
  16. package/src/cli/cli.js +97 -0
  17. package/src/cli/man.js +17 -0
  18. package/src/cli/read.js +43 -0
  19. package/src/fxp.d.ts +577 -0
  20. package/src/fxp.js +14 -0
  21. package/src/ignoreAttributes.js +18 -0
  22. package/src/util.js +61 -0
  23. package/src/v6/CharsSymbol.js +16 -0
  24. package/src/v6/EntitiesParser.js +106 -0
  25. package/src/v6/OptionsBuilder.js +61 -0
  26. package/src/v6/OutputBuilders/BaseOutputBuilder.js +69 -0
  27. package/src/v6/OutputBuilders/JsArrBuilder.js +103 -0
  28. package/src/v6/OutputBuilders/JsMinArrBuilder.js +100 -0
  29. package/src/v6/OutputBuilders/JsObjBuilder.js +154 -0
  30. package/src/v6/OutputBuilders/ParserOptionsBuilder.js +94 -0
  31. package/src/v6/Report.js +0 -0
  32. package/src/v6/TagPath.js +81 -0
  33. package/src/v6/TagPathMatcher.js +13 -0
  34. package/src/v6/XMLParser.js +83 -0
  35. package/src/v6/Xml2JsParser.js +235 -0
  36. package/src/v6/XmlPartReader.js +210 -0
  37. package/src/v6/XmlSpecialTagsReader.js +111 -0
  38. package/src/v6/inputSource/BufferSource.js +116 -0
  39. package/src/v6/inputSource/StringSource.js +121 -0
  40. package/src/v6/valueParsers/EntitiesParser.js +105 -0
  41. package/src/v6/valueParsers/booleanParser.js +22 -0
  42. package/src/v6/valueParsers/booleanParserExt.js +19 -0
  43. package/src/v6/valueParsers/currency.js +38 -0
  44. package/src/v6/valueParsers/join.js +13 -0
  45. package/src/v6/valueParsers/number.js +14 -0
  46. package/src/v6/valueParsers/trim.js +6 -0
  47. package/src/validator.js +425 -0
  48. package/src/xmlbuilder/json2xml.js +6 -0
  49. package/src/xmlparser/DocTypeReader.js +401 -0
  50. package/src/xmlparser/OptionsBuilder.js +159 -0
  51. package/src/xmlparser/OrderedObjParser.js +905 -0
  52. package/src/xmlparser/XMLParser.js +71 -0
  53. package/src/xmlparser/node2json.js +174 -0
  54. package/src/xmlparser/xmlNode.js +40 -0
package/lib/fxp.d.cts ADDED
@@ -0,0 +1,595 @@
1
+ // import type { Matcher, Expression } from 'path-expression-matcher';
2
+
3
+ type Matcher = unknown;
4
+ type Expression = unknown;
5
+
6
+ type ProcessEntitiesOptions = {
7
+ /**
8
+ * Whether to enable entity processing
9
+ *
10
+ * Defaults to `true`
11
+ */
12
+ enabled?: boolean;
13
+
14
+ /**
15
+ * Maximum size in characters for a single entity definition
16
+ *
17
+ * Defaults to `10000`
18
+ */
19
+ maxEntitySize?: number;
20
+
21
+ /**
22
+ * Maximum depth for nested entity references (reserved for future use)
23
+ *
24
+ * Defaults to `10`
25
+ */
26
+ maxExpansionDepth?: number;
27
+
28
+ /**
29
+ * Maximum total number of entity expansions allowed
30
+ *
31
+ * Defaults to `1000`
32
+ */
33
+ maxTotalExpansions?: number;
34
+
35
+ /**
36
+ * Maximum total expanded content length in characters
37
+ *
38
+ * Defaults to `100000`
39
+ */
40
+ maxExpandedLength?: number;
41
+
42
+ /**
43
+ * Maximum number of entities allowed in the XML
44
+ *
45
+ * Defaults to `100`
46
+ */
47
+ maxEntityCount?: number;
48
+
49
+ /**
50
+ * Array of tag names where entity replacement is allowed.
51
+ * If null, entities are replaced in all tags.
52
+ *
53
+ * Defaults to `null`
54
+ */
55
+ allowedTags?: string[] | null;
56
+
57
+ /**
58
+ * Custom filter function to determine if entities should be replaced in a tag
59
+ *
60
+ * @param tagName - The name of the current tag
61
+ * @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false)
62
+ * @returns `true` to allow entity replacement, `false` to skip
63
+ *
64
+ * Defaults to `null`
65
+ */
66
+ tagFilter?: ((tagName: string, jPathOrMatcher: string | Matcher) => boolean) | null;
67
+ };
68
+
69
+ type X2jOptions = {
70
+ /**
71
+ * Preserve the order of tags in resulting JS object
72
+ *
73
+ * Defaults to `false`
74
+ */
75
+ preserveOrder?: boolean;
76
+
77
+ /**
78
+ * Give a prefix to the attribute name in the resulting JS object
79
+ *
80
+ * Defaults to '@_'
81
+ */
82
+ attributeNamePrefix?: string;
83
+
84
+ /**
85
+ * A name to group all attributes of a tag under, or `false` to disable
86
+ *
87
+ * Defaults to `false`
88
+ */
89
+ attributesGroupName?: false | string;
90
+
91
+ /**
92
+ * The name of the next node in the resulting JS
93
+ *
94
+ * Defaults to `#text`
95
+ */
96
+ textNodeName?: string;
97
+
98
+ /**
99
+ * Whether to ignore attributes when parsing
100
+ *
101
+ * When `true` - ignores all the attributes
102
+ *
103
+ * When `false` - parses all the attributes
104
+ *
105
+ * When `Array<string | RegExp>` - filters out attributes that match provided patterns
106
+ *
107
+ * When `Function` - calls the function for each attribute and filters out those for which the function returned `true`
108
+ *
109
+ * Defaults to `true`
110
+ */
111
+ ignoreAttributes?: boolean | (string | RegExp)[] | ((attrName: string, jPathOrMatcher: string | Matcher) => boolean);
112
+
113
+ /**
114
+ * Whether to remove namespace string from tag and attribute names
115
+ *
116
+ * Defaults to `false`
117
+ */
118
+ removeNSPrefix?: boolean;
119
+
120
+ /**
121
+ * Whether to allow attributes without value
122
+ *
123
+ * Defaults to `false`
124
+ */
125
+ allowBooleanAttributes?: boolean;
126
+
127
+ /**
128
+ * Whether to parse tag value with `strnum` package
129
+ *
130
+ * Defaults to `true`
131
+ */
132
+ parseTagValue?: boolean;
133
+
134
+ /**
135
+ * Whether to parse attribute value with `strnum` package
136
+ *
137
+ * Defaults to `false`
138
+ */
139
+ parseAttributeValue?: boolean;
140
+
141
+ /**
142
+ * Whether to remove surrounding whitespace from tag or attribute value
143
+ *
144
+ * Defaults to `true`
145
+ */
146
+ trimValues?: boolean;
147
+
148
+ /**
149
+ * Give a property name to set CDATA values to instead of merging to tag's text value
150
+ *
151
+ * Defaults to `false`
152
+ */
153
+ cdataPropName?: false | string;
154
+
155
+ /**
156
+ * If set, parse comments and set as this property
157
+ *
158
+ * Defaults to `false`
159
+ */
160
+ commentPropName?: false | string;
161
+
162
+ /**
163
+ * Control how tag value should be parsed. Called only if tag value is not empty
164
+ *
165
+ * @param tagName - The name of the tag
166
+ * @param tagValue - The value of the tag
167
+ * @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false)
168
+ * @param hasAttributes - Whether the tag has attributes
169
+ * @param isLeafNode - Whether the tag is a leaf node
170
+ * @returns {undefined|null} `undefined` or `null` to set original value.
171
+ * @returns {unknown}
172
+ *
173
+ * 1. Different value or value with different data type to set new value.
174
+ * 2. Same value to set parsed value if `parseTagValue: true`.
175
+ *
176
+ * Defaults to `(tagName, val, jPathOrMatcher, hasAttributes, isLeafNode) => val`
177
+ */
178
+ tagValueProcessor?: (tagName: string, tagValue: string, jPathOrMatcher: string | Matcher, hasAttributes: boolean, isLeafNode: boolean) => unknown;
179
+
180
+ /**
181
+ * Control how attribute value should be parsed
182
+ *
183
+ * @param attrName - The name of the attribute
184
+ * @param attrValue - The value of the attribute
185
+ * @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false)
186
+ * @returns {undefined|null} `undefined` or `null` to set original value
187
+ * @returns {unknown}
188
+ *
189
+ * Defaults to `(attrName, val, jPathOrMatcher) => val`
190
+ */
191
+ attributeValueProcessor?: (attrName: string, attrValue: string, jPathOrMatcher: string | Matcher) => unknown;
192
+
193
+ /**
194
+ * Options to pass to `strnum` for parsing numbers
195
+ *
196
+ * Defaults to `{ hex: true, leadingZeros: true, eNotation: true }`
197
+ */
198
+ numberParseOptions?: strnumOptions;
199
+
200
+ /**
201
+ * Nodes to stop parsing at
202
+ *
203
+ * Accepts string patterns or Expression objects from path-expression-matcher
204
+ *
205
+ * String patterns starting with "*." are automatically converted to ".." for backward compatibility
206
+ *
207
+ * Defaults to `[]`
208
+ */
209
+ stopNodes?: (string | Expression)[];
210
+
211
+ /**
212
+ * List of tags without closing tags
213
+ *
214
+ * Defaults to `[]`
215
+ */
216
+ unpairedTags?: string[];
217
+
218
+ /**
219
+ * Whether to always create a text node
220
+ *
221
+ * Defaults to `false`
222
+ */
223
+ alwaysCreateTextNode?: boolean;
224
+
225
+ /**
226
+ * Determine whether a tag should be parsed as an array
227
+ *
228
+ * @param tagName - The name of the tag
229
+ * @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false)
230
+ * @param isLeafNode - Whether the tag is a leaf node
231
+ * @param isAttribute - Whether this is an attribute
232
+ * @returns {boolean}
233
+ *
234
+ * Defaults to `() => false`
235
+ */
236
+ isArray?: (tagName: string, jPathOrMatcher: string | Matcher, isLeafNode: boolean, isAttribute: boolean) => boolean;
237
+
238
+ /**
239
+ * Whether to process default and DOCTYPE entities
240
+ *
241
+ * When `true` - enables entity processing with default limits
242
+ *
243
+ * When `false` - disables all entity processing
244
+ *
245
+ * When `ProcessEntitiesOptions` - enables entity processing with custom configuration
246
+ *
247
+ * Defaults to `true`
248
+ */
249
+ processEntities?: boolean | ProcessEntitiesOptions;
250
+
251
+ /**
252
+ * Whether to process HTML entities
253
+ *
254
+ * Defaults to `false`
255
+ */
256
+ htmlEntities?: boolean;
257
+
258
+ /**
259
+ * Whether to ignore the declaration tag from output
260
+ *
261
+ * Defaults to `false`
262
+ */
263
+ ignoreDeclaration?: boolean;
264
+
265
+ /**
266
+ * Whether to ignore Pi tags
267
+ *
268
+ * Defaults to `false`
269
+ */
270
+ ignorePiTags?: boolean;
271
+
272
+ /**
273
+ * Transform tag names
274
+ *
275
+ * Defaults to `false`
276
+ */
277
+ transformTagName?: ((tagName: string) => string) | false;
278
+
279
+ /**
280
+ * Transform attribute names
281
+ *
282
+ * Defaults to `false`
283
+ */
284
+ transformAttributeName?: ((attributeName: string) => string) | false;
285
+
286
+ /**
287
+ * Change the tag name when a different name is returned. Skip the tag from parsed result when false is returned.
288
+ * Modify `attrs` object to control attributes for the given tag.
289
+ *
290
+ * @param tagName - The name of the tag
291
+ * @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false)
292
+ * @param attrs - The attributes object
293
+ * @returns {string} new tag name.
294
+ * @returns false to skip the tag
295
+ *
296
+ * Defaults to `(tagName, jPathOrMatcher, attrs) => tagName`
297
+ */
298
+ updateTag?: (tagName: string, jPathOrMatcher: string | Matcher, attrs: { [k: string]: string }) => string | boolean;
299
+
300
+ /**
301
+ * If true, adds a Symbol to all object nodes, accessible by {@link XMLParser.getMetaDataSymbol} with
302
+ * metadata about each the node in the XML file.
303
+ */
304
+ captureMetaData?: boolean;
305
+
306
+ /**
307
+ * Maximum number of nested tags
308
+ *
309
+ * Defaults to `100`
310
+ */
311
+ maxNestedTags?: number;
312
+
313
+ /**
314
+ * Whether to strictly validate tag names
315
+ *
316
+ * Defaults to `true`
317
+ */
318
+ strictReservedNames?: boolean;
319
+
320
+ /**
321
+ * Controls whether callbacks receive jPath as string or Matcher instance
322
+ *
323
+ * When `true` - callbacks receive jPath as string (backward compatible)
324
+ *
325
+ * When `false` - callbacks receive Matcher instance for advanced pattern matching
326
+ *
327
+ * Defaults to `true`
328
+ */
329
+ jPath?: boolean;
330
+
331
+ /**
332
+ * Function to sanitize dangerous property names
333
+ *
334
+ * @param name - The name of the property
335
+ * @returns {string} The sanitized name
336
+ *
337
+ * Defaults to `(name) => __name`
338
+ */
339
+ onDangerousProperty?: (name: string) => string;
340
+ };
341
+
342
+ type strnumOptions = {
343
+ hex: boolean;
344
+ leadingZeros: boolean,
345
+ skipLike?: RegExp,
346
+ eNotation?: boolean
347
+ }
348
+
349
+ type validationOptions = {
350
+ /**
351
+ * Whether to allow attributes without value
352
+ *
353
+ * Defaults to `false`
354
+ */
355
+ allowBooleanAttributes?: boolean;
356
+
357
+ /**
358
+ * List of tags without closing tags
359
+ *
360
+ * Defaults to `[]`
361
+ */
362
+ unpairedTags?: string[];
363
+ };
364
+
365
+ type XmlBuilderOptions = {
366
+ /**
367
+ * Give a prefix to the attribute name in the resulting JS object
368
+ *
369
+ * Defaults to '@_'
370
+ */
371
+ attributeNamePrefix?: string;
372
+
373
+ /**
374
+ * A name to group all attributes of a tag under, or `false` to disable
375
+ *
376
+ * Defaults to `false`
377
+ */
378
+ attributesGroupName?: false | string;
379
+
380
+ /**
381
+ * The name of the next node in the resulting JS
382
+ *
383
+ * Defaults to `#text`
384
+ */
385
+ textNodeName?: string;
386
+
387
+ /**
388
+ * Whether to ignore attributes when building
389
+ *
390
+ * When `true` - ignores all the attributes
391
+ *
392
+ * When `false` - builds all the attributes
393
+ *
394
+ * When `Array<string | RegExp>` - filters out attributes that match provided patterns
395
+ *
396
+ * When `Function` - calls the function for each attribute and filters out those for which the function returned `true`
397
+ *
398
+ * Defaults to `true`
399
+ */
400
+ ignoreAttributes?: boolean | (string | RegExp)[] | ((attrName: string, jPath: string) => boolean);
401
+
402
+ /**
403
+ * Give a property name to set CDATA values to instead of merging to tag's text value
404
+ *
405
+ * Defaults to `false`
406
+ */
407
+ cdataPropName?: false | string;
408
+
409
+ /**
410
+ * If set, parse comments and set as this property
411
+ *
412
+ * Defaults to `false`
413
+ */
414
+ commentPropName?: false | string;
415
+
416
+ /**
417
+ * Whether to make output pretty instead of single line
418
+ *
419
+ * Defaults to `false`
420
+ */
421
+ format?: boolean;
422
+
423
+
424
+ /**
425
+ * If `format` is set to `true`, sets the indent string
426
+ *
427
+ * Defaults to ` `
428
+ */
429
+ indentBy?: string;
430
+
431
+ /**
432
+ * Give a name to a top-level array
433
+ *
434
+ * Defaults to `undefined`
435
+ */
436
+ arrayNodeName?: string;
437
+
438
+ /**
439
+ * Create empty tags for tags with no text value
440
+ *
441
+ * Defaults to `false`
442
+ */
443
+ suppressEmptyNode?: boolean;
444
+
445
+ /**
446
+ * Suppress an unpaired tag
447
+ *
448
+ * Defaults to `true`
449
+ */
450
+ suppressUnpairedNode?: boolean;
451
+
452
+ /**
453
+ * Don't put a value for boolean attributes
454
+ *
455
+ * Defaults to `true`
456
+ */
457
+ suppressBooleanAttributes?: boolean;
458
+
459
+ /**
460
+ * Preserve the order of tags in resulting JS object
461
+ *
462
+ * Defaults to `false`
463
+ */
464
+ preserveOrder?: boolean;
465
+
466
+ /**
467
+ * List of tags without closing tags
468
+ *
469
+ * Defaults to `[]`
470
+ */
471
+ unpairedTags?: string[];
472
+
473
+ /**
474
+ * Nodes to stop parsing at
475
+ *
476
+ * Accepts string patterns or Expression objects from path-expression-matcher
477
+ *
478
+ * Defaults to `[]`
479
+ */
480
+ stopNodes?: (string | Expression)[];
481
+
482
+ /**
483
+ * Control how tag value should be parsed. Called only if tag value is not empty
484
+ *
485
+ * @returns {undefined|null} `undefined` or `null` to set original value.
486
+ * @returns {unknown}
487
+ *
488
+ * 1. Different value or value with different data type to set new value.
489
+ * 2. Same value to set parsed value if `parseTagValue: true`.
490
+ *
491
+ * Defaults to `(tagName, val, jPath, hasAttributes, isLeafNode) => val`
492
+ */
493
+ tagValueProcessor?: (name: string, value: unknown) => unknown;
494
+
495
+ /**
496
+ * Control how attribute value should be parsed
497
+ *
498
+ * @param attrName
499
+ * @param attrValue
500
+ * @param jPath
501
+ * @returns {undefined|null} `undefined` or `null` to set original value
502
+ * @returns {unknown}
503
+ *
504
+ * Defaults to `(attrName, val, jPath) => val`
505
+ */
506
+ attributeValueProcessor?: (name: string, value: unknown) => unknown;
507
+
508
+ /**
509
+ * Whether to process default and DOCTYPE entities
510
+ *
511
+ * Defaults to `true`
512
+ */
513
+ processEntities?: boolean;
514
+
515
+
516
+ oneListGroup?: boolean;
517
+
518
+ /**
519
+ * Maximum number of nested tags
520
+ *
521
+ * Defaults to `100`
522
+ */
523
+ maxNestedTags?: number;
524
+ };
525
+
526
+ type ESchema = string | object | Array<string | object>;
527
+
528
+ type ValidationError = {
529
+ err: {
530
+ code: string;
531
+ msg: string,
532
+ line: number,
533
+ col: number
534
+ };
535
+ };
536
+
537
+ declare class XMLParser {
538
+ constructor(options?: X2jOptions);
539
+ parse(xmlData: string | Uint8Array, validationOptions?: validationOptions | boolean): any;
540
+ /**
541
+ * Add Entity which is not by default supported by this library
542
+ * @param entityIdentifier {string} Eg: 'ent' for &ent;
543
+ * @param entityValue {string} Eg: '\r'
544
+ */
545
+ addEntity(entityIdentifier: string, entityValue: string): void;
546
+
547
+ /**
548
+ * Returns a Symbol that can be used to access the {@link XMLMetaData}
549
+ * property on a node.
550
+ *
551
+ * If Symbol is not available in the environment, an ordinary property is used
552
+ * and the name of the property is here returned.
553
+ *
554
+ * The XMLMetaData property is only present when {@link X2jOptions.captureMetaData}
555
+ * is true in the options.
556
+ */
557
+ static getMetaDataSymbol(): Symbol;
558
+ }
559
+
560
+ declare class XMLValidator {
561
+ static validate(xmlData: string, options?: validationOptions): true | ValidationError;
562
+ }
563
+
564
+ declare class XMLBuilder {
565
+ constructor(options?: XmlBuilderOptions);
566
+ build(jObj: any): string;
567
+ }
568
+
569
+
570
+ /**
571
+ * This object is available on nodes via the symbol {@link XMLParser.getMetaDataSymbol}
572
+ * when {@link X2jOptions.captureMetaData} is true.
573
+ */
574
+ declare interface XMLMetaData {
575
+ /** The index, if available, of the character where the XML node began in the input stream. */
576
+ startIndex?: number;
577
+ }
578
+
579
+ declare namespace fxp {
580
+ export {
581
+ XMLParser,
582
+ XMLValidator,
583
+ XMLBuilder,
584
+ XMLMetaData,
585
+ XmlBuilderOptions,
586
+ X2jOptions,
587
+ ESchema,
588
+ ValidationError,
589
+ strnumOptions,
590
+ validationOptions,
591
+ ProcessEntitiesOptions,
592
+ }
593
+ }
594
+
595
+ export = fxp;