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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-xml-parser",
3
- "version": "5.4.2",
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.0.0",
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 jPath - The jPath of the current tag
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, jPath: string) => boolean) | null;
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, jPath: string) => boolean);
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, jPath, hasAttributes, isLeafNode) => val`
173
+ * Defaults to `(tagName, val, jPathOrMatcher, hasAttributes, isLeafNode) => val`
167
174
  */
168
- tagValueProcessor?: (tagName: string, tagValue: string, jPath: string, hasAttributes: boolean, isLeafNode: boolean) => unknown;
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, jPath) => val`
186
+ * Defaults to `(attrName, val, jPathOrMatcher) => val`
180
187
  */
181
- attributeValueProcessor?: (attrName: string, attrValue: string, jPath: string) => unknown;
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, jPath: string, isLeafNode: boolean, isAttribute: boolean) => boolean;
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, jPath, attrs) => tagName`
293
+ * Defaults to `(tagName, jPathOrMatcher, attrs) => tagName`
280
294
  */
281
- updateTag?: (tagName: string, jPath: string, attrs: { [k: string]: string }) => string | boolean;
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
  };