fast-xml-parser 5.4.2 → 5.5.1
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.
- package/CHANGELOG.md +8 -0
- package/README.md +8 -7
- package/lib/fxbuilder.min.js +1 -1
- package/lib/fxbuilder.min.js.map +1 -1
- package/lib/fxp.cjs +1 -1
- package/lib/fxp.d.cts +46 -19
- package/lib/fxp.min.js +1 -1
- package/lib/fxp.min.js.map +1 -1
- package/lib/fxparser.min.js +1 -1
- package/lib/fxparser.min.js.map +1 -1
- package/package.json +3 -2
- package/src/fxp.d.ts +46 -19
- package/src/xmlparser/OptionsBuilder.js +13 -0
- package/src/xmlparser/OrderedObjParser.js +238 -89
- package/src/xmlparser/XMLParser.js +1 -1
- package/src/xmlparser/node2json.js +65 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fast-xml-parser",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.1",
|
|
4
4
|
"description": "Validate XML, Parse XML, Build XML without C/C++ based libraries",
|
|
5
5
|
"main": "./lib/fxp.cjs",
|
|
6
6
|
"type": "module",
|
|
@@ -87,7 +87,8 @@
|
|
|
87
87
|
}
|
|
88
88
|
],
|
|
89
89
|
"dependencies": {
|
|
90
|
-
"fast-xml-builder": "^1.
|
|
90
|
+
"fast-xml-builder": "^1.1.0",
|
|
91
|
+
"path-expression-matcher": "^1.1.2",
|
|
91
92
|
"strnum": "^2.1.2"
|
|
92
93
|
}
|
|
93
94
|
}
|
package/src/fxp.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Matcher, Expression } from 'path-expression-matcher';
|
|
2
|
+
|
|
1
3
|
export type ProcessEntitiesOptions = {
|
|
2
4
|
/**
|
|
3
5
|
* Whether to enable entity processing
|
|
@@ -53,12 +55,12 @@ export type ProcessEntitiesOptions = {
|
|
|
53
55
|
* Custom filter function to determine if entities should be replaced in a tag
|
|
54
56
|
*
|
|
55
57
|
* @param tagName - The name of the current tag
|
|
56
|
-
* @param
|
|
58
|
+
* @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false)
|
|
57
59
|
* @returns `true` to allow entity replacement, `false` to skip
|
|
58
60
|
*
|
|
59
61
|
* Defaults to `null`
|
|
60
62
|
*/
|
|
61
|
-
tagFilter?: ((tagName: string,
|
|
63
|
+
tagFilter?: ((tagName: string, jPathOrMatcher: string | Matcher) => boolean) | null;
|
|
62
64
|
};
|
|
63
65
|
|
|
64
66
|
export type X2jOptions = {
|
|
@@ -103,7 +105,7 @@ export type X2jOptions = {
|
|
|
103
105
|
*
|
|
104
106
|
* Defaults to `true`
|
|
105
107
|
*/
|
|
106
|
-
ignoreAttributes?: boolean | (string | RegExp)[] | ((attrName: string,
|
|
108
|
+
ignoreAttributes?: boolean | (string | RegExp)[] | ((attrName: string, jPathOrMatcher: string | Matcher) => boolean);
|
|
107
109
|
|
|
108
110
|
/**
|
|
109
111
|
* Whether to remove namespace string from tag and attribute names
|
|
@@ -157,28 +159,33 @@ export type X2jOptions = {
|
|
|
157
159
|
/**
|
|
158
160
|
* Control how tag value should be parsed. Called only if tag value is not empty
|
|
159
161
|
*
|
|
162
|
+
* @param tagName - The name of the tag
|
|
163
|
+
* @param tagValue - The value of the tag
|
|
164
|
+
* @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false)
|
|
165
|
+
* @param hasAttributes - Whether the tag has attributes
|
|
166
|
+
* @param isLeafNode - Whether the tag is a leaf node
|
|
160
167
|
* @returns {undefined|null} `undefined` or `null` to set original value.
|
|
161
168
|
* @returns {unknown}
|
|
162
169
|
*
|
|
163
170
|
* 1. Different value or value with different data type to set new value.
|
|
164
171
|
* 2. Same value to set parsed value if `parseTagValue: true`.
|
|
165
172
|
*
|
|
166
|
-
* Defaults to `(tagName, val,
|
|
173
|
+
* Defaults to `(tagName, val, jPathOrMatcher, hasAttributes, isLeafNode) => val`
|
|
167
174
|
*/
|
|
168
|
-
tagValueProcessor?: (tagName: string, tagValue: string,
|
|
175
|
+
tagValueProcessor?: (tagName: string, tagValue: string, jPathOrMatcher: string | Matcher, hasAttributes: boolean, isLeafNode: boolean) => unknown;
|
|
169
176
|
|
|
170
177
|
/**
|
|
171
178
|
* Control how attribute value should be parsed
|
|
172
179
|
*
|
|
173
|
-
* @param attrName
|
|
174
|
-
* @param attrValue
|
|
175
|
-
* @param jPath
|
|
180
|
+
* @param attrName - The name of the attribute
|
|
181
|
+
* @param attrValue - The value of the attribute
|
|
182
|
+
* @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false)
|
|
176
183
|
* @returns {undefined|null} `undefined` or `null` to set original value
|
|
177
184
|
* @returns {unknown}
|
|
178
185
|
*
|
|
179
|
-
* Defaults to `(attrName, val,
|
|
186
|
+
* Defaults to `(attrName, val, jPathOrMatcher) => val`
|
|
180
187
|
*/
|
|
181
|
-
attributeValueProcessor?: (attrName: string, attrValue: string,
|
|
188
|
+
attributeValueProcessor?: (attrName: string, attrValue: string, jPathOrMatcher: string | Matcher) => unknown;
|
|
182
189
|
|
|
183
190
|
/**
|
|
184
191
|
* Options to pass to `strnum` for parsing numbers
|
|
@@ -190,9 +197,13 @@ export type X2jOptions = {
|
|
|
190
197
|
/**
|
|
191
198
|
* Nodes to stop parsing at
|
|
192
199
|
*
|
|
200
|
+
* Accepts string patterns or Expression objects from path-expression-matcher
|
|
201
|
+
*
|
|
202
|
+
* String patterns starting with "*." are automatically converted to ".." for backward compatibility
|
|
203
|
+
*
|
|
193
204
|
* Defaults to `[]`
|
|
194
205
|
*/
|
|
195
|
-
stopNodes?: string[];
|
|
206
|
+
stopNodes?: (string | Expression)[];
|
|
196
207
|
|
|
197
208
|
/**
|
|
198
209
|
* List of tags without closing tags
|
|
@@ -211,15 +222,15 @@ export type X2jOptions = {
|
|
|
211
222
|
/**
|
|
212
223
|
* Determine whether a tag should be parsed as an array
|
|
213
224
|
*
|
|
214
|
-
* @param tagName
|
|
215
|
-
* @param jPath
|
|
216
|
-
* @param isLeafNode
|
|
217
|
-
* @param isAttribute
|
|
225
|
+
* @param tagName - The name of the tag
|
|
226
|
+
* @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false)
|
|
227
|
+
* @param isLeafNode - Whether the tag is a leaf node
|
|
228
|
+
* @param isAttribute - Whether this is an attribute
|
|
218
229
|
* @returns {boolean}
|
|
219
230
|
*
|
|
220
231
|
* Defaults to `() => false`
|
|
221
232
|
*/
|
|
222
|
-
isArray?: (tagName: string,
|
|
233
|
+
isArray?: (tagName: string, jPathOrMatcher: string | Matcher, isLeafNode: boolean, isAttribute: boolean) => boolean;
|
|
223
234
|
|
|
224
235
|
/**
|
|
225
236
|
* Whether to process default and DOCTYPE entities
|
|
@@ -273,12 +284,15 @@ export type X2jOptions = {
|
|
|
273
284
|
* Change the tag name when a different name is returned. Skip the tag from parsed result when false is returned.
|
|
274
285
|
* Modify `attrs` object to control attributes for the given tag.
|
|
275
286
|
*
|
|
287
|
+
* @param tagName - The name of the tag
|
|
288
|
+
* @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false)
|
|
289
|
+
* @param attrs - The attributes object
|
|
276
290
|
* @returns {string} new tag name.
|
|
277
291
|
* @returns false to skip the tag
|
|
278
292
|
*
|
|
279
|
-
* Defaults to `(tagName,
|
|
293
|
+
* Defaults to `(tagName, jPathOrMatcher, attrs) => tagName`
|
|
280
294
|
*/
|
|
281
|
-
updateTag?: (tagName: string,
|
|
295
|
+
updateTag?: (tagName: string, jPathOrMatcher: string | Matcher, attrs: { [k: string]: string }) => string | boolean;
|
|
282
296
|
|
|
283
297
|
/**
|
|
284
298
|
* If true, adds a Symbol to all object nodes, accessible by {@link XMLParser.getMetaDataSymbol} with
|
|
@@ -299,6 +313,17 @@ export type X2jOptions = {
|
|
|
299
313
|
* Defaults to `true`
|
|
300
314
|
*/
|
|
301
315
|
strictReservedNames?: boolean;
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Controls whether callbacks receive jPath as string or Matcher instance
|
|
319
|
+
*
|
|
320
|
+
* When `true` - callbacks receive jPath as string (backward compatible)
|
|
321
|
+
*
|
|
322
|
+
* When `false` - callbacks receive Matcher instance for advanced pattern matching
|
|
323
|
+
*
|
|
324
|
+
* Defaults to `true`
|
|
325
|
+
*/
|
|
326
|
+
jPath?: boolean;
|
|
302
327
|
};
|
|
303
328
|
|
|
304
329
|
|
|
@@ -437,9 +462,11 @@ export type XmlBuilderOptions = {
|
|
|
437
462
|
/**
|
|
438
463
|
* Nodes to stop parsing at
|
|
439
464
|
*
|
|
465
|
+
* Accepts string patterns or Expression objects from path-expression-matcher
|
|
466
|
+
*
|
|
440
467
|
* Defaults to `[]`
|
|
441
468
|
*/
|
|
442
|
-
stopNodes?: string[];
|
|
469
|
+
stopNodes?: (string | Expression)[];
|
|
443
470
|
|
|
444
471
|
/**
|
|
445
472
|
* Control how tag value should be parsed. Called only if tag value is not empty
|
|
@@ -40,6 +40,7 @@ export const defaultOptions = {
|
|
|
40
40
|
captureMetaData: false,
|
|
41
41
|
maxNestedTags: 100,
|
|
42
42
|
strictReservedNames: true,
|
|
43
|
+
jPath: true, // if true, pass jPath string to callbacks; if false, pass matcher instance
|
|
43
44
|
};
|
|
44
45
|
|
|
45
46
|
/**
|
|
@@ -85,6 +86,18 @@ export const buildOptions = function (options) {
|
|
|
85
86
|
|
|
86
87
|
// Always normalize processEntities for backward compatibility and validation
|
|
87
88
|
built.processEntities = normalizeProcessEntities(built.processEntities);
|
|
89
|
+
|
|
90
|
+
// Convert old-style stopNodes for backward compatibility
|
|
91
|
+
if (built.stopNodes && Array.isArray(built.stopNodes)) {
|
|
92
|
+
built.stopNodes = built.stopNodes.map(node => {
|
|
93
|
+
if (typeof node === 'string' && node.startsWith('*.')) {
|
|
94
|
+
// Old syntax: *.tagname meant "tagname anywhere"
|
|
95
|
+
// Convert to new syntax: ..tagname
|
|
96
|
+
return '..' + node.substring(2);
|
|
97
|
+
}
|
|
98
|
+
return node;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
88
101
|
//console.debug(built.processEntities)
|
|
89
102
|
return built;
|
|
90
103
|
};
|