@ooxml-tools/xml 0.1.0 → 0.2.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/README.md +21 -1
- package/dist/npm/index.js +15 -1
- package/dist/npm/types.d.ts +7 -1
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -42,7 +42,8 @@ safeXml`<foo>hello</bar>`
|
|
|
42
42
|
Substitution of arrays "just works" so you can map values in the tagged template literals
|
|
43
43
|
|
|
44
44
|
```ts
|
|
45
|
-
const
|
|
45
|
+
const items = [1,2,3].map(n => safeXml`<name>item ${1}</name>`);
|
|
46
|
+
const outXml = safeXml`<test>${items}</test>`
|
|
46
47
|
assert.equal(outXml, `<test><name>item 1</name><name>item 2</name><name>item 3</name></test>`);
|
|
47
48
|
```
|
|
48
49
|
|
|
@@ -118,6 +119,25 @@ But `<name><![CDATA[one < two]]><name>` is ugly and hard to read, so instead
|
|
|
118
119
|
safeXml`<name>${cdata("one < two")}</name>`
|
|
119
120
|
```
|
|
120
121
|
|
|
122
|
+
### `format`
|
|
123
|
+
Format XML in a consistent way, useful for logging and snapshot testing
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
format(`
|
|
127
|
+
<test> one
|
|
128
|
+
</test>
|
|
129
|
+
`) /* =>
|
|
130
|
+
* <test>
|
|
131
|
+
* one
|
|
132
|
+
* </test>
|
|
133
|
+
*/
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## CI
|
|
137
|
+
|
|
138
|
+
[](https://codecov.io/gh/ooxml-tools/xml)
|
|
139
|
+
|
|
140
|
+
|
|
121
141
|
## License
|
|
122
142
|
|
|
123
143
|
MIT
|
package/dist/npm/index.js
CHANGED
|
@@ -98,4 +98,18 @@ function collapseFragments(root) {
|
|
|
98
98
|
return out;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
function format(input, { spaces = 2 } = {}) {
|
|
102
|
+
const elementJson = xml2js(input, {
|
|
103
|
+
compact: false,
|
|
104
|
+
captureSpacesBetweenElements: false,
|
|
105
|
+
});
|
|
106
|
+
return js2xml(elementJson, {
|
|
107
|
+
spaces: spaces,
|
|
108
|
+
compact: false,
|
|
109
|
+
indentText: true,
|
|
110
|
+
fullTagEmptyElement: true,
|
|
111
|
+
indentAttributes: true,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export { asXmlElement, cdata, collapseFragments, compact, createFragment, format, safeXml };
|
package/dist/npm/types.d.ts
CHANGED
|
@@ -16,4 +16,10 @@ declare function compact(xml: string): string;
|
|
|
16
16
|
declare function createFragment(elements: Element[]): Element;
|
|
17
17
|
declare function collapseFragments(root: string | Element): Element;
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
type FormatOptions = {
|
|
20
|
+
spaces?: number;
|
|
21
|
+
};
|
|
22
|
+
declare function format(input: string, { spaces }?: FormatOptions): string;
|
|
23
|
+
|
|
24
|
+
export { asXmlElement, cdata, collapseFragments, compact, createFragment, format, safeXml };
|
|
25
|
+
export type { FormatOptions };
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ooxml-tools/xml",
|
|
3
3
|
"description": "Some XML helpers to help with OOXML development",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/npm/index.js",
|
|
7
7
|
"types": "./dist/npm/types.d.ts",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"lint": "npx prettier . --check",
|
|
11
|
-
"test": "vitest",
|
|
11
|
+
"test": "vitest run --coverage",
|
|
12
|
+
"test:ci": "vitest run --coverage --reporter=junit --outputFile=test-report.junit.xml",
|
|
12
13
|
"lint:format": "npx prettier . --write",
|
|
13
14
|
"build": "rollup -c rollup.config.ts --configPlugin typescript"
|
|
14
15
|
},
|
|
@@ -22,11 +23,13 @@
|
|
|
22
23
|
"./README.md"
|
|
23
24
|
],
|
|
24
25
|
"devDependencies": {
|
|
26
|
+
"@codecov/rollup-plugin": "^1.9.1",
|
|
25
27
|
"@rollup/plugin-json": "^6.1.0",
|
|
26
28
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
27
29
|
"@rollup/plugin-virtual": "^3.0.2",
|
|
28
30
|
"@tsconfig/node22": "^22.0.0",
|
|
29
31
|
"@types/yargs": "^17.0.32",
|
|
32
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
30
33
|
"prettier": "^3.4.2",
|
|
31
34
|
"rollup": "^4.18.1",
|
|
32
35
|
"rollup-plugin-copy": "^3.5.0",
|
|
@@ -37,7 +40,7 @@
|
|
|
37
40
|
"tslib": "^2.6.3",
|
|
38
41
|
"tsx": "^4.17.0",
|
|
39
42
|
"typescript": "^5.5.4",
|
|
40
|
-
"vitest": "^2.
|
|
43
|
+
"vitest": "^3.2.4"
|
|
41
44
|
},
|
|
42
45
|
"engines": {
|
|
43
46
|
"node": ">=20.x"
|