@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 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,177,260 hz | 788,296 hz | **6.57x** |
107
- | Nested element | 931,473 hz | 283,093 hz | **3.29x** |
108
- | Nested with declaration | 871,188 hz | 252,580 hz | **3.45x** |
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,007,094 hz | 91,782 hz | **10.97x** |
115
- | Complex OOXML | 340,595 hz | 49,733 hz | **6.85x** |
116
- | With captureSpaces | 314,648 hz | 44,190 hz | **7.12x** |
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 | 712,314 hz | 182,865 hz | **3.90x** |
123
- | Complex OOXML | 333,739 hz | 125,132 hz | **2.67x** |
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,922,735 hz | 1,083,869 hz | **12.85x** |
130
- | Nested | 3,799,372 hz | 436,241 hz | **8.71x** |
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-DTU54qj_.mjs";
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, any> | Record<string, any>[], options?: boolean | 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
- if (values._attr) for (const key of Object.keys(values._attr)) attrParts.push(`${key}="${escapeXml(String(values._attr[key]))}"`);
107
- if (values._attributes) for (const key of Object.keys(values._attributes)) attrParts.push(`${key}="${escapeXml(String(values._attributes[key]))}"`);
108
- if (values._cdata) {
109
- const escaped = String(values._cdata).replace(/\]\]>/g, "]]]]><![CDATA[>");
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) for (const key of Object.keys(value._attr)) attrParts.push(`${key}="${escapeXml(String(value._attr[key]))}"`);
115
- else if (value && typeof value === "object" && "_attributes" in value) for (const key of Object.keys(value._attributes)) attrParts.push(`${key}="${escapeXml(String(value._attributes[key]))}"`);
116
- else if (value && typeof value === "object") {
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
- let result = "";
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
- result += writeIndentation(opts.spaces, depth, isFirst);
428
- result += writeElement(element, opts, depth);
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) result += writeIndentation(opts.spaces, depth, isFirst);
433
- result += writeText(element.text);
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) result += writeIndentation(opts.spaces, depth, isFirst);
438
- result += writeCdata(element.cdata);
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
- result += writeIndentation(opts.spaces, depth, isFirst);
443
- result += writeComment(element.comment);
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
- result += writeIndentation(opts.spaces, depth, isFirst);
448
- result += writeDoctype(element.doctype);
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 result;
464
+ return parts.join("");
454
465
  }
455
466
  function writeText(text) {
456
467
  if (text == null) return "";
@@ -23,7 +23,7 @@ interface Element {
23
23
  parent?: Element;
24
24
  }
25
25
  interface ElementCompact {
26
- [key: string]: any;
26
+ [key: string]: unknown;
27
27
  _declaration?: {
28
28
  _attributes?: DeclarationAttributes;
29
29
  };
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-DTU54qj_.mjs";
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@office-open/xml",
3
- "version": "0.6.8",
3
+ "version": "0.6.10",
4
4
  "description": "XML parsing and serialization for Office Open XML. Zero dependencies, drop-in replacement for xml + xml-js.",
5
5
  "keywords": [
6
6
  "office-open",