projen-pipelines 0.3.21 → 0.3.23
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/.jsii +7 -4
- package/API.md +420 -0
- package/lib/assign-approver/base.js +3 -4
- package/lib/assign-approver/github.js +4 -4
- package/lib/awscdk/base.js +48 -6
- package/lib/awscdk/bash.js +2 -4
- package/lib/awscdk/github.js +13 -6
- package/lib/awscdk/gitlab.js +11 -6
- package/lib/drift/base.js +8 -4
- package/lib/drift/bash.js +3 -4
- package/lib/drift/detect-drift.js +3 -2
- package/lib/drift/github.js +5 -4
- package/lib/drift/gitlab.js +5 -4
- package/lib/drift/step.js +2 -4
- package/lib/release.js +5 -2
- package/lib/steps/amplify-deploy.step.js +5 -4
- package/lib/steps/artifact-steps.js +5 -6
- package/lib/steps/aws-assume-role.step.js +3 -4
- package/lib/steps/github-summary.step.js +3 -4
- package/lib/steps/package-manager-setup.step.js +4 -6
- package/lib/steps/registries.js +7 -8
- package/lib/steps/set-env.step.js +2 -1
- package/lib/steps/step.js +9 -10
- package/lib/versioning/computation.js +6 -8
- package/lib/versioning/config.js +3 -6
- package/lib/versioning/outputs.js +13 -16
- package/lib/versioning/setup.js +9 -9
- package/lib/versioning/strategy.js +4 -4
- package/lib/versioning/version-info.js +18 -9
- package/node_modules/@babel/code-frame/package.json +2 -2
- package/node_modules/@babel/helper-validator-identifier/package.json +1 -1
- package/node_modules/@nodable/entities/README.md +52 -1
- package/node_modules/@nodable/entities/package.json +4 -1
- package/node_modules/@nodable/entities/src/EntityDecoder.js +105 -4
- package/node_modules/@nodable/entities/src/EntityEncoder.js +79 -34
- package/node_modules/@nodable/entities/src/all-entities.js +53 -0
- package/node_modules/@nodable/entities/src/entities.js +0 -38
- package/node_modules/@nodable/entities/src/entityTries.js +48 -37
- package/node_modules/@nodable/entities/src/index.d.ts +93 -2
- package/node_modules/@nodable/entities/src/index.js +2 -2
- package/node_modules/anynum/LICENSE +21 -0
- package/node_modules/anynum/README.md +142 -0
- package/node_modules/anynum/anynum.js +135 -0
- package/node_modules/anynum/digitTable.js +116 -0
- package/node_modules/anynum/package.json +42 -0
- package/node_modules/dotgitignore/node_modules/brace-expansion/README.md +23 -1
- package/node_modules/dotgitignore/node_modules/brace-expansion/index.js +265 -86
- package/node_modules/dotgitignore/node_modules/brace-expansion/package.json +1 -1
- package/node_modules/fast-xml-builder/CHANGELOG.md +12 -0
- package/node_modules/fast-xml-builder/README.md +4 -1
- package/node_modules/fast-xml-builder/lib/fxb.cjs +1 -1
- package/node_modules/fast-xml-builder/lib/fxb.min.js +1 -1
- package/node_modules/fast-xml-builder/lib/fxb.min.js.map +1 -1
- package/node_modules/fast-xml-builder/package.json +6 -10
- package/node_modules/fast-xml-builder/src/fxb.js +34 -24
- package/node_modules/fast-xml-builder/src/orderedJs2Xml.js +18 -17
- package/node_modules/fast-xml-builder/src/util.js +10 -3
- package/node_modules/fast-xml-parser/CHANGELOG.md +34 -0
- package/node_modules/fast-xml-parser/README.md +10 -6
- package/node_modules/fast-xml-parser/lib/fxbuilder.min.js +1 -1
- package/node_modules/fast-xml-parser/lib/fxbuilder.min.js.map +1 -1
- package/node_modules/fast-xml-parser/lib/fxp.cjs +1 -1
- package/node_modules/fast-xml-parser/lib/fxp.d.cts +3 -1
- package/node_modules/fast-xml-parser/lib/fxp.min.js +1 -1
- package/node_modules/fast-xml-parser/lib/fxp.min.js.map +1 -1
- package/node_modules/fast-xml-parser/lib/fxparser.min.js +1 -1
- package/node_modules/fast-xml-parser/lib/fxparser.min.js.map +1 -1
- package/node_modules/fast-xml-parser/package.json +8 -10
- package/node_modules/fast-xml-parser/src/fxp.d.ts +5 -1
- package/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js +16 -1
- package/node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js +2 -1
- package/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js +36 -3
- package/node_modules/fast-xml-parser/src/xmlparser/xmlNode.js +14 -0
- package/node_modules/get-pkg-repo/node_modules/yargs/package.json +27 -26
- package/node_modules/get-pkg-repo/node_modules/yargs/yargs +5 -9
- package/node_modules/get-pkg-repo/node_modules/yargs/yargs.cjs +15 -0
- package/node_modules/hasown/CHANGELOG.md +7 -0
- package/node_modules/hasown/index.d.ts +0 -1
- package/node_modules/hasown/package.json +4 -5
- package/node_modules/is-unsafe/LICENSE +21 -0
- package/node_modules/is-unsafe/README.md +599 -0
- package/node_modules/is-unsafe/package.json +56 -0
- package/node_modules/is-unsafe/src/contexts/html.js +102 -0
- package/node_modules/is-unsafe/src/contexts/log.js +98 -0
- package/node_modules/is-unsafe/src/contexts/nosql.js +114 -0
- package/node_modules/is-unsafe/src/contexts/redos.js +60 -0
- package/node_modules/is-unsafe/src/contexts/shell.js +105 -0
- package/node_modules/is-unsafe/src/contexts/sql-strict.js +47 -0
- package/node_modules/is-unsafe/src/contexts/sql.js +95 -0
- package/node_modules/is-unsafe/src/contexts/svg.js +81 -0
- package/node_modules/is-unsafe/src/contexts/xml.js +79 -0
- package/node_modules/is-unsafe/src/index.cjs +27 -0
- package/node_modules/is-unsafe/src/index.d.ts +95 -0
- package/node_modules/is-unsafe/src/index.js +265 -0
- package/node_modules/path-expression-matcher/README.md +82 -7
- package/node_modules/path-expression-matcher/lib/pem.cjs +1 -1
- package/node_modules/path-expression-matcher/lib/pem.d.cts +94 -3
- package/node_modules/path-expression-matcher/lib/pem.min.js +1 -1
- package/node_modules/path-expression-matcher/lib/pem.min.js.map +1 -1
- package/node_modules/path-expression-matcher/package.json +2 -1
- package/node_modules/path-expression-matcher/src/ExpressionSet.js +18 -2
- package/node_modules/path-expression-matcher/src/Matcher.js +109 -16
- package/node_modules/path-expression-matcher/src/index.d.ts +67 -1
- package/node_modules/path-expression-matcher/src/index.js +3 -2
- package/node_modules/semver/classes/range.js +24 -4
- package/node_modules/semver/classes/semver.js +19 -2
- package/node_modules/semver/package.json +2 -2
- package/node_modules/semver/ranges/subset.js +2 -2
- package/node_modules/strnum/CHANGELOG.md +14 -0
- package/node_modules/strnum/README.md +9 -0
- package/node_modules/strnum/package.json +7 -3
- package/node_modules/strnum/strnum.js +14 -2
- package/node_modules/xml-naming/LICENSE +21 -0
- package/node_modules/xml-naming/README.md +99 -1
- package/node_modules/xml-naming/package.json +4 -2
- package/node_modules/xml-naming/src/index.d.ts +34 -0
- package/node_modules/xml-naming/src/index.js +134 -22
- package/node_modules/yargs/build/index.cjs +1 -1
- package/node_modules/yargs/package.json +6 -4
- package/node_modules/yargs/yargs +5 -9
- package/node_modules/yargs/yargs.cjs +15 -0
- package/package.json +8 -9
- package/node_modules/yargs/browser.d.ts +0 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fast-xml-builder",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Build XML from JSON without C/C++ based libraries",
|
|
5
5
|
"main": "./lib/fxb.cjs",
|
|
6
6
|
"type": "module",
|
|
@@ -25,10 +25,7 @@
|
|
|
25
25
|
"unit": "jasmine",
|
|
26
26
|
"lint": "eslint src/**/*.js spec/**/*.js benchmark/**/*.js",
|
|
27
27
|
"bundle": "webpack --config webpack.cjs.config.js",
|
|
28
|
-
"prettier": "prettier --write src/**/*.js"
|
|
29
|
-
"checkReadiness": "publish-please --dry-run",
|
|
30
|
-
"publish-please": "publish-please",
|
|
31
|
-
"prepublishOnly": "publish-please guard"
|
|
28
|
+
"prettier": "prettier --write src/**/*.js"
|
|
32
29
|
},
|
|
33
30
|
"files": [
|
|
34
31
|
"lib",
|
|
@@ -55,15 +52,14 @@
|
|
|
55
52
|
"@babel/plugin-transform-runtime": "^7.13.10",
|
|
56
53
|
"@babel/preset-env": "^7.13.10",
|
|
57
54
|
"@babel/register": "^7.13.8",
|
|
55
|
+
"@nodable/entities": "^2.1.0",
|
|
58
56
|
"@types/node": "20",
|
|
59
57
|
"babel-loader": "^8.2.2",
|
|
60
58
|
"c8": "^10.1.3",
|
|
61
59
|
"eslint": "^8.3.0",
|
|
62
60
|
"fast-xml-parser": "^5.3.9",
|
|
63
|
-
"he": "^1.2.0",
|
|
64
61
|
"jasmine": "^5.6.0",
|
|
65
62
|
"prettier": "^3.5.1",
|
|
66
|
-
"publish-please": "^5.5.2",
|
|
67
63
|
"typescript": "5",
|
|
68
64
|
"webpack": "^5.64.4",
|
|
69
65
|
"webpack-cli": "^4.9.1"
|
|
@@ -75,7 +71,7 @@
|
|
|
75
71
|
}
|
|
76
72
|
],
|
|
77
73
|
"dependencies": {
|
|
78
|
-
"path-expression-matcher": "^1.
|
|
79
|
-
"xml-naming": "^0.
|
|
74
|
+
"path-expression-matcher": "^1.6.2",
|
|
75
|
+
"xml-naming": "^0.3.0"
|
|
80
76
|
}
|
|
81
|
-
}
|
|
77
|
+
}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
import buildFromOrderedJs from './orderedJs2Xml.js';
|
|
4
4
|
import getIgnoreAttributesFn from "./ignoreAttributes.js";
|
|
5
5
|
import { Expression, Matcher } from 'path-expression-matcher';
|
|
6
|
-
import { safeComment, safeCdata, escapeAttribute } from './util.js';
|
|
7
|
-
import {
|
|
6
|
+
import { safeComment, safeCdata, escapeAttribute, valToStr } from './util.js';
|
|
7
|
+
import { createValidator } from 'xml-naming';
|
|
8
8
|
|
|
9
9
|
const defaultOptions = {
|
|
10
10
|
attributeNamePrefix: '@_',
|
|
@@ -130,11 +130,11 @@ function detectXmlVersionFromObj(jObj, options) {
|
|
|
130
130
|
* @param {boolean} isAttribute - true when resolving an attribute name
|
|
131
131
|
* @param {object} options
|
|
132
132
|
* @param {Matcher} matcher - current matcher state (readonly from callback perspective)
|
|
133
|
-
* @param {
|
|
133
|
+
* @param {function} qNameValidator - function to validate tag names
|
|
134
134
|
*/
|
|
135
|
-
function resolveTagName(name, isAttribute, options, matcher,
|
|
135
|
+
function resolveTagName(name, isAttribute, options, matcher, qNameValidator) {
|
|
136
136
|
if (!options.sanitizeName) return name;
|
|
137
|
-
if (
|
|
137
|
+
if (qNameValidator(name)) return name;
|
|
138
138
|
return options.sanitizeName(name, { isAttribute, matcher: matcher.readOnly() });
|
|
139
139
|
}
|
|
140
140
|
|
|
@@ -150,11 +150,12 @@ Builder.prototype.build = function (jObj) {
|
|
|
150
150
|
// Initialize matcher for path tracking
|
|
151
151
|
const matcher = new Matcher();
|
|
152
152
|
const xmlVersion = detectXmlVersionFromObj(jObj, this.options);
|
|
153
|
-
|
|
153
|
+
const qNameValidator = createValidator('qName', { xmlVersion });
|
|
154
|
+
return this.j2x(jObj, 0, matcher, qNameValidator).val;
|
|
154
155
|
}
|
|
155
156
|
};
|
|
156
157
|
|
|
157
|
-
Builder.prototype.j2x = function (jObj, level, matcher,
|
|
158
|
+
Builder.prototype.j2x = function (jObj, level, matcher, qNameValidator) {
|
|
158
159
|
let attrStr = '';
|
|
159
160
|
let val = '';
|
|
160
161
|
if (this.options.maxNestedTags && matcher.getDepth() >= this.options.maxNestedTags) {
|
|
@@ -182,7 +183,7 @@ Builder.prototype.j2x = function (jObj, level, matcher, xmlVersion) {
|
|
|
182
183
|
|
|
183
184
|
const resolvedKey = isSpecialKey
|
|
184
185
|
? key
|
|
185
|
-
: resolveTagName(key, false, this.options, matcher,
|
|
186
|
+
: resolveTagName(key, false, this.options, matcher, qNameValidator);
|
|
186
187
|
|
|
187
188
|
if (typeof jObj[key] === 'undefined') {
|
|
188
189
|
// supress undefined node only if it is not an attribute
|
|
@@ -207,12 +208,12 @@ Builder.prototype.j2x = function (jObj, level, matcher, xmlVersion) {
|
|
|
207
208
|
const attr = this.isAttribute(key);
|
|
208
209
|
if (attr && !this.ignoreAttributesFn(attr, jPath)) {
|
|
209
210
|
// Resolve the attribute name through sanitizeName
|
|
210
|
-
const resolvedAttr = resolveTagName(attr, true, this.options, matcher,
|
|
211
|
-
attrStr += this.buildAttrPairStr(resolvedAttr,
|
|
211
|
+
const resolvedAttr = resolveTagName(attr, true, this.options, matcher, qNameValidator);
|
|
212
|
+
attrStr += this.buildAttrPairStr(resolvedAttr, valToStr(jObj[key]), isCurrentStopNode);
|
|
212
213
|
} else if (!attr) {
|
|
213
214
|
//tag value
|
|
214
215
|
if (key === this.options.textNodeName) {
|
|
215
|
-
let newval = this.options.tagValueProcessor(key,
|
|
216
|
+
let newval = this.options.tagValueProcessor(key, valToStr(jObj[key]));
|
|
216
217
|
val += this.replaceEntitiesValue(newval);
|
|
217
218
|
} else {
|
|
218
219
|
// Check if this is a stopNode before building
|
|
@@ -222,7 +223,7 @@ Builder.prototype.j2x = function (jObj, level, matcher, xmlVersion) {
|
|
|
222
223
|
|
|
223
224
|
if (isStopNode) {
|
|
224
225
|
// Build as raw content without encoding
|
|
225
|
-
const textValue =
|
|
226
|
+
const textValue = valToStr(jObj[key]);
|
|
226
227
|
if (textValue === '') {
|
|
227
228
|
val += this.indentate(level) + '<' + resolvedKey + this.closeTag(resolvedKey) + this.tagEndChar;
|
|
228
229
|
} else {
|
|
@@ -249,7 +250,7 @@ Builder.prototype.j2x = function (jObj, level, matcher, xmlVersion) {
|
|
|
249
250
|
if (this.options.oneListGroup) {
|
|
250
251
|
// Push tag to matcher before recursive call
|
|
251
252
|
matcher.push(resolvedKey);
|
|
252
|
-
const result = this.j2x(item, level + 1, matcher,
|
|
253
|
+
const result = this.j2x(item, level + 1, matcher, qNameValidator);
|
|
253
254
|
// Pop tag from matcher after recursive call
|
|
254
255
|
matcher.pop();
|
|
255
256
|
|
|
@@ -258,12 +259,13 @@ Builder.prototype.j2x = function (jObj, level, matcher, xmlVersion) {
|
|
|
258
259
|
listTagAttr += result.attrStr
|
|
259
260
|
}
|
|
260
261
|
} else {
|
|
261
|
-
listTagVal += this.processTextOrObjNode(item, resolvedKey, level, matcher,
|
|
262
|
+
listTagVal += this.processTextOrObjNode(item, resolvedKey, level, matcher, qNameValidator)
|
|
262
263
|
}
|
|
263
264
|
} else {
|
|
264
265
|
if (this.options.oneListGroup) {
|
|
265
266
|
let textValue = this.options.tagValueProcessor(resolvedKey, item);
|
|
266
267
|
textValue = this.replaceEntitiesValue(textValue);
|
|
268
|
+
textValue = valToStr(textValue);
|
|
267
269
|
listTagVal += textValue;
|
|
268
270
|
} else {
|
|
269
271
|
// Check if this is a stopNode before building
|
|
@@ -273,7 +275,7 @@ Builder.prototype.j2x = function (jObj, level, matcher, xmlVersion) {
|
|
|
273
275
|
|
|
274
276
|
if (isStopNode) {
|
|
275
277
|
// Build as raw content without encoding
|
|
276
|
-
const textValue =
|
|
278
|
+
const textValue = valToStr(item);
|
|
277
279
|
if (textValue === '') {
|
|
278
280
|
listTagVal += this.indentate(level) + '<' + resolvedKey + this.closeTag(resolvedKey) + this.tagEndChar;
|
|
279
281
|
} else {
|
|
@@ -296,11 +298,11 @@ Builder.prototype.j2x = function (jObj, level, matcher, xmlVersion) {
|
|
|
296
298
|
const L = Ks.length;
|
|
297
299
|
for (let j = 0; j < L; j++) {
|
|
298
300
|
// Resolve attribute names inside attributesGroupName
|
|
299
|
-
const resolvedAttr = resolveTagName(Ks[j], true, this.options, matcher,
|
|
300
|
-
attrStr += this.buildAttrPairStr(resolvedAttr,
|
|
301
|
+
const resolvedAttr = resolveTagName(Ks[j], true, this.options, matcher, qNameValidator);
|
|
302
|
+
attrStr += this.buildAttrPairStr(resolvedAttr, valToStr(jObj[key][Ks[j]]), isCurrentStopNode);
|
|
301
303
|
}
|
|
302
304
|
} else {
|
|
303
|
-
val += this.processTextOrObjNode(jObj[key], resolvedKey, level, matcher,
|
|
305
|
+
val += this.processTextOrObjNode(jObj[key], resolvedKey, level, matcher, qNameValidator)
|
|
304
306
|
}
|
|
305
307
|
}
|
|
306
308
|
}
|
|
@@ -309,7 +311,7 @@ Builder.prototype.j2x = function (jObj, level, matcher, xmlVersion) {
|
|
|
309
311
|
|
|
310
312
|
Builder.prototype.buildAttrPairStr = function (attrName, val, isStopNode) {
|
|
311
313
|
if (!isStopNode) {
|
|
312
|
-
val = this.options.attributeValueProcessor(attrName,
|
|
314
|
+
val = this.options.attributeValueProcessor(attrName, valToStr(val));
|
|
313
315
|
val = this.replaceEntitiesValue(val);
|
|
314
316
|
}
|
|
315
317
|
if (this.options.suppressBooleanAttributes && val === "true") {
|
|
@@ -317,7 +319,7 @@ Builder.prototype.buildAttrPairStr = function (attrName, val, isStopNode) {
|
|
|
317
319
|
} else return ' ' + attrName + '="' + escapeAttribute(val) + '"';
|
|
318
320
|
}
|
|
319
321
|
|
|
320
|
-
function processTextOrObjNode(object, key, level, matcher,
|
|
322
|
+
function processTextOrObjNode(object, key, level, matcher, qNameValidator) {
|
|
321
323
|
// Extract attributes to pass to matcher
|
|
322
324
|
const attrValues = this.extractAttributes(object);
|
|
323
325
|
|
|
@@ -335,7 +337,7 @@ function processTextOrObjNode(object, key, level, matcher, xmlVersion) {
|
|
|
335
337
|
return this.buildObjectNode(rawContent, key, attrStr, level);
|
|
336
338
|
}
|
|
337
339
|
|
|
338
|
-
const result = this.j2x(object, level + 1, matcher,
|
|
340
|
+
const result = this.j2x(object, level + 1, matcher, qNameValidator);
|
|
339
341
|
// Pop tag from matcher after recursion
|
|
340
342
|
matcher.pop();
|
|
341
343
|
|
|
@@ -464,7 +466,9 @@ Builder.prototype.buildAttributesForStopNode = function (obj) {
|
|
|
464
466
|
if (val === true && this.options.suppressBooleanAttributes) {
|
|
465
467
|
attrStr += ' ' + cleanKey;
|
|
466
468
|
} else {
|
|
467
|
-
|
|
469
|
+
// stopNode content is raw, but the quote delimiter is always escaped
|
|
470
|
+
// so a quote in the value cannot break out of the attribute (see orderedJs2Xml attr_to_str)
|
|
471
|
+
attrStr += ' ' + cleanKey + '="' + escapeAttribute(val) + '"';
|
|
468
472
|
}
|
|
469
473
|
}
|
|
470
474
|
} else {
|
|
@@ -477,7 +481,9 @@ Builder.prototype.buildAttributesForStopNode = function (obj) {
|
|
|
477
481
|
if (val === true && this.options.suppressBooleanAttributes) {
|
|
478
482
|
attrStr += ' ' + attr;
|
|
479
483
|
} else {
|
|
480
|
-
|
|
484
|
+
// stopNode content is raw, but the quote delimiter is always escaped
|
|
485
|
+
// so a quote in the value cannot break out of the attribute (see orderedJs2Xml attr_to_str)
|
|
486
|
+
attrStr += ' ' + attr + '="' + escapeAttribute(val) + '"';
|
|
481
487
|
}
|
|
482
488
|
}
|
|
483
489
|
}
|
|
@@ -508,7 +514,7 @@ Builder.prototype.buildObjectNode = function (val, key, attrStr, level) {
|
|
|
508
514
|
if ((attrStr || attrStr === '') && val.indexOf('<') === -1) {
|
|
509
515
|
return (this.indentate(level) + '<' + key + attrStr + piClosingChar + '>' + val + tagEndExp);
|
|
510
516
|
} else if (this.options.commentPropName !== false && key === this.options.commentPropName && piClosingChar.length === 0) {
|
|
511
|
-
return this.indentate(level) + `<!--${val}-->` + this.newLine;
|
|
517
|
+
return this.indentate(level) + `<!--${safeComment(val)}-->` + this.newLine;
|
|
512
518
|
} else {
|
|
513
519
|
return (
|
|
514
520
|
this.indentate(level) + '<' + key + attrStr + piClosingChar + this.tagEndChar +
|
|
@@ -565,6 +571,10 @@ Builder.prototype.buildTextValNode = function (val, key, attrStr, level, matcher
|
|
|
565
571
|
// Normal processing: apply tagValueProcessor and entity replacement
|
|
566
572
|
let textValue = this.options.tagValueProcessor(key, val);
|
|
567
573
|
textValue = this.replaceEntitiesValue(textValue);
|
|
574
|
+
// tagValueProcessor may return the raw value unchanged (default is identity), and
|
|
575
|
+
// replaceEntitiesValue no-ops on non-strings, so a plain number can still reach here;
|
|
576
|
+
// stringify it now, sign-preserving, before it's implicitly ToString'd below.
|
|
577
|
+
textValue = valToStr(textValue);
|
|
568
578
|
|
|
569
579
|
if (textValue === '') {
|
|
570
580
|
return this.indentate(level) + '<' + key + attrStr + this.closeTag(key) + this.tagEndChar;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Expression, Matcher } from 'path-expression-matcher';
|
|
2
|
-
import { safeComment, safeCdata, escapeAttribute } from "./util.js";
|
|
3
|
-
import {
|
|
2
|
+
import { safeComment, safeCdata, escapeAttribute, valToStr } from "./util.js";
|
|
3
|
+
import { createValidator } from 'xml-naming';
|
|
4
4
|
|
|
5
5
|
const EOL = "\n";
|
|
6
6
|
|
|
@@ -36,11 +36,11 @@ function detectXmlVersionFromArray(jArray, options) {
|
|
|
36
36
|
* @param {boolean} isAttribute - true when resolving an attribute name
|
|
37
37
|
* @param {object} options
|
|
38
38
|
* @param {Matcher} matcher - current matcher state (readonly from callback perspective)
|
|
39
|
-
* @param {
|
|
39
|
+
* @param {function} qNameValidator - function to validate tag names
|
|
40
40
|
*/
|
|
41
|
-
function resolveTagName(name, isAttribute, options, matcher,
|
|
41
|
+
function resolveTagName(name, isAttribute, options, matcher, qNameValidator) {
|
|
42
42
|
if (!options.sanitizeName) return name;
|
|
43
|
-
if (
|
|
43
|
+
if (qNameValidator(name)) return name;
|
|
44
44
|
return options.sanitizeName(name, { isAttribute, matcher: matcher.readOnly() });
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -70,14 +70,14 @@ export default function toXml(jArray, options) {
|
|
|
70
70
|
|
|
71
71
|
// Detect XML version for use in name validation
|
|
72
72
|
const xmlVersion = detectXmlVersionFromArray(jArray, options);
|
|
73
|
-
|
|
73
|
+
const qNameValidator = createValidator('qName', { xmlVersion });
|
|
74
74
|
// Initialize matcher for path tracking
|
|
75
75
|
const matcher = new Matcher();
|
|
76
76
|
|
|
77
|
-
return arrToStr(jArray, options, indentation, matcher, stopNodeExpressions,
|
|
77
|
+
return arrToStr(jArray, options, indentation, matcher, stopNodeExpressions, qNameValidator);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
function arrToStr(arr, options, indentation, matcher, stopNodeExpressions,
|
|
80
|
+
function arrToStr(arr, options, indentation, matcher, stopNodeExpressions, qNameValidator) {
|
|
81
81
|
let xmlStr = "";
|
|
82
82
|
let isPreviousElementTag = false;
|
|
83
83
|
|
|
@@ -88,7 +88,7 @@ function arrToStr(arr, options, indentation, matcher, stopNodeExpressions, xmlVe
|
|
|
88
88
|
if (!Array.isArray(arr)) {
|
|
89
89
|
// Non-array values (e.g. string tag values) should be treated as text content
|
|
90
90
|
if (arr !== undefined && arr !== null) {
|
|
91
|
-
let text = arr
|
|
91
|
+
let text = valToStr(arr);
|
|
92
92
|
text = replaceEntitiesValue(text, options);
|
|
93
93
|
return text;
|
|
94
94
|
}
|
|
@@ -110,7 +110,7 @@ function arrToStr(arr, options, indentation, matcher, stopNodeExpressions, xmlVe
|
|
|
110
110
|
// Resolve tag name (may transform it; may throw for invalid names)
|
|
111
111
|
const tagName = isSpecialName
|
|
112
112
|
? rawTagName
|
|
113
|
-
: resolveTagName(rawTagName, false, options, matcher,
|
|
113
|
+
: resolveTagName(rawTagName, false, options, matcher, qNameValidator);
|
|
114
114
|
|
|
115
115
|
// Extract attributes from ":@" property
|
|
116
116
|
const attrValues = extractAttributeValues(tagObj[":@"], options);
|
|
@@ -127,6 +127,7 @@ function arrToStr(arr, options, indentation, matcher, stopNodeExpressions, xmlVe
|
|
|
127
127
|
tagText = options.tagValueProcessor(tagName, tagText);
|
|
128
128
|
tagText = replaceEntitiesValue(tagText, options);
|
|
129
129
|
}
|
|
130
|
+
tagText = valToStr(tagText);
|
|
130
131
|
if (isPreviousElementTag) {
|
|
131
132
|
xmlStr += indentation;
|
|
132
133
|
}
|
|
@@ -152,7 +153,7 @@ function arrToStr(arr, options, indentation, matcher, stopNodeExpressions, xmlVe
|
|
|
152
153
|
matcher.pop();
|
|
153
154
|
continue;
|
|
154
155
|
} else if (tagName[0] === "?") {
|
|
155
|
-
const attStr = attr_to_str(tagObj[":@"], options, isStopNode, matcher,
|
|
156
|
+
const attStr = attr_to_str(tagObj[":@"], options, isStopNode, matcher, qNameValidator);
|
|
156
157
|
const tempInd = tagName === "?xml" ? "" : indentation;
|
|
157
158
|
// Text node content on PI/XML declaration tags is intentionally ignored.
|
|
158
159
|
// Only attributes are valid on these tags per the XML spec.
|
|
@@ -168,7 +169,7 @@ function arrToStr(arr, options, indentation, matcher, stopNodeExpressions, xmlVe
|
|
|
168
169
|
}
|
|
169
170
|
|
|
170
171
|
// Pass isStopNode to attr_to_str so attributes are also not processed for stopNodes
|
|
171
|
-
const attStr = attr_to_str(tagObj[":@"], options, isStopNode, matcher,
|
|
172
|
+
const attStr = attr_to_str(tagObj[":@"], options, isStopNode, matcher, qNameValidator);
|
|
172
173
|
const tagStart = indentation + `<${tagName}${attStr}`;
|
|
173
174
|
|
|
174
175
|
// If this is a stopNode, get raw content without processing
|
|
@@ -176,7 +177,7 @@ function arrToStr(arr, options, indentation, matcher, stopNodeExpressions, xmlVe
|
|
|
176
177
|
if (isStopNode) {
|
|
177
178
|
tagValue = getRawContent(tagObj[rawTagName], options);
|
|
178
179
|
} else {
|
|
179
|
-
tagValue = arrToStr(tagObj[rawTagName], options, newIdentation, matcher, stopNodeExpressions,
|
|
180
|
+
tagValue = arrToStr(tagObj[rawTagName], options, newIdentation, matcher, stopNodeExpressions, qNameValidator);
|
|
180
181
|
}
|
|
181
182
|
|
|
182
183
|
if (options.unpairedTags.indexOf(tagName) !== -1) {
|
|
@@ -235,7 +236,7 @@ function getRawContent(arr, options) {
|
|
|
235
236
|
if (!Array.isArray(arr)) {
|
|
236
237
|
// Non-array values return as-is
|
|
237
238
|
if (arr !== undefined && arr !== null) {
|
|
238
|
-
return arr
|
|
239
|
+
return valToStr(arr);
|
|
239
240
|
}
|
|
240
241
|
return "";
|
|
241
242
|
}
|
|
@@ -247,7 +248,7 @@ function getRawContent(arr, options) {
|
|
|
247
248
|
|
|
248
249
|
if (tagName === options.textNodeName) {
|
|
249
250
|
// Raw text content - NO processing, NO entity replacement
|
|
250
|
-
content += item[tagName];
|
|
251
|
+
content += valToStr(item[tagName]);
|
|
251
252
|
} else if (tagName === options.cdataPropName) {
|
|
252
253
|
// CDATA content
|
|
253
254
|
content += item[tagName][0][options.textNodeName];
|
|
@@ -305,7 +306,7 @@ function propName(obj) {
|
|
|
305
306
|
* Build attribute string, resolving attribute names through sanitizeName when configured.
|
|
306
307
|
* Accepts matcher so the callback has path context.
|
|
307
308
|
*/
|
|
308
|
-
function attr_to_str(attrMap, options, isStopNode, matcher,
|
|
309
|
+
function attr_to_str(attrMap, options, isStopNode, matcher, qNameValidator) {
|
|
309
310
|
let attrStr = "";
|
|
310
311
|
if (attrMap && !options.ignoreAttributes) {
|
|
311
312
|
for (let attr in attrMap) {
|
|
@@ -315,7 +316,7 @@ function attr_to_str(attrMap, options, isStopNode, matcher, xmlVersion) {
|
|
|
315
316
|
const cleanAttrName = attr.substr(options.attributeNamePrefix.length);
|
|
316
317
|
const resolvedAttrName = isStopNode
|
|
317
318
|
? cleanAttrName // stopNodes are raw — skip sanitizeName for attr names too
|
|
318
|
-
: resolveTagName(cleanAttrName, true, options, matcher,
|
|
319
|
+
: resolveTagName(cleanAttrName, true, options, matcher, qNameValidator);
|
|
319
320
|
|
|
320
321
|
let attrVal;
|
|
321
322
|
if (isStopNode) {
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
// String(val)/val.toString() drop the sign of -0 (e.g. String(-0) === '0'), silently
|
|
4
|
+
// corrupting a round-tripped negative-zero value. XML has no separate int/float syntax,
|
|
5
|
+
// so this is the single place every raw value gets turned into text.
|
|
6
|
+
export function valToStr(val) {
|
|
7
|
+
return typeof val === 'number' && Object.is(val, -0) ? '-0' : String(val)
|
|
8
|
+
}
|
|
9
|
+
|
|
3
10
|
export function safeComment(val) {
|
|
4
|
-
return
|
|
11
|
+
return valToStr(val)
|
|
5
12
|
.replace(/--/g, '- -') // -- is illegal anywhere in comment content
|
|
6
13
|
.replace(/--/g, '- -') // handle the scenario when 2 consiucative dashes appears
|
|
7
14
|
.replace(/-$/, '- '); // trailing - would form -- with the closing -->
|
|
8
15
|
}
|
|
9
16
|
|
|
10
17
|
export function safeCdata(val) {
|
|
11
|
-
return
|
|
18
|
+
return valToStr(val).replace(/\]\]>/g, ']]]]><]
|
|
9
|
+
- fix: don't crash on a closing tag with no matching opening tag (#861) [By [Haïm Dimer](https://github.com/hdimer)]
|
|
10
|
+
- fix: DOCTYPE to read SYSTEM/PUBLIC
|
|
11
|
+
- deps: strnum v2.4.2
|
|
12
|
+
|
|
13
|
+
**5.10.1 / 2026-07-17**
|
|
14
|
+
- fix: multiple DOCTYPE declarations.
|
|
15
|
+
- deps: `@nodable/entities` for treeshaking
|
|
16
|
+
|
|
17
|
+
**5.10.0 / 2026-07-11**
|
|
18
|
+
- upgrade:
|
|
19
|
+
- xml-naming v0.3.0: cache support
|
|
20
|
+
- PEM v1.6.2: sibling bug fix
|
|
21
|
+
- is-unsafe v2.0.0: tree shaking
|
|
22
|
+
|
|
23
|
+
**5.9.3 / 2026-06-19*
|
|
24
|
+
- update strnum
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
**5.9.2 / 2026-06-17*
|
|
28
|
+
- dummy release to test changes in github action
|
|
29
|
+
|
|
30
|
+
**5.9.1 / 2026-06-17*
|
|
31
|
+
- dummy release to test release from github action
|
|
32
|
+
|
|
33
|
+
**5.9.0 / 2026-06-15*
|
|
34
|
+
- update strnum to 2.3.0
|
|
35
|
+
- you can set hex, binary, enotation, infinity, unicode
|
|
36
|
+
- validate unsafe HTML or XML data in doctype entities unsing 'is-unsafe' library.
|
|
37
|
+
User can override rules by overriding EntityDecoder.
|
|
38
|
+
|
|
5
39
|
**5.8.0 / 2026-05-12*
|
|
6
40
|
- integrate xml-naming to validate DOCTYPE entity name and notation name (using qname becaue of backward compatibility)
|
|
7
41
|
- This will consider xml-version as well. '1.0' is default
|
|
@@ -13,21 +13,25 @@ Validate XML, Parse XML to JS Object, or Build XML from JS Object without C/C++
|
|
|
13
13
|
|
|
14
14
|
It can handle big files (tested up to 100mb). XML Entities, HTML entities, and DOCTYPE entites are supported. Unpaired tags (Eg `<br>` in HTML), stop nodes (Eg `<script>` in HTML) are supported. It can also preserve Order of tags in JS object
|
|
15
15
|
|
|
16
|
-
> [
|
|
16
|
+
> **IMPORTANT**: It is recommended to use [fast-xml-validator](https://github.com/NaturalIntelligence/fast-xml-validator) instead of inbuilt validator.
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
# Before using this library
|
|
19
|
+
|
|
20
|
+
- [Flexible-XML-Parser](https://github.com/nodable/flexible-xml-parser) is 1.25 times faster than this library when not preserving order of tags. Takes less memory when processing big files. Supports incomplete XML/HTML. And output is highly customizable. Build whatever you want. So if you're fine with some extra configuration then try it out.
|
|
21
|
+
- [@nodable/sax](https://github.com/nodable/sax) is a SAX parser based on [Flexible-XML-Parser](https://github.com/nodable/flexible-xml-parser). 3-4 times faster than `sax` and support all features of base package like incomplete input, streams, skipping certain tags from processing etc.
|
|
22
|
+
- [fast-xml-validator](https://github.com/NaturalIntelligence/fast-xml-validator) is separated from this package. Has many features. Faster. You can exvlude particular tag from validation. And much more.
|
|
23
|
+
- [fast-xml-builder](https://github.com/NaturalIntelligence/fast-xml-builder) is a XML to JS Object builder used in this package in past. Now, it supports more features, and faster. So, recommend to use it directly.
|
|
20
24
|
|
|
21
|
-
Please join [Discord community](https://discord.gg/X4Qp9u6Vz) for pre release announcements and discussions. This will prevent us to release breaking changes.
|
|
22
25
|
|
|
26
|
+
---
|
|
27
|
+
# Your Support, Our Motivation
|
|
23
28
|
|
|
29
|
+
Please join [Discord community](https://discord.gg/X4Qp9u6Vz) for pre release announcements and discussions.
|
|
24
30
|
|
|
25
31
|
<!-- ## Try out our New Thoughts
|
|
26
32
|
|
|
27
33
|
- WishIn - You need it if negative thoughts take over all the time <br>
|
|
28
34
|
<a href="https://play.google.com/store/apps/details?id=com.solothought.wishin"> <img src="https://solothought.com/products/assets/images/wishin/YouTubeThumbnail.png" width="500px"/> </a>
|
|
29
|
-
- **Flowgger**: 90% less logs size and 90% less debugging time<br>
|
|
30
|
-
<a href="https://github.com/solothought/flowgger"> <img src="static/img/flowgger_h.webp" alt="Flowgger Logging Framework" width="300px"/></a>
|
|
31
35
|
- [Text2Chart](https://solothought.com/text2chart/flow): interactive flow chart out of simple text. -->
|
|
32
36
|
|
|
33
37
|
## Financial Support
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.XMLBuilder=e():t.XMLBuilder=e()}(this,()=>(()=>{"use strict";var t={d:(e,i)=>{for(var s in i)t.o(i,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:i[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{default:()=>C});class i{constructor(t,e={},i){this.pattern=t,this.separator=e.separator||".",this.segments=this._parse(t),this.data=i,this._hasDeepWildcard=this.segments.some(t=>"deep-wildcard"===t.type),this._hasAttributeCondition=this.segments.some(t=>void 0!==t.attrName),this._hasPositionSelector=this.segments.some(t=>void 0!==t.position)}_parse(t){const e=[];let i=0,s="";for(;i<t.length;)t[i]===this.separator?i+1<t.length&&t[i+1]===this.separator?(s.trim()&&(e.push(this._parseSegment(s.trim())),s=""),e.push({type:"deep-wildcard"}),i+=2):(s.trim()&&e.push(this._parseSegment(s.trim())),s="",i++):(s+=t[i],i++);return s.trim()&&e.push(this._parseSegment(s.trim())),e}_parseSegment(t){const e={type:"tag"};let i=null,s=t;const n=t.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);if(n&&(s=n[1]+n[3],n[2])){const t=n[2].slice(1,-1);t&&(i=t)}let r,o,a=s;if(s.includes("::")){const e=s.indexOf("::");if(r=s.substring(0,e).trim(),a=s.substring(e+2).trim(),!r)throw new Error(`Invalid namespace in pattern: ${t}`)}let h=null;if(a.includes(":")){const t=a.lastIndexOf(":"),e=a.substring(0,t).trim(),i=a.substring(t+1).trim();["first","last","odd","even"].includes(i)||/^nth\(\d+\)$/.test(i)?(o=e,h=i):o=a}else o=a;if(!o)throw new Error(`Invalid segment pattern: ${t}`);if(e.tag=o,r&&(e.namespace=r),i)if(i.includes("=")){const t=i.indexOf("=");e.attrName=i.substring(0,t).trim(),e.attrValue=i.substring(t+1).trim()}else e.attrName=i.trim();if(h){const t=h.match(/^nth\((\d+)\)$/);t?(e.position="nth",e.positionValue=parseInt(t[1],10)):e.position=h}return e}get length(){return this.segments.length}hasDeepWildcard(){return this._hasDeepWildcard}hasAttributeCondition(){return this._hasAttributeCondition}hasPositionSelector(){return this._hasPositionSelector}toString(){return this.pattern}}class s{constructor(t){this._matcher=t}get separator(){return this._matcher.separator}getCurrentTag(){const t=this._matcher.path;return t.length>0?t[t.length-1].tag:void 0}getCurrentNamespace(){const t=this._matcher.path;return t.length>0?t[t.length-1].namespace:void 0}getAttrValue(t){const e=this._matcher.path;if(0!==e.length)return e[e.length-1].values?.[t]}hasAttr(t){const e=this._matcher.path;if(0===e.length)return!1;const i=e[e.length-1];return void 0!==i.values&&t in i.values}getPosition(){const t=this._matcher.path;return 0===t.length?-1:t[t.length-1].position??0}getCounter(){const t=this._matcher.path;return 0===t.length?-1:t[t.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this._matcher.path.length}toString(t,e=!0){return this._matcher.toString(t,e)}toArray(){return this._matcher.path.map(t=>t.tag)}matches(t){return this._matcher.matches(t)}matchesAny(t){return t.matchesAny(this._matcher)}}class n{constructor(t={}){this.separator=t.separator||".",this.path=[],this.siblingStacks=[],this._pathStringCache=null,this._view=new s(this)}push(t,e=null,i=null){this._pathStringCache=null,this.path.length>0&&(this.path[this.path.length-1].values=void 0);const s=this.path.length;this.siblingStacks[s]||(this.siblingStacks[s]=new Map);const n=this.siblingStacks[s],r=i?`${i}:${t}`:t,o=n.get(r)||0;let a=0;for(const t of n.values())a+=t;n.set(r,o+1);const h={tag:t,position:a,counter:o};null!=i&&(h.namespace=i),null!=e&&(h.values=e),this.path.push(h)}pop(){if(0===this.path.length)return;this._pathStringCache=null;const t=this.path.pop();return this.siblingStacks.length>this.path.length+1&&(this.siblingStacks.length=this.path.length+1),t}updateCurrent(t){if(this.path.length>0){const e=this.path[this.path.length-1];null!=t&&(e.values=t)}}getCurrentTag(){return this.path.length>0?this.path[this.path.length-1].tag:void 0}getCurrentNamespace(){return this.path.length>0?this.path[this.path.length-1].namespace:void 0}getAttrValue(t){if(0!==this.path.length)return this.path[this.path.length-1].values?.[t]}hasAttr(t){if(0===this.path.length)return!1;const e=this.path[this.path.length-1];return void 0!==e.values&&t in e.values}getPosition(){return 0===this.path.length?-1:this.path[this.path.length-1].position??0}getCounter(){return 0===this.path.length?-1:this.path[this.path.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this.path.length}toString(t,e=!0){const i=t||this.separator;if(i===this.separator&&!0===e){if(null!==this._pathStringCache)return this._pathStringCache;const t=this.path.map(t=>t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(i);return this._pathStringCache=t,t}return this.path.map(t=>e&&t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(i)}toArray(){return this.path.map(t=>t.tag)}reset(){this._pathStringCache=null,this.path=[],this.siblingStacks=[]}matches(t){const e=t.segments;return 0!==e.length&&(t.hasDeepWildcard()?this._matchWithDeepWildcard(e):this._matchSimple(e))}_matchSimple(t){if(this.path.length!==t.length)return!1;for(let e=0;e<t.length;e++)if(!this._matchSegment(t[e],this.path[e],e===this.path.length-1))return!1;return!0}_matchWithDeepWildcard(t){let e=this.path.length-1,i=t.length-1;for(;i>=0&&e>=0;){const s=t[i];if("deep-wildcard"===s.type){if(i--,i<0)return!0;const s=t[i];let n=!1;for(let t=e;t>=0;t--)if(this._matchSegment(s,this.path[t],t===this.path.length-1)){e=t-1,i--,n=!0;break}if(!n)return!1}else{if(!this._matchSegment(s,this.path[e],e===this.path.length-1))return!1;e--,i--}}return i<0}_matchSegment(t,e,i){if("*"!==t.tag&&t.tag!==e.tag)return!1;if(void 0!==t.namespace&&"*"!==t.namespace&&t.namespace!==e.namespace)return!1;if(void 0!==t.attrName){if(!i)return!1;if(!e.values||!(t.attrName in e.values))return!1;if(void 0!==t.attrValue&&String(e.values[t.attrName])!==String(t.attrValue))return!1}if(void 0!==t.position){if(!i)return!1;const s=e.counter??0;if("first"===t.position&&0!==s)return!1;if("odd"===t.position&&s%2!=1)return!1;if("even"===t.position&&s%2!=0)return!1;if("nth"===t.position&&s!==t.positionValue)return!1}return!0}matchesAny(t){return t.matchesAny(this)}snapshot(){return{path:this.path.map(t=>({...t})),siblingStacks:this.siblingStacks.map(t=>new Map(t))}}restore(t){this._pathStringCache=null,this.path=t.path.map(t=>({...t})),this.siblingStacks=t.siblingStacks.map(t=>new Map(t))}readOnly(){return this._view}}function r(t){return String(t).replace(/--/g,"- -").replace(/--/g,"- -").replace(/-$/,"- ")}function o(t){return String(t).replace(/\]\]>/g,"]]]]><![CDATA[>")}function a(t){return String(t).replace(/"/g,""").replace(/'/g,"'")}const h=":A-Za-z_À-ÖØ-öø-˿Ͱ-ͽͿ-҆҈--⁰-Ⰰ-、-豈-﷏ﷰ-�",p=":A-Za-z_À-˿Ͱ-ͽͿ-҆҈--⁰-Ⰰ-、-豈-﷏ﷰ-�𐀀-",u=p+"\\-\\.\\d·̀-ͯ҇‿-⁀",l=(t,e,i="")=>{const s=`[${t.replace(":","")}][${e.replace(":","")}]*`;return{name:new RegExp(`^[${t}][${e}]*$`,i),ncName:new RegExp(`^${s}$`,i),qName:new RegExp(`^${s}(?::${s})?$`,i),nmToken:new RegExp(`^[${e}]+$`,i),nmTokens:new RegExp(`^[${e}]+(?:\\s+[${e}]+)*$`,i)}},c=l(h,h+"\\-\\.\\d·̀-ͯ‿-⁀"),g=l(p,u,"u"),d=(t,{xmlVersion:e="1.0"}={})=>((t="1.0")=>"1.1"===t?g:c)(e).qName.test(t);function f(t,e,i,s,n){return i.sanitizeName?d(t,{xmlVersion:n})?t:i.sanitizeName(t,{isAttribute:e,matcher:s.readOnly()}):t}function m(t,e){let s="";e.format&&(s="\n");const r=[];if(e.stopNodes&&Array.isArray(e.stopNodes))for(let t=0;t<e.stopNodes.length;t++){const s=e.stopNodes[t];"string"==typeof s?r.push(new i(s)):s instanceof i&&r.push(s)}const o=function(t,e){if(!Array.isArray(t)||0===t.length)return"1.0";const i=t[0];if("?xml"===A(i)){const t=i[":@"];if(t){const i=e.attributeNamePrefix+"version";if(t[i])return t[i]}}return"1.0"}(t,e);return b(t,e,s,new n,r,o)}function b(t,e,i,s,n,a){let h="",p=!1;if(e.maxNestedTags&&s.getDepth()>e.maxNestedTags)throw new Error("Maximum nested tags exceeded");if(!Array.isArray(t)){if(null!=t){let i=t.toString();return i=S(i,e),i}return""}for(let u=0;u<t.length;u++){const l=t[u],c=A(l);if(void 0===c)continue;const g=c===e.textNodeName||c===e.cdataPropName||c===e.commentPropName||"?"===c[0]?c:f(c,!1,e,s,a),d=N(l[":@"],e);s.push(g,d);const m=P(s,n);if(g===e.textNodeName){let t=l[c];m||(t=e.tagValueProcessor(g,t),t=S(t,e)),p&&(h+=i),h+=t,p=!1,s.pop();continue}if(g===e.cdataPropName){p&&(h+=i),h+=`<![CDATA[${o(l[c][0][e.textNodeName])}]]>`,p=!1,s.pop();continue}if(g===e.commentPropName){h+=i+`\x3c!--${r(l[c][0][e.textNodeName])}--\x3e`,p=!0,s.pop();continue}if("?"===g[0]){h+=("?xml"===g?"":i)+`<${g}${$(l[":@"],e,m,s,a)}?>`,p=!0,s.pop();continue}let y=i;""!==y&&(y+=e.indentBy);const v=i+`<${g}${$(l[":@"],e,m,s,a)}`;let w;w=m?x(l[c],e):b(l[c],e,y,s,n,a),-1!==e.unpairedTags.indexOf(g)?e.suppressUnpairedNode?h+=v+">":h+=v+"/>":w&&0!==w.length||!e.suppressEmptyNode?w&&w.endsWith(">")?h+=v+`>${w}${i}</${g}>`:(h+=v+">",w&&""!==i&&(w.includes("/>")||w.includes("</"))?h+=i+e.indentBy+w+i:h+=w,h+=`</${g}>`):h+=v+"/>",p=!0,s.pop()}return h}function N(t,e){if(!t||e.ignoreAttributes)return null;const i={};let s=!1;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n.startsWith(e.attributeNamePrefix)?n.substr(e.attributeNamePrefix.length):n]=a(t[n]),s=!0);return s?i:null}function x(t,e){if(!Array.isArray(t))return null!=t?t.toString():"";let i="";for(let s=0;s<t.length;s++){const n=t[s],r=A(n);if(r===e.textNodeName)i+=n[r];else if(r===e.cdataPropName)i+=n[r][0][e.textNodeName];else if(r===e.commentPropName)i+=n[r][0][e.textNodeName];else{if(r&&"?"===r[0])continue;if(r){const t=y(n[":@"],e),s=x(n[r],e);s&&0!==s.length?i+=`<${r}${t}>${s}</${r}>`:i+=`<${r}${t}/>`}}}return i}function y(t,e){let i="";if(t&&!e.ignoreAttributes)for(let s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;let n=t[s];!0===n&&e.suppressBooleanAttributes?i+=` ${s.substr(e.attributeNamePrefix.length)}`:i+=` ${s.substr(e.attributeNamePrefix.length)}="${a(n)}"`}return i}function A(t){const e=Object.keys(t);for(let i=0;i<e.length;i++){const s=e[i];if(Object.prototype.hasOwnProperty.call(t,s)&&":@"!==s)return s}}function $(t,e,i,s,n){let r="";if(t&&!e.ignoreAttributes)for(let o in t){if(!Object.prototype.hasOwnProperty.call(t,o))continue;const h=o.substr(e.attributeNamePrefix.length),p=i?h:f(h,!0,e,s,n);let u;i?u=t[o]:(u=e.attributeValueProcessor(o,t[o]),u=S(u,e)),!0===u&&e.suppressBooleanAttributes?r+=` ${p}`:r+=` ${p}="${a(u)}"`}return r}function P(t,e){if(!e||0===e.length)return!1;for(let i=0;i<e.length;i++)if(t.matches(e[i]))return!0;return!1}function S(t,e){if(t&&t.length>0&&e.processEntities)for(let i=0;i<e.entities.length;i++){const s=e.entities[i];t=t.replace(s.regex,s.val)}return t}const v={attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:" ",suppressEmptyNode:!1,suppressUnpairedNode:!0,suppressBooleanAttributes:!0,tagValueProcessor:function(t,e){return e},attributeValueProcessor:function(t,e){return e},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:[{regex:new RegExp("&","g"),val:"&"},{regex:new RegExp(">","g"),val:">"},{regex:new RegExp("<","g"),val:"<"},{regex:new RegExp("'","g"),val:"'"},{regex:new RegExp('"',"g"),val:"""}],processEntities:!0,stopNodes:[],oneListGroup:!1,maxNestedTags:100,jPath:!0,sanitizeName:!1};function w(t){if(this.options=Object.assign({},v,t),this.options.stopNodes&&Array.isArray(this.options.stopNodes)&&(this.options.stopNodes=this.options.stopNodes.map(t=>"string"==typeof t&&t.startsWith("*.")?".."+t.substring(2):t)),this.stopNodeExpressions=[],this.options.stopNodes&&Array.isArray(this.options.stopNodes))for(let t=0;t<this.options.stopNodes.length;t++){const e=this.options.stopNodes[t];"string"==typeof e?this.stopNodeExpressions.push(new i(e)):e instanceof i&&this.stopNodeExpressions.push(e)}var e;!0===this.options.ignoreAttributes||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.ignoreAttributesFn="function"==typeof(e=this.options.ignoreAttributes)?e:Array.isArray(e)?t=>{for(const i of e){if("string"==typeof i&&t===i)return!0;if(i instanceof RegExp&&i.test(t))return!0}}:()=>!1,this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=j),this.processTextOrObjNode=O,this.options.format?(this.indentate=_,this.tagEndChar=">\n",this.newLine="\n"):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}function E(t,e,i,s,n){return i.sanitizeName?d(t,{xmlVersion:n})?t:i.sanitizeName(t,{isAttribute:e,matcher:s.readOnly()}):t}function O(t,e,i,s,n){const r=this.extractAttributes(t);if(s.push(e,r),this.checkStopNode(s)){const n=this.buildRawContent(t),r=this.buildAttributesForStopNode(t);return s.pop(),this.buildObjectNode(n,e,r,i)}const o=this.j2x(t,i+1,s,n);return s.pop(),"?"===e[0]?this.buildTextValNode("",e,o.attrStr,i,s):void 0!==t[this.options.textNodeName]&&1===Object.keys(t).length?this.buildTextValNode(t[this.options.textNodeName],e,o.attrStr,i,s):this.buildObjectNode(o.val,e,o.attrStr,i)}function _(t){return this.options.indentBy.repeat(t)}function j(t){return!(!t.startsWith(this.options.attributeNamePrefix)||t===this.options.textNodeName)&&t.substr(this.attrPrefixLen)}w.prototype.build=function(t){if(this.options.preserveOrder)return m(t,this.options);{Array.isArray(t)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(t={[this.options.arrayNodeName]:t});const e=new n,i=function(t,e){const i=t["?xml"];if(i&&"object"==typeof i){if(e.attributesGroupName&&i[e.attributesGroupName]){const t=i[e.attributesGroupName][e.attributeNamePrefix+"version"];if(t)return t}const t=i[e.attributeNamePrefix+"version"];if(t)return t}return"1.0"}(t,this.options);return this.j2x(t,0,e,i).val}},w.prototype.j2x=function(t,e,i,s){let n="",r="";if(this.options.maxNestedTags&&i.getDepth()>=this.options.maxNestedTags)throw new Error("Maximum nested tags exceeded");const o=this.options.jPath?i.toString():i,a=this.checkStopNode(i);for(let h in t){if(!Object.prototype.hasOwnProperty.call(t,h))continue;const p=h===this.options.textNodeName||h===this.options.cdataPropName||h===this.options.commentPropName||this.options.attributesGroupName&&h===this.options.attributesGroupName||this.isAttribute(h)||"?"===h[0]?h:E(h,!1,this.options,i,s);if(void 0===t[h])this.isAttribute(h)&&(r+="");else if(null===t[h])this.isAttribute(h)||p===this.options.cdataPropName||p===this.options.commentPropName?r+="":"?"===p[0]?r+=this.indentate(e)+"<"+p+"?"+this.tagEndChar:r+=this.indentate(e)+"<"+p+"/"+this.tagEndChar;else if(t[h]instanceof Date)r+=this.buildTextValNode(t[h],p,"",e,i);else if("object"!=typeof t[h]){const u=this.isAttribute(h);if(u&&!this.ignoreAttributesFn(u,o)){const e=E(u,!0,this.options,i,s);n+=this.buildAttrPairStr(e,""+t[h],a)}else if(!u)if(h===this.options.textNodeName){let e=this.options.tagValueProcessor(h,""+t[h]);r+=this.replaceEntitiesValue(e)}else{i.push(p);const s=this.checkStopNode(i);if(i.pop(),s){const i=""+t[h];r+=""===i?this.indentate(e)+"<"+p+this.closeTag(p)+this.tagEndChar:this.indentate(e)+"<"+p+">"+i+"</"+p+this.tagEndChar}else r+=this.buildTextValNode(t[h],p,"",e,i)}}else if(Array.isArray(t[h])){const n=t[h].length;let o="",a="";for(let u=0;u<n;u++){const n=t[h][u];if(void 0===n);else if(null===n)"?"===p[0]?r+=this.indentate(e)+"<"+p+"?"+this.tagEndChar:r+=this.indentate(e)+"<"+p+"/"+this.tagEndChar;else if("object"==typeof n)if(this.options.oneListGroup){i.push(p);const t=this.j2x(n,e+1,i,s);i.pop(),o+=t.val,this.options.attributesGroupName&&n.hasOwnProperty(this.options.attributesGroupName)&&(a+=t.attrStr)}else o+=this.processTextOrObjNode(n,p,e,i,s);else if(this.options.oneListGroup){let t=this.options.tagValueProcessor(p,n);t=this.replaceEntitiesValue(t),o+=t}else{i.push(p);const t=this.checkStopNode(i);if(i.pop(),t){const t=""+n;o+=""===t?this.indentate(e)+"<"+p+this.closeTag(p)+this.tagEndChar:this.indentate(e)+"<"+p+">"+t+"</"+p+this.tagEndChar}else o+=this.buildTextValNode(n,p,"",e,i)}}this.options.oneListGroup&&(o=this.buildObjectNode(o,p,a,e)),r+=o}else if(this.options.attributesGroupName&&h===this.options.attributesGroupName){const e=Object.keys(t[h]),r=e.length;for(let o=0;o<r;o++){const r=E(e[o],!0,this.options,i,s);n+=this.buildAttrPairStr(r,""+t[h][e[o]],a)}}else r+=this.processTextOrObjNode(t[h],p,e,i,s)}return{attrStr:n,val:r}},w.prototype.buildAttrPairStr=function(t,e,i){return i||(e=this.options.attributeValueProcessor(t,""+e),e=this.replaceEntitiesValue(e)),this.options.suppressBooleanAttributes&&"true"===e?" "+t:" "+t+'="'+a(e)+'"'},w.prototype.extractAttributes=function(t){if(!t||"object"!=typeof t)return null;const e={};let i=!1;if(this.options.attributesGroupName&&t[this.options.attributesGroupName]){const s=t[this.options.attributesGroupName];for(let t in s)Object.prototype.hasOwnProperty.call(s,t)&&(e[t.startsWith(this.options.attributeNamePrefix)?t.substring(this.options.attributeNamePrefix.length):t]=a(s[t]),i=!0)}else for(let s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;const n=this.isAttribute(s);n&&(e[n]=a(t[s]),i=!0)}return i?e:null},w.prototype.buildRawContent=function(t){if("string"==typeof t)return t;if("object"!=typeof t||null===t)return String(t);if(void 0!==t[this.options.textNodeName])return t[this.options.textNodeName];let e="";for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;if(this.isAttribute(i))continue;if(this.options.attributesGroupName&&i===this.options.attributesGroupName)continue;const s=t[i];if(i===this.options.textNodeName)e+=s;else if(Array.isArray(s)){for(let t of s)if("string"==typeof t||"number"==typeof t)e+=`<${i}>${t}</${i}>`;else if("object"==typeof t&&null!==t){const s=this.buildRawContent(t),n=this.buildAttributesForStopNode(t);e+=""===s?`<${i}${n}/>`:`<${i}${n}>${s}</${i}>`}}else if("object"==typeof s&&null!==s){const t=this.buildRawContent(s),n=this.buildAttributesForStopNode(s);e+=""===t?`<${i}${n}/>`:`<${i}${n}>${t}</${i}>`}else e+=`<${i}>${s}</${i}>`}return e},w.prototype.buildAttributesForStopNode=function(t){if(!t||"object"!=typeof t)return"";let e="";if(this.options.attributesGroupName&&t[this.options.attributesGroupName]){const i=t[this.options.attributesGroupName];for(let t in i){if(!Object.prototype.hasOwnProperty.call(i,t))continue;const s=t.startsWith(this.options.attributeNamePrefix)?t.substring(this.options.attributeNamePrefix.length):t,n=i[t];!0===n&&this.options.suppressBooleanAttributes?e+=" "+s:e+=" "+s+'="'+n+'"'}}else for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;const s=this.isAttribute(i);if(s){const n=t[i];!0===n&&this.options.suppressBooleanAttributes?e+=" "+s:e+=" "+s+'="'+n+'"'}}return e},w.prototype.buildObjectNode=function(t,e,i,s){if(""===t)return"?"===e[0]?this.indentate(s)+"<"+e+i+"?"+this.tagEndChar:this.indentate(s)+"<"+e+i+this.closeTag(e)+this.tagEndChar;if("?"===e[0])return this.indentate(s)+"<"+e+i+"?"+this.tagEndChar;{let n="</"+e+this.tagEndChar,r="";return"?"===e[0]&&(r="?",n=""),!i&&""!==i||-1!==t.indexOf("<")?!1!==this.options.commentPropName&&e===this.options.commentPropName&&0===r.length?this.indentate(s)+`\x3c!--${t}--\x3e`+this.newLine:this.indentate(s)+"<"+e+i+r+this.tagEndChar+t+this.indentate(s)+n:this.indentate(s)+"<"+e+i+r+">"+t+n}},w.prototype.closeTag=function(t){let e="";return-1!==this.options.unpairedTags.indexOf(t)?this.options.suppressUnpairedNode||(e="/"):e=this.options.suppressEmptyNode?"/":`></${t}`,e},w.prototype.checkStopNode=function(t){if(!this.stopNodeExpressions||0===this.stopNodeExpressions.length)return!1;for(let e=0;e<this.stopNodeExpressions.length;e++)if(t.matches(this.stopNodeExpressions[e]))return!0;return!1},w.prototype.buildTextValNode=function(t,e,i,s,n){if(!1!==this.options.cdataPropName&&e===this.options.cdataPropName){const e=o(t);return this.indentate(s)+`<![CDATA[${e}]]>`+this.newLine}if(!1!==this.options.commentPropName&&e===this.options.commentPropName){const e=r(t);return this.indentate(s)+`\x3c!--${e}--\x3e`+this.newLine}if("?"===e[0])return this.indentate(s)+"<"+e+i+"?"+this.tagEndChar;{let n=this.options.tagValueProcessor(e,t);return n=this.replaceEntitiesValue(n),""===n?this.indentate(s)+"<"+e+i+this.closeTag(e)+this.tagEndChar:this.indentate(s)+"<"+e+i+">"+n+"</"+e+this.tagEndChar}},w.prototype.replaceEntitiesValue=function(t){if(t&&t.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){const i=this.options.entities[e];t=t.replace(i.regex,i.val)}return t};const C=w;return e})());
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.XMLBuilder=e():t.XMLBuilder=e()}(this,()=>(()=>{"use strict";var t={d:(e,i)=>{for(var s in i)t.o(i,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:i[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{default:()=>C});class i{constructor(t,e={},i){this.pattern=t,this.separator=e.separator||".",this.segments=this._parse(t),this.data=i,this._hasDeepWildcard=this.segments.some(t=>"deep-wildcard"===t.type),this._hasAttributeCondition=this.segments.some(t=>void 0!==t.attrName),this._hasPositionSelector=this.segments.some(t=>void 0!==t.position)}_parse(t){const e=[];let i=0,s="";for(;i<t.length;)t[i]===this.separator?i+1<t.length&&t[i+1]===this.separator?(s.trim()&&(e.push(this._parseSegment(s.trim())),s=""),e.push({type:"deep-wildcard"}),i+=2):(s.trim()&&e.push(this._parseSegment(s.trim())),s="",i++):(s+=t[i],i++);return s.trim()&&e.push(this._parseSegment(s.trim())),e}_parseSegment(t){const e={type:"tag"};let i=null,s=t;const n=t.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);if(n&&(s=n[1]+n[3],n[2])){const t=n[2].slice(1,-1);t&&(i=t)}let r,o,a=s;if(s.includes("::")){const e=s.indexOf("::");if(r=s.substring(0,e).trim(),a=s.substring(e+2).trim(),!r)throw new Error(`Invalid namespace in pattern: ${t}`)}let h=null;if(a.includes(":")){const t=a.lastIndexOf(":"),e=a.substring(0,t).trim(),i=a.substring(t+1).trim();["first","last","odd","even"].includes(i)||/^nth\(\d+\)$/.test(i)?(o=e,h=i):o=a}else o=a;if(!o)throw new Error(`Invalid segment pattern: ${t}`);if(e.tag=o,r&&(e.namespace=r),i)if(i.includes("=")){const t=i.indexOf("=");e.attrName=i.substring(0,t).trim(),e.attrValue=i.substring(t+1).trim()}else e.attrName=i.trim();if(h){const t=h.match(/^nth\((\d+)\)$/);t?(e.position="nth",e.positionValue=parseInt(t[1],10)):e.position=h}return e}get length(){return this.segments.length}hasDeepWildcard(){return this._hasDeepWildcard}hasAttributeCondition(){return this._hasAttributeCondition}hasPositionSelector(){return this._hasPositionSelector}toString(){return this.pattern}}class s{constructor(t){this._matcher=t}get separator(){return this._matcher.separator}getCurrentTag(){const t=this._matcher.path;return t.length>0?t[t.length-1].tag:void 0}getCurrentNamespace(){const t=this._matcher.path;return t.length>0?t[t.length-1].namespace:void 0}getAttrValue(t){const e=this._matcher.path;if(0!==e.length)return e[e.length-1].values?.[t]}hasAttr(t){const e=this._matcher.path;if(0===e.length)return!1;const i=e[e.length-1];return void 0!==i.values&&t in i.values}getAnyParentAttr(t){return this._matcher.getAnyParentAttr(t)}hasAnyParentAttr(t){return this._matcher.hasAnyParentAttr(t)}getPosition(){const t=this._matcher.path;return 0===t.length?-1:t[t.length-1].position??0}getCounter(){const t=this._matcher.path;return 0===t.length?-1:t[t.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this._matcher.path.length}toString(t,e=!0){return this._matcher.toString(t,e)}toArray(){return this._matcher.path.map(t=>t.tag)}matches(t){return this._matcher.matches(t)}matchesAny(t){return t.matchesAny(this._matcher)}}class n{constructor(t={}){this.separator=t.separator||".",this.path=[],this.siblingStacks=[],this._pathStringCache=null,this._view=new s(this),this._keptAttrs=[]}push(t,e=null,i=null,s=null){this._pathStringCache=null,this.path.length>0&&(this.path[this.path.length-1].values=void 0);const n=this.path.length;let r=this.siblingStacks[n];r||(r={counts:new Map,total:0},this.siblingStacks[n]=r);const o=i?`${i}:${t}`:t,a=r.counts.get(o)||0,h=r.total;r.counts.set(o,a+1),r.total++;const p={tag:t,position:h,counter:a};null!=i&&(p.namespace=i),null!=e&&(p.values=e),this.path.push(p);const u=this.path.length,l=null!==s?s.keep:null;if(null!=l&&l.length>0&&e)for(let t=0;t<l.length;t++){const i=l[t];void 0!==e[i]&&this._keptAttrs.push({depth:u,name:i,value:e[i]})}}pop(){if(0===this.path.length)return;this._pathStringCache=null;const t=this.path.pop();this.siblingStacks.length>this.path.length+1&&(this.siblingStacks.length=this.path.length+1);const e=this.path.length+1;for(;this._keptAttrs.length>0&&this._keptAttrs[this._keptAttrs.length-1].depth>=e;)this._keptAttrs.pop();return t}updateCurrent(t){if(this.path.length>0){const e=this.path[this.path.length-1];null!=t&&(e.values=t)}}getCurrentTag(){return this.path.length>0?this.path[this.path.length-1].tag:void 0}getCurrentNamespace(){return this.path.length>0?this.path[this.path.length-1].namespace:void 0}getAttrValue(t){if(0!==this.path.length)return this.path[this.path.length-1].values?.[t]}hasAttr(t){if(0===this.path.length)return!1;const e=this.path[this.path.length-1];return void 0!==e.values&&t in e.values}getAnyParentAttr(t){const e=this._keptAttrs;for(let i=e.length-1;i>=0;i--)if(e[i].name===t)return e[i].value}hasAnyParentAttr(t){const e=this._keptAttrs;for(let i=e.length-1;i>=0;i--)if(e[i].name===t)return!0;return!1}getPosition(){return 0===this.path.length?-1:this.path[this.path.length-1].position??0}getCounter(){return 0===this.path.length?-1:this.path[this.path.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this.path.length}toString(t,e=!0){const i=t||this.separator;if(i===this.separator&&!0===e){if(null!==this._pathStringCache)return this._pathStringCache;const t=this.path.map(t=>t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(i);return this._pathStringCache=t,t}return this.path.map(t=>e&&t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(i)}toArray(){return this.path.map(t=>t.tag)}reset(){this._pathStringCache=null,this.path=[],this.siblingStacks=[],this._keptAttrs=[]}matches(t){const e=t.segments;return 0!==e.length&&(t.hasDeepWildcard()?this._matchWithDeepWildcard(e):this._matchSimple(e))}_matchSimple(t){if(this.path.length!==t.length)return!1;for(let e=0;e<t.length;e++)if(!this._matchSegment(t[e],this.path[e],e===this.path.length-1))return!1;return!0}_matchWithDeepWildcard(t){let e=this.path.length-1,i=t.length-1;for(;i>=0&&e>=0;){const s=t[i];if("deep-wildcard"===s.type){if(i--,i<0)return!0;const s=t[i];let n=!1;for(let t=e;t>=0;t--)if(this._matchSegment(s,this.path[t],t===this.path.length-1)){e=t-1,i--,n=!0;break}if(!n)return!1}else{if(!this._matchSegment(s,this.path[e],e===this.path.length-1))return!1;e--,i--}}return i<0}_matchSegment(t,e,i){if("*"!==t.tag&&t.tag!==e.tag)return!1;if(void 0!==t.namespace&&"*"!==t.namespace&&t.namespace!==e.namespace)return!1;if(void 0!==t.attrName){if(!i)return!1;if(!e.values||!(t.attrName in e.values))return!1;if(void 0!==t.attrValue&&String(e.values[t.attrName])!==String(t.attrValue))return!1}if(void 0!==t.position){if(!i)return!1;const s=e.counter??0;if("first"===t.position&&0!==s)return!1;if("odd"===t.position&&s%2!=1)return!1;if("even"===t.position&&s%2!=0)return!1;if("nth"===t.position&&s!==t.positionValue)return!1}return!0}matchesAny(t){return t.matchesAny(this)}snapshot(){return{path:this.path.map(t=>({...t})),siblingStacks:this.siblingStacks.map(t=>t?{counts:new Map(t.counts),total:t.total}:t),keptAttrs:this._keptAttrs.map(t=>({...t}))}}restore(t){this._pathStringCache=null,this.path=t.path.map(t=>({...t})),this.siblingStacks=t.siblingStacks.map(t=>t?{counts:new Map(t.counts),total:t.total}:t),this._keptAttrs=(t.keptAttrs||[]).map(t=>({...t}))}readOnly(){return this._view}}function r(t){return String(t).replace(/--/g,"- -").replace(/--/g,"- -").replace(/-$/,"- ")}function o(t){return String(t).replace(/\]\]>/g,"]]]]><![CDATA[>")}function a(t){return String(t).replace(/"/g,""").replace(/'/g,"'")}const h=":A-Za-z_À-ÖØ-öø-˿Ͱ-ͽͿ-҆҈--⁰-Ⰰ-、-豈-﷏ﷰ-�",p=":A-Za-z_À-˿Ͱ-ͽͿ-҆҈--⁰-Ⰰ-、-豈-﷏ﷰ-�𐀀-",u=p+"\\-\\.\\d·̀-ͯ҇‿-⁀",l=(t,e,i="")=>{const s=`[${t.replace(":","")}][${e.replace(":","")}]*`;return{name:new RegExp(`^[${t}][${e}]*$`,i),ncName:new RegExp(`^${s}$`,i),qName:new RegExp(`^${s}(?::${s})?$`,i),nmToken:new RegExp(`^[${e}]+$`,i),nmTokens:new RegExp(`^[${e}]+(?:\\s+[${e}]+)*$`,i)}},c=l(h,h+"\\-\\.\\d·̀-ͯ‿-⁀"),g=l(p,u,"u"),d=(t,{xmlVersion:e="1.0"}={})=>((t="1.0")=>"1.1"===t?g:c)(e).qName.test(t);function f(t,e,i,s,n){return i.sanitizeName?d(t,{xmlVersion:n})?t:i.sanitizeName(t,{isAttribute:e,matcher:s.readOnly()}):t}function m(t,e){let s="";e.format&&(s="\n");const r=[];if(e.stopNodes&&Array.isArray(e.stopNodes))for(let t=0;t<e.stopNodes.length;t++){const s=e.stopNodes[t];"string"==typeof s?r.push(new i(s)):s instanceof i&&r.push(s)}const o=function(t,e){if(!Array.isArray(t)||0===t.length)return"1.0";const i=t[0];if("?xml"===A(i)){const t=i[":@"];if(t){const i=e.attributeNamePrefix+"version";if(t[i])return t[i]}}return"1.0"}(t,e);return b(t,e,s,new n,r,o)}function b(t,e,i,s,n,a){let h="",p=!1;if(e.maxNestedTags&&s.getDepth()>e.maxNestedTags)throw new Error("Maximum nested tags exceeded");if(!Array.isArray(t)){if(null!=t){let i=t.toString();return i=S(i,e),i}return""}for(let u=0;u<t.length;u++){const l=t[u],c=A(l);if(void 0===c)continue;const g=c===e.textNodeName||c===e.cdataPropName||c===e.commentPropName||"?"===c[0]?c:f(c,!1,e,s,a),d=N(l[":@"],e);s.push(g,d);const m=$(s,n);if(g===e.textNodeName){let t=l[c];m||(t=e.tagValueProcessor(g,t),t=S(t,e)),p&&(h+=i),h+=t,p=!1,s.pop();continue}if(g===e.cdataPropName){p&&(h+=i),h+=`<![CDATA[${o(l[c][0][e.textNodeName])}]]>`,p=!1,s.pop();continue}if(g===e.commentPropName){h+=i+`\x3c!--${r(l[c][0][e.textNodeName])}--\x3e`,p=!0,s.pop();continue}if("?"===g[0]){h+=("?xml"===g?"":i)+`<${g}${P(l[":@"],e,m,s,a)}?>`,p=!0,s.pop();continue}let x=i;""!==x&&(x+=e.indentBy);const _=i+`<${g}${P(l[":@"],e,m,s,a)}`;let v;v=m?y(l[c],e):b(l[c],e,x,s,n,a),-1!==e.unpairedTags.indexOf(g)?e.suppressUnpairedNode?h+=_+">":h+=_+"/>":v&&0!==v.length||!e.suppressEmptyNode?v&&v.endsWith(">")?h+=_+`>${v}${i}</${g}>`:(h+=_+">",v&&""!==i&&(v.includes("/>")||v.includes("</"))?h+=i+e.indentBy+v+i:h+=v,h+=`</${g}>`):h+=_+"/>",p=!0,s.pop()}return h}function N(t,e){if(!t||e.ignoreAttributes)return null;const i={};let s=!1;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n.startsWith(e.attributeNamePrefix)?n.substr(e.attributeNamePrefix.length):n]=a(t[n]),s=!0);return s?i:null}function y(t,e){if(!Array.isArray(t))return null!=t?t.toString():"";let i="";for(let s=0;s<t.length;s++){const n=t[s],r=A(n);if(r===e.textNodeName)i+=n[r];else if(r===e.cdataPropName)i+=n[r][0][e.textNodeName];else if(r===e.commentPropName)i+=n[r][0][e.textNodeName];else{if(r&&"?"===r[0])continue;if(r){const t=x(n[":@"],e),s=y(n[r],e);s&&0!==s.length?i+=`<${r}${t}>${s}</${r}>`:i+=`<${r}${t}/>`}}}return i}function x(t,e){let i="";if(t&&!e.ignoreAttributes)for(let s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;let n=t[s];!0===n&&e.suppressBooleanAttributes?i+=` ${s.substr(e.attributeNamePrefix.length)}`:i+=` ${s.substr(e.attributeNamePrefix.length)}="${a(n)}"`}return i}function A(t){const e=Object.keys(t);for(let i=0;i<e.length;i++){const s=e[i];if(Object.prototype.hasOwnProperty.call(t,s)&&":@"!==s)return s}}function P(t,e,i,s,n){let r="";if(t&&!e.ignoreAttributes)for(let o in t){if(!Object.prototype.hasOwnProperty.call(t,o))continue;const h=o.substr(e.attributeNamePrefix.length),p=i?h:f(h,!0,e,s,n);let u;i?u=t[o]:(u=e.attributeValueProcessor(o,t[o]),u=S(u,e)),!0===u&&e.suppressBooleanAttributes?r+=` ${p}`:r+=` ${p}="${a(u)}"`}return r}function $(t,e){if(!e||0===e.length)return!1;for(let i=0;i<e.length;i++)if(t.matches(e[i]))return!0;return!1}function S(t,e){if(t&&t.length>0&&e.processEntities)for(let i=0;i<e.entities.length;i++){const s=e.entities[i];t=t.replace(s.regex,s.val)}return t}const _={attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:" ",suppressEmptyNode:!1,suppressUnpairedNode:!0,suppressBooleanAttributes:!0,tagValueProcessor:function(t,e){return e},attributeValueProcessor:function(t,e){return e},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:[{regex:new RegExp("&","g"),val:"&"},{regex:new RegExp(">","g"),val:">"},{regex:new RegExp("<","g"),val:"<"},{regex:new RegExp("'","g"),val:"'"},{regex:new RegExp('"',"g"),val:"""}],processEntities:!0,stopNodes:[],oneListGroup:!1,maxNestedTags:100,jPath:!0,sanitizeName:!1};function v(t){if(this.options=Object.assign({},_,t),this.options.stopNodes&&Array.isArray(this.options.stopNodes)&&(this.options.stopNodes=this.options.stopNodes.map(t=>"string"==typeof t&&t.startsWith("*.")?".."+t.substring(2):t)),this.stopNodeExpressions=[],this.options.stopNodes&&Array.isArray(this.options.stopNodes))for(let t=0;t<this.options.stopNodes.length;t++){const e=this.options.stopNodes[t];"string"==typeof e?this.stopNodeExpressions.push(new i(e)):e instanceof i&&this.stopNodeExpressions.push(e)}var e;!0===this.options.ignoreAttributes||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.ignoreAttributesFn="function"==typeof(e=this.options.ignoreAttributes)?e:Array.isArray(e)?t=>{for(const i of e){if("string"==typeof i&&t===i)return!0;if(i instanceof RegExp&&i.test(t))return!0}}:()=>!1,this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=j),this.processTextOrObjNode=E,this.options.format?(this.indentate=O,this.tagEndChar=">\n",this.newLine="\n"):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}function w(t,e,i,s,n){return i.sanitizeName?d(t,{xmlVersion:n})?t:i.sanitizeName(t,{isAttribute:e,matcher:s.readOnly()}):t}function E(t,e,i,s,n){const r=this.extractAttributes(t);if(s.push(e,r),this.checkStopNode(s)){const n=this.buildRawContent(t),r=this.buildAttributesForStopNode(t);return s.pop(),this.buildObjectNode(n,e,r,i)}const o=this.j2x(t,i+1,s,n);return s.pop(),"?"===e[0]?this.buildTextValNode("",e,o.attrStr,i,s):void 0!==t[this.options.textNodeName]&&1===Object.keys(t).length?this.buildTextValNode(t[this.options.textNodeName],e,o.attrStr,i,s):this.buildObjectNode(o.val,e,o.attrStr,i)}function O(t){return this.options.indentBy.repeat(t)}function j(t){return!(!t.startsWith(this.options.attributeNamePrefix)||t===this.options.textNodeName)&&t.substr(this.attrPrefixLen)}v.prototype.build=function(t){if(this.options.preserveOrder)return m(t,this.options);{Array.isArray(t)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(t={[this.options.arrayNodeName]:t});const e=new n,i=function(t,e){const i=t["?xml"];if(i&&"object"==typeof i){if(e.attributesGroupName&&i[e.attributesGroupName]){const t=i[e.attributesGroupName][e.attributeNamePrefix+"version"];if(t)return t}const t=i[e.attributeNamePrefix+"version"];if(t)return t}return"1.0"}(t,this.options);return this.j2x(t,0,e,i).val}},v.prototype.j2x=function(t,e,i,s){let n="",r="";if(this.options.maxNestedTags&&i.getDepth()>=this.options.maxNestedTags)throw new Error("Maximum nested tags exceeded");const o=this.options.jPath?i.toString():i,a=this.checkStopNode(i);for(let h in t){if(!Object.prototype.hasOwnProperty.call(t,h))continue;const p=h===this.options.textNodeName||h===this.options.cdataPropName||h===this.options.commentPropName||this.options.attributesGroupName&&h===this.options.attributesGroupName||this.isAttribute(h)||"?"===h[0]?h:w(h,!1,this.options,i,s);if(void 0===t[h])this.isAttribute(h)&&(r+="");else if(null===t[h])this.isAttribute(h)||p===this.options.cdataPropName||p===this.options.commentPropName?r+="":"?"===p[0]?r+=this.indentate(e)+"<"+p+"?"+this.tagEndChar:r+=this.indentate(e)+"<"+p+"/"+this.tagEndChar;else if(t[h]instanceof Date)r+=this.buildTextValNode(t[h],p,"",e,i);else if("object"!=typeof t[h]){const u=this.isAttribute(h);if(u&&!this.ignoreAttributesFn(u,o)){const e=w(u,!0,this.options,i,s);n+=this.buildAttrPairStr(e,""+t[h],a)}else if(!u)if(h===this.options.textNodeName){let e=this.options.tagValueProcessor(h,""+t[h]);r+=this.replaceEntitiesValue(e)}else{i.push(p);const s=this.checkStopNode(i);if(i.pop(),s){const i=""+t[h];r+=""===i?this.indentate(e)+"<"+p+this.closeTag(p)+this.tagEndChar:this.indentate(e)+"<"+p+">"+i+"</"+p+this.tagEndChar}else r+=this.buildTextValNode(t[h],p,"",e,i)}}else if(Array.isArray(t[h])){const n=t[h].length;let o="",a="";for(let u=0;u<n;u++){const n=t[h][u];if(void 0===n);else if(null===n)"?"===p[0]?r+=this.indentate(e)+"<"+p+"?"+this.tagEndChar:r+=this.indentate(e)+"<"+p+"/"+this.tagEndChar;else if("object"==typeof n)if(this.options.oneListGroup){i.push(p);const t=this.j2x(n,e+1,i,s);i.pop(),o+=t.val,this.options.attributesGroupName&&n.hasOwnProperty(this.options.attributesGroupName)&&(a+=t.attrStr)}else o+=this.processTextOrObjNode(n,p,e,i,s);else if(this.options.oneListGroup){let t=this.options.tagValueProcessor(p,n);t=this.replaceEntitiesValue(t),o+=t}else{i.push(p);const t=this.checkStopNode(i);if(i.pop(),t){const t=""+n;o+=""===t?this.indentate(e)+"<"+p+this.closeTag(p)+this.tagEndChar:this.indentate(e)+"<"+p+">"+t+"</"+p+this.tagEndChar}else o+=this.buildTextValNode(n,p,"",e,i)}}this.options.oneListGroup&&(o=this.buildObjectNode(o,p,a,e)),r+=o}else if(this.options.attributesGroupName&&h===this.options.attributesGroupName){const e=Object.keys(t[h]),r=e.length;for(let o=0;o<r;o++){const r=w(e[o],!0,this.options,i,s);n+=this.buildAttrPairStr(r,""+t[h][e[o]],a)}}else r+=this.processTextOrObjNode(t[h],p,e,i,s)}return{attrStr:n,val:r}},v.prototype.buildAttrPairStr=function(t,e,i){return i||(e=this.options.attributeValueProcessor(t,""+e),e=this.replaceEntitiesValue(e)),this.options.suppressBooleanAttributes&&"true"===e?" "+t:" "+t+'="'+a(e)+'"'},v.prototype.extractAttributes=function(t){if(!t||"object"!=typeof t)return null;const e={};let i=!1;if(this.options.attributesGroupName&&t[this.options.attributesGroupName]){const s=t[this.options.attributesGroupName];for(let t in s)Object.prototype.hasOwnProperty.call(s,t)&&(e[t.startsWith(this.options.attributeNamePrefix)?t.substring(this.options.attributeNamePrefix.length):t]=a(s[t]),i=!0)}else for(let s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;const n=this.isAttribute(s);n&&(e[n]=a(t[s]),i=!0)}return i?e:null},v.prototype.buildRawContent=function(t){if("string"==typeof t)return t;if("object"!=typeof t||null===t)return String(t);if(void 0!==t[this.options.textNodeName])return t[this.options.textNodeName];let e="";for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;if(this.isAttribute(i))continue;if(this.options.attributesGroupName&&i===this.options.attributesGroupName)continue;const s=t[i];if(i===this.options.textNodeName)e+=s;else if(Array.isArray(s)){for(let t of s)if("string"==typeof t||"number"==typeof t)e+=`<${i}>${t}</${i}>`;else if("object"==typeof t&&null!==t){const s=this.buildRawContent(t),n=this.buildAttributesForStopNode(t);e+=""===s?`<${i}${n}/>`:`<${i}${n}>${s}</${i}>`}}else if("object"==typeof s&&null!==s){const t=this.buildRawContent(s),n=this.buildAttributesForStopNode(s);e+=""===t?`<${i}${n}/>`:`<${i}${n}>${t}</${i}>`}else e+=`<${i}>${s}</${i}>`}return e},v.prototype.buildAttributesForStopNode=function(t){if(!t||"object"!=typeof t)return"";let e="";if(this.options.attributesGroupName&&t[this.options.attributesGroupName]){const i=t[this.options.attributesGroupName];for(let t in i){if(!Object.prototype.hasOwnProperty.call(i,t))continue;const s=t.startsWith(this.options.attributeNamePrefix)?t.substring(this.options.attributeNamePrefix.length):t,n=i[t];!0===n&&this.options.suppressBooleanAttributes?e+=" "+s:e+=" "+s+'="'+n+'"'}}else for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;const s=this.isAttribute(i);if(s){const n=t[i];!0===n&&this.options.suppressBooleanAttributes?e+=" "+s:e+=" "+s+'="'+n+'"'}}return e},v.prototype.buildObjectNode=function(t,e,i,s){if(""===t)return"?"===e[0]?this.indentate(s)+"<"+e+i+"?"+this.tagEndChar:this.indentate(s)+"<"+e+i+this.closeTag(e)+this.tagEndChar;if("?"===e[0])return this.indentate(s)+"<"+e+i+"?"+this.tagEndChar;{let n="</"+e+this.tagEndChar,r="";return"?"===e[0]&&(r="?",n=""),!i&&""!==i||-1!==t.indexOf("<")?!1!==this.options.commentPropName&&e===this.options.commentPropName&&0===r.length?this.indentate(s)+`\x3c!--${t}--\x3e`+this.newLine:this.indentate(s)+"<"+e+i+r+this.tagEndChar+t+this.indentate(s)+n:this.indentate(s)+"<"+e+i+r+">"+t+n}},v.prototype.closeTag=function(t){let e="";return-1!==this.options.unpairedTags.indexOf(t)?this.options.suppressUnpairedNode||(e="/"):e=this.options.suppressEmptyNode?"/":`></${t}`,e},v.prototype.checkStopNode=function(t){if(!this.stopNodeExpressions||0===this.stopNodeExpressions.length)return!1;for(let e=0;e<this.stopNodeExpressions.length;e++)if(t.matches(this.stopNodeExpressions[e]))return!0;return!1},v.prototype.buildTextValNode=function(t,e,i,s,n){if(!1!==this.options.cdataPropName&&e===this.options.cdataPropName){const e=o(t);return this.indentate(s)+`<![CDATA[${e}]]>`+this.newLine}if(!1!==this.options.commentPropName&&e===this.options.commentPropName){const e=r(t);return this.indentate(s)+`\x3c!--${e}--\x3e`+this.newLine}if("?"===e[0])return this.indentate(s)+"<"+e+i+"?"+this.tagEndChar;{let n=this.options.tagValueProcessor(e,t);return n=this.replaceEntitiesValue(n),""===n?this.indentate(s)+"<"+e+i+this.closeTag(e)+this.tagEndChar:this.indentate(s)+"<"+e+i+">"+n+"</"+e+this.tagEndChar}},v.prototype.replaceEntitiesValue=function(t){if(t&&t.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){const i=this.options.entities[e];t=t.replace(i.regex,i.val)}return t};const C=v;return e})());
|
|
2
2
|
//# sourceMappingURL=fxbuilder.min.js.map
|