@cj-tech-master/excelts 7.4.0 → 7.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/modules/xml/dom.d.ts +1 -1
- package/dist/browser/modules/xml/dom.js +6 -4
- package/dist/browser/modules/xml/to-object-shared.d.ts +1 -0
- package/dist/browser/modules/xml/to-object-shared.js +2 -1
- package/dist/browser/modules/xml/to-object.js +5 -3
- package/dist/browser/modules/xml/types.d.ts +9 -1
- package/dist/cjs/modules/xml/dom.js +6 -4
- package/dist/cjs/modules/xml/to-object-shared.js +2 -1
- package/dist/cjs/modules/xml/to-object.js +5 -3
- package/dist/esm/modules/xml/dom.js +6 -4
- package/dist/esm/modules/xml/to-object-shared.js +2 -1
- package/dist/esm/modules/xml/to-object.js +5 -3
- 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 +1 -0
- package/dist/types/modules/xml/types.d.ts +9 -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 = "";
|
|
@@ -7,6 +7,7 @@
|
|
|
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;
|
|
@@ -6,6 +6,7 @@
|
|
|
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,
|
|
@@ -52,7 +53,7 @@ export function resolveValue(obj, text, hasAttributes, hasChildren, opts) {
|
|
|
52
53
|
if (hasText) {
|
|
53
54
|
obj[opts.textKey] = text;
|
|
54
55
|
}
|
|
55
|
-
// Empty element with no attributes → empty string
|
|
56
|
+
// Empty element with no attributes → empty string
|
|
56
57
|
if (!hasAttributes && !hasChildren && !hasText) {
|
|
57
58
|
return "";
|
|
58
59
|
}
|
|
@@ -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;
|
|
@@ -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;
|
|
@@ -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 = "";
|
|
@@ -11,6 +11,7 @@ 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,
|
|
@@ -57,7 +58,7 @@ function resolveValue(obj, text, hasAttributes, hasChildren, opts) {
|
|
|
57
58
|
if (hasText) {
|
|
58
59
|
obj[opts.textKey] = text;
|
|
59
60
|
}
|
|
60
|
-
// Empty element with no attributes → empty string
|
|
61
|
+
// Empty element with no attributes → empty string
|
|
61
62
|
if (!hasAttributes && !hasChildren && !hasText) {
|
|
62
63
|
return "";
|
|
63
64
|
}
|
|
@@ -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;
|
|
@@ -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 = "";
|
|
@@ -6,6 +6,7 @@
|
|
|
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,
|
|
@@ -52,7 +53,7 @@ export function resolveValue(obj, text, hasAttributes, hasChildren, opts) {
|
|
|
52
53
|
if (hasText) {
|
|
53
54
|
obj[opts.textKey] = text;
|
|
54
55
|
}
|
|
55
|
-
// Empty element with no attributes → empty string
|
|
56
|
+
// Empty element with no attributes → empty string
|
|
56
57
|
if (!hasAttributes && !hasChildren && !hasText) {
|
|
57
58
|
return "";
|
|
58
59
|
}
|
|
@@ -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;
|
|
@@ -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,6 +7,7 @@
|
|
|
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;
|
|
@@ -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;
|