@cj-tech-master/excelts 7.3.0 → 7.4.0-canary.20260402030331.3ae7f67
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/dist/browser/modules/xml/dom.d.ts +1 -1
- package/dist/browser/modules/xml/dom.js +7 -5
- package/dist/browser/modules/xml/to-object-shared.d.ts +3 -1
- package/dist/browser/modules/xml/to-object-shared.js +6 -3
- package/dist/browser/modules/xml/to-object.js +6 -6
- package/dist/browser/modules/xml/types.d.ts +16 -1
- package/dist/cjs/modules/xml/dom.js +7 -5
- package/dist/cjs/modules/xml/to-object-shared.js +6 -3
- package/dist/cjs/modules/xml/to-object.js +6 -6
- package/dist/esm/modules/xml/dom.js +7 -5
- package/dist/esm/modules/xml/to-object-shared.js +6 -3
- package/dist/esm/modules/xml/to-object.js +6 -6
- package/dist/iife/excelts.iife.js +1 -1
- package/dist/iife/excelts.iife.min.js +1 -1
- package/dist/types/modules/xml/dom.d.ts +1 -1
- package/dist/types/modules/xml/to-object-shared.d.ts +3 -1
- package/dist/types/modules/xml/types.d.ts +16 -1
- package/package.json +1 -1
|
@@ -52,7 +52,7 @@ declare function walk(element: XmlElement, visitor: (el: XmlElement) => void): v
|
|
|
52
52
|
/**
|
|
53
53
|
* Convert an {@link XmlElement} DOM tree to a plain JavaScript object.
|
|
54
54
|
*
|
|
55
|
-
* Produces
|
|
55
|
+
* Produces a plain JavaScript object where element names become object keys,
|
|
56
56
|
* attributes are prefixed (default `@_`), text-only elements collapse to their
|
|
57
57
|
* string value, and repeated sibling names merge into arrays.
|
|
58
58
|
*
|
|
@@ -256,7 +256,7 @@ function walk(element, visitor) {
|
|
|
256
256
|
/**
|
|
257
257
|
* Convert an {@link XmlElement} DOM tree to a plain JavaScript object.
|
|
258
258
|
*
|
|
259
|
-
* Produces
|
|
259
|
+
* Produces a plain JavaScript object where element names become object keys,
|
|
260
260
|
* attributes are prefixed (default `@_`), text-only elements collapse to their
|
|
261
261
|
* string value, and repeated sibling names merge into arrays.
|
|
262
262
|
*
|
|
@@ -285,9 +285,11 @@ function toPlainObject(element, options) {
|
|
|
285
285
|
// Add attributes — el.attributes is created via Object.create(null)
|
|
286
286
|
// by safeAttributes(), so no prototype keys to guard against.
|
|
287
287
|
let hasAttributes = false;
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
288
|
+
if (!opts.ignoreAttributes) {
|
|
289
|
+
for (const key in el.attributes) {
|
|
290
|
+
obj[opts.attrPrefix + key] = el.attributes[key];
|
|
291
|
+
hasAttributes = true;
|
|
292
|
+
}
|
|
291
293
|
}
|
|
292
294
|
// Collect text and child elements in a single pass.
|
|
293
295
|
let text = "";
|
|
@@ -304,7 +306,7 @@ function toPlainObject(element, options) {
|
|
|
304
306
|
break;
|
|
305
307
|
case "element": {
|
|
306
308
|
const value = convertElement(child);
|
|
307
|
-
addChildValue(obj, child.name, value, opts.alwaysArray);
|
|
309
|
+
addChildValue(obj, child.name, value, opts.alwaysArray, opts.isArray);
|
|
308
310
|
hasChildren = true;
|
|
309
311
|
break;
|
|
310
312
|
}
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
import type { ToPlainObjectOptions } from "./types.js";
|
|
8
8
|
/** Options with all defaults resolved — no more `??` checks at hot-path call sites. */
|
|
9
9
|
export interface ResolvedOptions {
|
|
10
|
+
readonly ignoreAttributes: boolean;
|
|
10
11
|
readonly attrPrefix: string;
|
|
11
12
|
readonly textKey: string;
|
|
12
13
|
readonly alwaysArray: boolean;
|
|
14
|
+
readonly isArray: ((name: string) => boolean) | null;
|
|
13
15
|
readonly preserveCData: boolean;
|
|
14
16
|
readonly ignoreWS: boolean;
|
|
15
17
|
}
|
|
@@ -26,4 +28,4 @@ export declare function resolveValue(obj: Record<string, unknown>, text: string,
|
|
|
26
28
|
* Add a resolved child value into a parent object, merging repeated names
|
|
27
29
|
* into arrays.
|
|
28
30
|
*/
|
|
29
|
-
export declare function addChildValue(parent: Record<string, unknown>, name: string, value: unknown, alwaysArray: boolean): void;
|
|
31
|
+
export declare function addChildValue(parent: Record<string, unknown>, name: string, value: unknown, alwaysArray: boolean, isArray: ((name: string) => boolean) | null): void;
|
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export function resolveOptions(options) {
|
|
8
8
|
return {
|
|
9
|
+
ignoreAttributes: options?.ignoreAttributes ?? false,
|
|
9
10
|
attrPrefix: options?.attributePrefix ?? "@_",
|
|
10
11
|
textKey: options?.textKey ?? "#text",
|
|
11
12
|
alwaysArray: options?.alwaysArray ?? false,
|
|
13
|
+
isArray: options?.isArray ?? null,
|
|
12
14
|
preserveCData: options?.preserveCData ?? true,
|
|
13
15
|
ignoreWS: options?.ignoreWhitespaceText ?? true
|
|
14
16
|
};
|
|
@@ -51,7 +53,7 @@ export function resolveValue(obj, text, hasAttributes, hasChildren, opts) {
|
|
|
51
53
|
if (hasText) {
|
|
52
54
|
obj[opts.textKey] = text;
|
|
53
55
|
}
|
|
54
|
-
// Empty element with no attributes → empty string
|
|
56
|
+
// Empty element with no attributes → empty string
|
|
55
57
|
if (!hasAttributes && !hasChildren && !hasText) {
|
|
56
58
|
return "";
|
|
57
59
|
}
|
|
@@ -64,7 +66,7 @@ export function resolveValue(obj, text, hasAttributes, hasChildren, opts) {
|
|
|
64
66
|
* Add a resolved child value into a parent object, merging repeated names
|
|
65
67
|
* into arrays.
|
|
66
68
|
*/
|
|
67
|
-
export function addChildValue(parent, name, value, alwaysArray) {
|
|
69
|
+
export function addChildValue(parent, name, value, alwaysArray, isArray) {
|
|
68
70
|
const existing = parent[name];
|
|
69
71
|
if (existing !== undefined) {
|
|
70
72
|
if (Array.isArray(existing)) {
|
|
@@ -75,6 +77,7 @@ export function addChildValue(parent, name, value, alwaysArray) {
|
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
79
|
else {
|
|
78
|
-
|
|
80
|
+
const wrap = alwaysArray || (isArray !== null && isArray(name));
|
|
81
|
+
parent[name] = wrap ? [value] : value;
|
|
79
82
|
}
|
|
80
83
|
}
|
|
@@ -64,9 +64,11 @@ function parseXmlToObject(xml, options) {
|
|
|
64
64
|
name: tag.name
|
|
65
65
|
};
|
|
66
66
|
// Write attributes directly into frame.obj
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
if (!opts.ignoreAttributes) {
|
|
68
|
+
for (const key in tag.attributes) {
|
|
69
|
+
frame.obj[opts.attrPrefix + key] = tag.attributes[key];
|
|
70
|
+
frame.hasAttributes = true;
|
|
71
|
+
}
|
|
70
72
|
}
|
|
71
73
|
// Mark parent as having children
|
|
72
74
|
stack[stack.length - 1].hasChildren = true;
|
|
@@ -113,9 +115,7 @@ function parseXmlToObject(xml, options) {
|
|
|
113
115
|
*/
|
|
114
116
|
function finishFrame(frame, parent, opts) {
|
|
115
117
|
const value = resolveValue(frame.obj, frame.text, frame.hasAttributes, frame.hasChildren, opts);
|
|
116
|
-
// The document root element (child of synthetic root) should never be
|
|
117
|
-
// wrapped in an array by alwaysArray — it's always a direct value.
|
|
118
118
|
const isDocRoot = parent.name === "";
|
|
119
|
-
addChildValue(parent.obj, frame.name, value, isDocRoot ? false : opts.alwaysArray);
|
|
119
|
+
addChildValue(parent.obj, frame.name, value, isDocRoot ? false : opts.alwaysArray, isDocRoot ? null : opts.isArray);
|
|
120
120
|
}
|
|
121
121
|
export { parseXmlToObject };
|
|
@@ -202,12 +202,20 @@ export interface WritableTarget {
|
|
|
202
202
|
* Options for `toPlainObject()`.
|
|
203
203
|
*
|
|
204
204
|
* Controls how an {@link XmlElement} DOM tree is converted to a plain
|
|
205
|
-
* JavaScript object
|
|
205
|
+
* JavaScript object.
|
|
206
206
|
*/
|
|
207
207
|
export interface ToPlainObjectOptions {
|
|
208
|
+
/**
|
|
209
|
+
* When true, discard all attributes entirely. Takes precedence over
|
|
210
|
+
* `attributePrefix` — when `ignoreAttributes` is true, no attribute keys
|
|
211
|
+
* appear in the output regardless of prefix settings.
|
|
212
|
+
* @default false
|
|
213
|
+
*/
|
|
214
|
+
ignoreAttributes?: boolean;
|
|
208
215
|
/**
|
|
209
216
|
* Prefix for attribute keys.
|
|
210
217
|
* Set to `""` to use bare attribute names.
|
|
218
|
+
* Ignored when `ignoreAttributes` is true.
|
|
211
219
|
* @default "@_"
|
|
212
220
|
*/
|
|
213
221
|
attributePrefix?: string;
|
|
@@ -223,6 +231,13 @@ export interface ToPlainObjectOptions {
|
|
|
223
231
|
* @default false
|
|
224
232
|
*/
|
|
225
233
|
alwaysArray?: boolean;
|
|
234
|
+
/**
|
|
235
|
+
* Callback to determine whether a specific tag name should always be wrapped
|
|
236
|
+
* in an array, even if only a single element exists. Takes precedence over
|
|
237
|
+
* `alwaysArray` for matching names. When both `isArray` and `alwaysArray` are
|
|
238
|
+
* set, a tag is wrapped if either returns/is true.
|
|
239
|
+
*/
|
|
240
|
+
isArray?: (name: string) => boolean;
|
|
226
241
|
/**
|
|
227
242
|
* When true, include CDATA node values (already merged to text by default
|
|
228
243
|
* in `parseXml`, only relevant with `cdataAsNodes`).
|
|
@@ -265,7 +265,7 @@ function walk(element, visitor) {
|
|
|
265
265
|
/**
|
|
266
266
|
* Convert an {@link XmlElement} DOM tree to a plain JavaScript object.
|
|
267
267
|
*
|
|
268
|
-
* Produces
|
|
268
|
+
* Produces a plain JavaScript object where element names become object keys,
|
|
269
269
|
* attributes are prefixed (default `@_`), text-only elements collapse to their
|
|
270
270
|
* string value, and repeated sibling names merge into arrays.
|
|
271
271
|
*
|
|
@@ -294,9 +294,11 @@ function toPlainObject(element, options) {
|
|
|
294
294
|
// Add attributes — el.attributes is created via Object.create(null)
|
|
295
295
|
// by safeAttributes(), so no prototype keys to guard against.
|
|
296
296
|
let hasAttributes = false;
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
297
|
+
if (!opts.ignoreAttributes) {
|
|
298
|
+
for (const key in el.attributes) {
|
|
299
|
+
obj[opts.attrPrefix + key] = el.attributes[key];
|
|
300
|
+
hasAttributes = true;
|
|
301
|
+
}
|
|
300
302
|
}
|
|
301
303
|
// Collect text and child elements in a single pass.
|
|
302
304
|
let text = "";
|
|
@@ -313,7 +315,7 @@ function toPlainObject(element, options) {
|
|
|
313
315
|
break;
|
|
314
316
|
case "element": {
|
|
315
317
|
const value = convertElement(child);
|
|
316
|
-
(0, to_object_shared_1.addChildValue)(obj, child.name, value, opts.alwaysArray);
|
|
318
|
+
(0, to_object_shared_1.addChildValue)(obj, child.name, value, opts.alwaysArray, opts.isArray);
|
|
317
319
|
hasChildren = true;
|
|
318
320
|
break;
|
|
319
321
|
}
|
|
@@ -11,9 +11,11 @@ exports.resolveValue = resolveValue;
|
|
|
11
11
|
exports.addChildValue = addChildValue;
|
|
12
12
|
function resolveOptions(options) {
|
|
13
13
|
return {
|
|
14
|
+
ignoreAttributes: options?.ignoreAttributes ?? false,
|
|
14
15
|
attrPrefix: options?.attributePrefix ?? "@_",
|
|
15
16
|
textKey: options?.textKey ?? "#text",
|
|
16
17
|
alwaysArray: options?.alwaysArray ?? false,
|
|
18
|
+
isArray: options?.isArray ?? null,
|
|
17
19
|
preserveCData: options?.preserveCData ?? true,
|
|
18
20
|
ignoreWS: options?.ignoreWhitespaceText ?? true
|
|
19
21
|
};
|
|
@@ -56,7 +58,7 @@ function resolveValue(obj, text, hasAttributes, hasChildren, opts) {
|
|
|
56
58
|
if (hasText) {
|
|
57
59
|
obj[opts.textKey] = text;
|
|
58
60
|
}
|
|
59
|
-
// Empty element with no attributes → empty string
|
|
61
|
+
// Empty element with no attributes → empty string
|
|
60
62
|
if (!hasAttributes && !hasChildren && !hasText) {
|
|
61
63
|
return "";
|
|
62
64
|
}
|
|
@@ -69,7 +71,7 @@ function resolveValue(obj, text, hasAttributes, hasChildren, opts) {
|
|
|
69
71
|
* Add a resolved child value into a parent object, merging repeated names
|
|
70
72
|
* into arrays.
|
|
71
73
|
*/
|
|
72
|
-
function addChildValue(parent, name, value, alwaysArray) {
|
|
74
|
+
function addChildValue(parent, name, value, alwaysArray, isArray) {
|
|
73
75
|
const existing = parent[name];
|
|
74
76
|
if (existing !== undefined) {
|
|
75
77
|
if (Array.isArray(existing)) {
|
|
@@ -80,6 +82,7 @@ function addChildValue(parent, name, value, alwaysArray) {
|
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
84
|
else {
|
|
83
|
-
|
|
85
|
+
const wrap = alwaysArray || (isArray !== null && isArray(name));
|
|
86
|
+
parent[name] = wrap ? [value] : value;
|
|
84
87
|
}
|
|
85
88
|
}
|
|
@@ -67,9 +67,11 @@ function parseXmlToObject(xml, options) {
|
|
|
67
67
|
name: tag.name
|
|
68
68
|
};
|
|
69
69
|
// Write attributes directly into frame.obj
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
if (!opts.ignoreAttributes) {
|
|
71
|
+
for (const key in tag.attributes) {
|
|
72
|
+
frame.obj[opts.attrPrefix + key] = tag.attributes[key];
|
|
73
|
+
frame.hasAttributes = true;
|
|
74
|
+
}
|
|
73
75
|
}
|
|
74
76
|
// Mark parent as having children
|
|
75
77
|
stack[stack.length - 1].hasChildren = true;
|
|
@@ -116,8 +118,6 @@ function parseXmlToObject(xml, options) {
|
|
|
116
118
|
*/
|
|
117
119
|
function finishFrame(frame, parent, opts) {
|
|
118
120
|
const value = (0, to_object_shared_1.resolveValue)(frame.obj, frame.text, frame.hasAttributes, frame.hasChildren, opts);
|
|
119
|
-
// The document root element (child of synthetic root) should never be
|
|
120
|
-
// wrapped in an array by alwaysArray — it's always a direct value.
|
|
121
121
|
const isDocRoot = parent.name === "";
|
|
122
|
-
(0, to_object_shared_1.addChildValue)(parent.obj, frame.name, value, isDocRoot ? false : opts.alwaysArray);
|
|
122
|
+
(0, to_object_shared_1.addChildValue)(parent.obj, frame.name, value, isDocRoot ? false : opts.alwaysArray, isDocRoot ? null : opts.isArray);
|
|
123
123
|
}
|
|
@@ -256,7 +256,7 @@ function walk(element, visitor) {
|
|
|
256
256
|
/**
|
|
257
257
|
* Convert an {@link XmlElement} DOM tree to a plain JavaScript object.
|
|
258
258
|
*
|
|
259
|
-
* Produces
|
|
259
|
+
* Produces a plain JavaScript object where element names become object keys,
|
|
260
260
|
* attributes are prefixed (default `@_`), text-only elements collapse to their
|
|
261
261
|
* string value, and repeated sibling names merge into arrays.
|
|
262
262
|
*
|
|
@@ -285,9 +285,11 @@ function toPlainObject(element, options) {
|
|
|
285
285
|
// Add attributes — el.attributes is created via Object.create(null)
|
|
286
286
|
// by safeAttributes(), so no prototype keys to guard against.
|
|
287
287
|
let hasAttributes = false;
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
288
|
+
if (!opts.ignoreAttributes) {
|
|
289
|
+
for (const key in el.attributes) {
|
|
290
|
+
obj[opts.attrPrefix + key] = el.attributes[key];
|
|
291
|
+
hasAttributes = true;
|
|
292
|
+
}
|
|
291
293
|
}
|
|
292
294
|
// Collect text and child elements in a single pass.
|
|
293
295
|
let text = "";
|
|
@@ -304,7 +306,7 @@ function toPlainObject(element, options) {
|
|
|
304
306
|
break;
|
|
305
307
|
case "element": {
|
|
306
308
|
const value = convertElement(child);
|
|
307
|
-
addChildValue(obj, child.name, value, opts.alwaysArray);
|
|
309
|
+
addChildValue(obj, child.name, value, opts.alwaysArray, opts.isArray);
|
|
308
310
|
hasChildren = true;
|
|
309
311
|
break;
|
|
310
312
|
}
|
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export function resolveOptions(options) {
|
|
8
8
|
return {
|
|
9
|
+
ignoreAttributes: options?.ignoreAttributes ?? false,
|
|
9
10
|
attrPrefix: options?.attributePrefix ?? "@_",
|
|
10
11
|
textKey: options?.textKey ?? "#text",
|
|
11
12
|
alwaysArray: options?.alwaysArray ?? false,
|
|
13
|
+
isArray: options?.isArray ?? null,
|
|
12
14
|
preserveCData: options?.preserveCData ?? true,
|
|
13
15
|
ignoreWS: options?.ignoreWhitespaceText ?? true
|
|
14
16
|
};
|
|
@@ -51,7 +53,7 @@ export function resolveValue(obj, text, hasAttributes, hasChildren, opts) {
|
|
|
51
53
|
if (hasText) {
|
|
52
54
|
obj[opts.textKey] = text;
|
|
53
55
|
}
|
|
54
|
-
// Empty element with no attributes → empty string
|
|
56
|
+
// Empty element with no attributes → empty string
|
|
55
57
|
if (!hasAttributes && !hasChildren && !hasText) {
|
|
56
58
|
return "";
|
|
57
59
|
}
|
|
@@ -64,7 +66,7 @@ export function resolveValue(obj, text, hasAttributes, hasChildren, opts) {
|
|
|
64
66
|
* Add a resolved child value into a parent object, merging repeated names
|
|
65
67
|
* into arrays.
|
|
66
68
|
*/
|
|
67
|
-
export function addChildValue(parent, name, value, alwaysArray) {
|
|
69
|
+
export function addChildValue(parent, name, value, alwaysArray, isArray) {
|
|
68
70
|
const existing = parent[name];
|
|
69
71
|
if (existing !== undefined) {
|
|
70
72
|
if (Array.isArray(existing)) {
|
|
@@ -75,6 +77,7 @@ export function addChildValue(parent, name, value, alwaysArray) {
|
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
79
|
else {
|
|
78
|
-
|
|
80
|
+
const wrap = alwaysArray || (isArray !== null && isArray(name));
|
|
81
|
+
parent[name] = wrap ? [value] : value;
|
|
79
82
|
}
|
|
80
83
|
}
|
|
@@ -64,9 +64,11 @@ function parseXmlToObject(xml, options) {
|
|
|
64
64
|
name: tag.name
|
|
65
65
|
};
|
|
66
66
|
// Write attributes directly into frame.obj
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
if (!opts.ignoreAttributes) {
|
|
68
|
+
for (const key in tag.attributes) {
|
|
69
|
+
frame.obj[opts.attrPrefix + key] = tag.attributes[key];
|
|
70
|
+
frame.hasAttributes = true;
|
|
71
|
+
}
|
|
70
72
|
}
|
|
71
73
|
// Mark parent as having children
|
|
72
74
|
stack[stack.length - 1].hasChildren = true;
|
|
@@ -113,9 +115,7 @@ function parseXmlToObject(xml, options) {
|
|
|
113
115
|
*/
|
|
114
116
|
function finishFrame(frame, parent, opts) {
|
|
115
117
|
const value = resolveValue(frame.obj, frame.text, frame.hasAttributes, frame.hasChildren, opts);
|
|
116
|
-
// The document root element (child of synthetic root) should never be
|
|
117
|
-
// wrapped in an array by alwaysArray — it's always a direct value.
|
|
118
118
|
const isDocRoot = parent.name === "";
|
|
119
|
-
addChildValue(parent.obj, frame.name, value, isDocRoot ? false : opts.alwaysArray);
|
|
119
|
+
addChildValue(parent.obj, frame.name, value, isDocRoot ? false : opts.alwaysArray, isDocRoot ? null : opts.isArray);
|
|
120
120
|
}
|
|
121
121
|
export { parseXmlToObject };
|
|
@@ -52,7 +52,7 @@ declare function walk(element: XmlElement, visitor: (el: XmlElement) => void): v
|
|
|
52
52
|
/**
|
|
53
53
|
* Convert an {@link XmlElement} DOM tree to a plain JavaScript object.
|
|
54
54
|
*
|
|
55
|
-
* Produces
|
|
55
|
+
* Produces a plain JavaScript object where element names become object keys,
|
|
56
56
|
* attributes are prefixed (default `@_`), text-only elements collapse to their
|
|
57
57
|
* string value, and repeated sibling names merge into arrays.
|
|
58
58
|
*
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
import type { ToPlainObjectOptions } from "./types.js";
|
|
8
8
|
/** Options with all defaults resolved — no more `??` checks at hot-path call sites. */
|
|
9
9
|
export interface ResolvedOptions {
|
|
10
|
+
readonly ignoreAttributes: boolean;
|
|
10
11
|
readonly attrPrefix: string;
|
|
11
12
|
readonly textKey: string;
|
|
12
13
|
readonly alwaysArray: boolean;
|
|
14
|
+
readonly isArray: ((name: string) => boolean) | null;
|
|
13
15
|
readonly preserveCData: boolean;
|
|
14
16
|
readonly ignoreWS: boolean;
|
|
15
17
|
}
|
|
@@ -26,4 +28,4 @@ export declare function resolveValue(obj: Record<string, unknown>, text: string,
|
|
|
26
28
|
* Add a resolved child value into a parent object, merging repeated names
|
|
27
29
|
* into arrays.
|
|
28
30
|
*/
|
|
29
|
-
export declare function addChildValue(parent: Record<string, unknown>, name: string, value: unknown, alwaysArray: boolean): void;
|
|
31
|
+
export declare function addChildValue(parent: Record<string, unknown>, name: string, value: unknown, alwaysArray: boolean, isArray: ((name: string) => boolean) | null): void;
|
|
@@ -202,12 +202,20 @@ export interface WritableTarget {
|
|
|
202
202
|
* Options for `toPlainObject()`.
|
|
203
203
|
*
|
|
204
204
|
* Controls how an {@link XmlElement} DOM tree is converted to a plain
|
|
205
|
-
* JavaScript object
|
|
205
|
+
* JavaScript object.
|
|
206
206
|
*/
|
|
207
207
|
export interface ToPlainObjectOptions {
|
|
208
|
+
/**
|
|
209
|
+
* When true, discard all attributes entirely. Takes precedence over
|
|
210
|
+
* `attributePrefix` — when `ignoreAttributes` is true, no attribute keys
|
|
211
|
+
* appear in the output regardless of prefix settings.
|
|
212
|
+
* @default false
|
|
213
|
+
*/
|
|
214
|
+
ignoreAttributes?: boolean;
|
|
208
215
|
/**
|
|
209
216
|
* Prefix for attribute keys.
|
|
210
217
|
* Set to `""` to use bare attribute names.
|
|
218
|
+
* Ignored when `ignoreAttributes` is true.
|
|
211
219
|
* @default "@_"
|
|
212
220
|
*/
|
|
213
221
|
attributePrefix?: string;
|
|
@@ -223,6 +231,13 @@ export interface ToPlainObjectOptions {
|
|
|
223
231
|
* @default false
|
|
224
232
|
*/
|
|
225
233
|
alwaysArray?: boolean;
|
|
234
|
+
/**
|
|
235
|
+
* Callback to determine whether a specific tag name should always be wrapped
|
|
236
|
+
* in an array, even if only a single element exists. Takes precedence over
|
|
237
|
+
* `alwaysArray` for matching names. When both `isArray` and `alwaysArray` are
|
|
238
|
+
* set, a tag is wrapped if either returns/is true.
|
|
239
|
+
*/
|
|
240
|
+
isArray?: (name: string) => boolean;
|
|
226
241
|
/**
|
|
227
242
|
* When true, include CDATA node values (already merged to text by default
|
|
228
243
|
* in `parseXml`, only relevant with `cdataAsNodes`).
|
package/package.json
CHANGED