@office-open/xml 0.6.8 → 0.6.10
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/README.md +10 -10
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +30 -19
- package/dist/{utils-DTU54qj_.d.mts → utils-DJSm61Ws.d.mts} +1 -1
- package/dist/utils.d.mts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -103,31 +103,31 @@ Performance comparison against original `xml` (1.0.1) and `xml-js` (1.6.11) pack
|
|
|
103
103
|
|
|
104
104
|
| Scenario | @office-open/xml | xml | Speedup |
|
|
105
105
|
| ----------------------- | ---------------: | ---------: | --------: |
|
|
106
|
-
| Simple element | 5,
|
|
107
|
-
| Nested element |
|
|
108
|
-
| Nested with declaration |
|
|
106
|
+
| Simple element | 5,069,751 hz | 724,533 hz | **7.00x** |
|
|
107
|
+
| Nested element | 1,122,376 hz | 279,423 hz | **4.02x** |
|
|
108
|
+
| Nested with declaration | 1,050,046 hz | 248,678 hz | **4.22x** |
|
|
109
109
|
|
|
110
110
|
### Parsing (xml2js)
|
|
111
111
|
|
|
112
112
|
| Scenario | @office-open/xml | xml-js | Speedup |
|
|
113
113
|
| ------------------ | ---------------: | --------: | ---------: |
|
|
114
|
-
| Simple XML | 1,
|
|
115
|
-
| Complex OOXML |
|
|
116
|
-
| With captureSpaces |
|
|
114
|
+
| Simple XML | 1,000,869 hz | 90,488 hz | **11.06x** |
|
|
115
|
+
| Complex OOXML | 310,266 hz | 42,938 hz | **7.23x** |
|
|
116
|
+
| With captureSpaces | 313,183 hz | 41,814 hz | **7.49x** |
|
|
117
117
|
|
|
118
118
|
### Stringifying (js2xml)
|
|
119
119
|
|
|
120
120
|
| Scenario | @office-open/xml | xml-js | Speedup |
|
|
121
121
|
| -------------- | ---------------: | ---------: | --------: |
|
|
122
|
-
| Simple element |
|
|
123
|
-
| Complex OOXML |
|
|
122
|
+
| Simple element | 975,878 hz | 198,953 hz | **4.90x** |
|
|
123
|
+
| Complex OOXML | 492,220 hz | 107,815 hz | **4.57x** |
|
|
124
124
|
|
|
125
125
|
### Direct Conversion (toElement vs bridge)
|
|
126
126
|
|
|
127
127
|
| Scenario | toElement() | xml() + xml2js() bridge | Speedup |
|
|
128
128
|
| -------- | ------------: | ----------------------: | ---------: |
|
|
129
|
-
| Simple | 13,
|
|
130
|
-
| Nested |
|
|
129
|
+
| Simple | 13,199,415 hz | 805,104 hz | **16.40x** |
|
|
130
|
+
| Nested | 4,207,319 hz | 458,333 hz | **9.18x** |
|
|
131
131
|
|
|
132
132
|
## Bundle Size
|
|
133
133
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { C as XmlAttrs, D as XmlOption, E as XmlObject, S as XmlAtom, T as XmlDescArray, _ as ElementCompact, a as childCount, b as Js2XmlOptions, c as collectText, d as findDeep, f as hasChild, g as Element, h as DeclarationAttributes, i as attrNum, l as colorAttr, m as Attributes, n as attr, o as childText, p as textOf, r as attrBool, s as children, t as allChildren, u as findChild, v as ElementObject, w as XmlDesc, x as Xml2JsOptions, y as IgnoreOptions } from "./utils-
|
|
1
|
+
import { C as XmlAttrs, D as XmlOption, E as XmlObject, S as XmlAtom, T as XmlDescArray, _ as ElementCompact, a as childCount, b as Js2XmlOptions, c as collectText, d as findDeep, f as hasChild, g as Element, h as DeclarationAttributes, i as attrNum, l as colorAttr, m as Attributes, n as attr, o as childText, p as textOf, r as attrBool, s as children, t as allChildren, u as findChild, v as ElementObject, w as XmlDesc, x as Xml2JsOptions, y as IgnoreOptions } from "./utils-DJSm61Ws.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/serialize.d.ts
|
|
4
|
-
declare function xml(input: Record<string,
|
|
4
|
+
declare function xml(input: Record<string, unknown> | Record<string, unknown>[], options?: boolean | string | {
|
|
5
5
|
indent?: boolean | string;
|
|
6
6
|
declaration?: boolean | {
|
|
7
7
|
encoding?: string;
|
|
@@ -50,4 +50,4 @@ declare function selfCloseElement(tag: string, attrStr?: string): string;
|
|
|
50
50
|
/** Convert XML string to JSON string — xml-js compatible export */
|
|
51
51
|
declare function xml2json(xml: string, options?: Xml2JsOptions): string;
|
|
52
52
|
//#endregion
|
|
53
|
-
export { Attributes, DeclarationAttributes, Element, ElementCompact, ElementObject, IgnoreOptions, Js2XmlOptions, Xml2JsOptions, XmlAtom, XmlAttrs, XmlDesc, XmlDescArray, XmlObject, XmlOption, allChildren, attr, attrBool, attrNum, attrs, childCount, childText, children, collectText, colorAttr, escapeXml, findChild, findDeep, hasChild, js2xml, json2xml, nativeTypeValue, parseAttributes, selfCloseElement, textOf, toElement, unescapeXml, xml, xml2js, xml2json };
|
|
53
|
+
export { type Attributes, type DeclarationAttributes, type Element, type ElementCompact, type ElementObject, type IgnoreOptions, type Js2XmlOptions, type Xml2JsOptions, type XmlAtom, type XmlAttrs, type XmlDesc, type XmlDescArray, type XmlObject, type XmlOption, allChildren, attr, attrBool, attrNum, attrs, childCount, childText, children, collectText, colorAttr, escapeXml, findChild, findDeep, hasChild, js2xml, json2xml, nativeTypeValue, parseAttributes, selfCloseElement, textOf, toElement, unescapeXml, xml, xml2js, xml2json };
|
package/dist/index.mjs
CHANGED
|
@@ -103,17 +103,28 @@ function formatElement(name, values, indent, depth) {
|
|
|
103
103
|
return `${indent ? indent.repeat(depth) : ""}<${name}${attrStr}/>`;
|
|
104
104
|
}
|
|
105
105
|
if (typeof values === "object") {
|
|
106
|
-
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
const
|
|
106
|
+
const obj = values;
|
|
107
|
+
if (obj._attr) {
|
|
108
|
+
const attr = obj._attr;
|
|
109
|
+
for (const key of Object.keys(attr)) attrParts.push(`${key}="${escapeXml(String(attr[key]))}"`);
|
|
110
|
+
}
|
|
111
|
+
if (obj._attributes) {
|
|
112
|
+
const attr = obj._attributes;
|
|
113
|
+
for (const key of Object.keys(attr)) attrParts.push(`${key}="${escapeXml(String(attr[key]))}"`);
|
|
114
|
+
}
|
|
115
|
+
if (obj._cdata) {
|
|
116
|
+
const escaped = String(obj._cdata).replace(/\]\]>/g, "]]]]><![CDATA[>");
|
|
110
117
|
textParts.push(`<![CDATA[${escaped}]]>`);
|
|
111
118
|
}
|
|
112
119
|
if (Array.isArray(values)) {
|
|
113
120
|
if (values.length === 0) emptyArray = true;
|
|
114
|
-
else for (const value of values) if (value && typeof value === "object" && "_attr" in value)
|
|
115
|
-
|
|
116
|
-
|
|
121
|
+
else for (const value of values) if (value && typeof value === "object" && "_attr" in value) {
|
|
122
|
+
const attr = value._attr;
|
|
123
|
+
for (const key of Object.keys(attr)) attrParts.push(`${key}="${escapeXml(String(attr[key]))}"`);
|
|
124
|
+
} else if (value && typeof value === "object" && "_attributes" in value) {
|
|
125
|
+
const attr = value._attributes;
|
|
126
|
+
for (const key of Object.keys(attr)) attrParts.push(`${key}="${escapeXml(String(attr[key]))}"`);
|
|
127
|
+
} else if (value && typeof value === "object") {
|
|
117
128
|
const childKeys = Object.keys(value);
|
|
118
129
|
elemParts.push(formatElement(childKeys[0], value[childKeys[0]], indent, depth + 1));
|
|
119
130
|
} else if (value != null) textParts.push(escapeXml(String(value)));
|
|
@@ -418,39 +429,39 @@ function writeElement(element, opts, depth) {
|
|
|
418
429
|
return parts.join("");
|
|
419
430
|
}
|
|
420
431
|
function writeElements(elements, opts, depth, firstLine) {
|
|
421
|
-
|
|
432
|
+
const parts = [];
|
|
422
433
|
for (let i = 0; i < elements.length; i++) {
|
|
423
434
|
const element = elements[i];
|
|
424
435
|
const isFirst = firstLine && i === 0;
|
|
425
436
|
switch (element.type) {
|
|
426
437
|
case "element":
|
|
427
|
-
|
|
428
|
-
|
|
438
|
+
parts.push(writeIndentation(opts.spaces, depth, isFirst));
|
|
439
|
+
parts.push(writeElement(element, opts, depth));
|
|
429
440
|
break;
|
|
430
441
|
case "text":
|
|
431
442
|
if (opts.ignoreText) continue;
|
|
432
|
-
if (opts.indentText)
|
|
433
|
-
|
|
443
|
+
if (opts.indentText) parts.push(writeIndentation(opts.spaces, depth, isFirst));
|
|
444
|
+
parts.push(writeText(element.text));
|
|
434
445
|
break;
|
|
435
446
|
case "cdata":
|
|
436
447
|
if (opts.ignoreCdata) continue;
|
|
437
|
-
if (opts.indentCdata)
|
|
438
|
-
|
|
448
|
+
if (opts.indentCdata) parts.push(writeIndentation(opts.spaces, depth, isFirst));
|
|
449
|
+
parts.push(writeCdata(element.cdata));
|
|
439
450
|
break;
|
|
440
451
|
case "comment":
|
|
441
452
|
if (opts.ignoreComment) continue;
|
|
442
|
-
|
|
443
|
-
|
|
453
|
+
parts.push(writeIndentation(opts.spaces, depth, isFirst));
|
|
454
|
+
parts.push(writeComment(element.comment));
|
|
444
455
|
break;
|
|
445
456
|
case "doctype":
|
|
446
457
|
if (opts.ignoreDoctype) continue;
|
|
447
|
-
|
|
448
|
-
|
|
458
|
+
parts.push(writeIndentation(opts.spaces, depth, isFirst));
|
|
459
|
+
parts.push(writeDoctype(element.doctype));
|
|
449
460
|
break;
|
|
450
461
|
default: break;
|
|
451
462
|
}
|
|
452
463
|
}
|
|
453
|
-
return
|
|
464
|
+
return parts.join("");
|
|
454
465
|
}
|
|
455
466
|
function writeText(text) {
|
|
456
467
|
if (text == null) return "";
|
package/dist/utils.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as childCount, c as collectText, d as findDeep, f as hasChild, i as attrNum, l as colorAttr, n as attr, o as childText, p as textOf, r as attrBool, s as children, t as allChildren, u as findChild } from "./utils-
|
|
1
|
+
import { a as childCount, c as collectText, d as findDeep, f as hasChild, i as attrNum, l as colorAttr, n as attr, o as childText, p as textOf, r as attrBool, s as children, t as allChildren, u as findChild } from "./utils-DJSm61Ws.mjs";
|
|
2
2
|
export { allChildren, attr, attrBool, attrNum, childCount, childText, children, collectText, colorAttr, findChild, findDeep, hasChild, textOf };
|