@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 +12 -12
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +6 -2
- 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 | 4,
|
|
107
|
-
| Nested element |
|
|
108
|
-
| Nested with declaration |
|
|
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 |
|
|
113
|
-
| ------------------ | ---------------: |
|
|
114
|
-
| Simple XML | 1,
|
|
115
|
-
| Complex OOXML |
|
|
116
|
-
| With captureSpaces |
|
|
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 |
|
|
123
|
-
| Complex OOXML |
|
|
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 |
|
|
130
|
-
| Nested | 4,
|
|
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
|
">": ">"
|
|
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
|
-
|
|
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.
|