@office-open/xml 0.6.1 → 0.6.2

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 | 4,023,269 hz | 742,728 hz | **5.42x** |
107
- | Nested element | 1,030,612 hz | 322,801 hz | **3.19x** |
108
- | Nested with declaration | 963,725 hz | 276,547 hz | **3.49x** |
106
+ | Simple element | 4,823,128 hz | 781,207 hz | **6.17x** |
107
+ | Nested element | 947,678 hz | 313,665 hz | **3.02x** |
108
+ | Nested with declaration | 899,301 hz | 266,551 hz | **3.37x** |
109
109
 
110
110
  ### Parsing (xml2js)
111
111
 
112
- | Scenario | @office-open/xml | xml-js | Speedup |
113
- | ------------------ | ---------------: | --------: | ---------: |
114
- | Simple XML | 1,147,347 hz | 95,579 hz | **12.00x** |
115
- | Complex OOXML | 401,553 hz | 52,327 hz | **7.67x** |
116
- | With captureSpaces | 387,082 hz | 52,317 hz | **7.40x** |
112
+ | Scenario | @office-open/xml | xml-js | Speedup |
113
+ | ------------------ | ---------------: | ---------: | ---------: |
114
+ | Simple XML | 1,083,833 hz | 100,053 hz | **10.83x** |
115
+ | Complex OOXML | 364,581 hz | 51,730 hz | **7.05x** |
116
+ | With captureSpaces | 375,042 hz | 51,373 hz | **7.30x** |
117
117
 
118
118
  ### Stringifying (js2xml)
119
119
 
120
120
  | Scenario | @office-open/xml | xml-js | Speedup |
121
121
  | -------------- | ---------------: | ---------: | --------: |
122
- | Simple element | 778,368 hz | 197,520 hz | **3.94x** |
123
- | Complex OOXML | 344,376 hz | 127,493 hz | **2.70x** |
122
+ | Simple element | 767,535 hz | 194,930 hz | **3.94x** |
123
+ | Complex OOXML | 367,936 hz | 130,716 hz | **2.81x** |
124
124
 
125
125
  ### Direct Conversion (toElement vs bridge)
126
126
 
127
127
  | Scenario | toElement() | xml() + xml2js() bridge | Speedup |
128
128
  | -------- | ------------: | ----------------------: | ---------: |
129
- | Simple | 14,953,390 hz | 803,917 hz | **18.61x** |
130
- | Nested | 4,530,626 hz | 466,126 hz | **9.72x** |
129
+ | Simple | 15,895,382 hz | 1,079,249 hz | **14.72x** |
130
+ | Nested | 4,077,988 hz | 465,743 hz | **8.76x** |
131
131
 
132
132
  ## Bundle Size
133
133
 
package/dist/index.d.mts CHANGED
@@ -28,7 +28,7 @@ declare function json2xml(json: Element, options?: Js2XmlOptions): string;
28
28
  declare function toElement(xmlObject: Record<string, any>): Element;
29
29
  //#endregion
30
30
  //#region src/escape.d.ts
31
- /** Escape text content for XML */
31
+ /** Escape text content for XML. Fast path returns original string when no special chars. */
32
32
  declare function escapeXml(str: string): string;
33
33
  /**
34
34
  * Escape attribute value matching xml-js's js2xml behavior.
package/dist/index.mjs CHANGED
@@ -8,9 +8,13 @@ const XML_CHAR_MAP = {
8
8
  ">": "&gt;"
9
9
  };
10
10
  const XML_CHAR_PATTERN = /([&"<>'])/g;
11
- /** Escape text content for XML */
11
+ /** Escape text content for XML. Fast path returns original string when no special chars. */
12
12
  function escapeXml(str) {
13
- return str.replace(XML_CHAR_PATTERN, (ch) => XML_CHAR_MAP[ch]);
13
+ for (let i = 0; i < str.length; i++) {
14
+ const c = str.charCodeAt(i);
15
+ if (c === 38 || c === 34 || c === 39 || c === 60 || c === 62) return str.replace(XML_CHAR_PATTERN, (ch) => XML_CHAR_MAP[ch]);
16
+ }
17
+ return str;
14
18
  }
15
19
  /**
16
20
  * Escape attribute value matching xml-js's js2xml behavior.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@office-open/xml",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
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",