@lowlighter/xml 5.4.7 → 5.4.9

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
@@ -8,22 +8,23 @@
8
8
 
9
9
  ## ✨ Features
10
10
 
11
- - Based on [quick-xml](https://github.com/tafia/quick-xml) rust package (compiled to WASM)
12
- - Support `XML.parse` and `XML.stringify`
13
- - Support `<!-- -->` comments
14
- - Support XML entities (`&amp;`, `&#38;`, `&#x26;`, ...)
15
- - Support mixed content (text and nodes)
16
- - Large output transformation options
17
- - Auto-flattening of nodes with a single child, text or attributes
18
- - Auto-revival of `boolean`, `number`, etc.
19
- - Auto-group same-named nodes into arrays
20
- - Formatting options (indentation, break lines, etc.)
21
- - Custom `reviver` and `replacer` functions
22
- - Metadata stored into non-enumerable properties for advanced usage
11
+ - Based on the [quick-xml](https://github.com/tafia/quick-xml) Rust package (compiled to WASM).
12
+ - Support for `XML.parse` and `XML.stringify` in the style of the `JSON` global.
13
+ - Support for `<!-- -->` comments.
14
+ - Support for XML entities (`&amp;`, `&#38;`, `&#x26;`, ).
15
+ - Support for mixed content (both text and nodes).
16
+ - Support for large output transformation options:
17
+ - Auto-flatten nodes with a single child, text or attributes
18
+ - Auto-revive `boolean`s, `number`s, etc.
19
+ - Auto-group same-named nodes into arrays.
20
+ - Format (indentation, break lines, etc.)
21
+ - Support for custom `reviver` and `replacer` functions
22
+ - Support for metadata stored into non-enumerable properties (advanced usage).
23
23
 
24
24
  ## 🕊️ Migrating from `4.x.x` to `5.x.x`
25
25
 
26
- Starting from version `5.0.0`, this library use a WASM-compiled binding of the [quick-xml](https://github.com/tafia/quick-xml) rust package. It provides better performances while allowing to support more features.
26
+ Prior to version version `5.0.0`, this library was fully written in TypeScript.
27
+ It now uses a WASM-compiled binding of the [quick-xml](https://github.com/tafia/quick-xml) Rust package, which provides better performance while allowing us to support more features.
27
28
 
28
29
  ### Internal API changes
29
30
 
@@ -40,7 +41,7 @@ The `$XML` internal symbol has been replaced by a set of non-enumerable properti
40
41
  </root>
41
42
  ```
42
43
 
43
- ```diff
44
+ ```diff js
44
45
  <ref *1> {
45
46
  - [$XML]: { cdata: [ "root", "node" ] },
46
47
  + "~parent": null,
@@ -70,7 +71,7 @@ Processing instructions (like XML stylesheets) are now parsed the same way as re
70
71
  <root/>
71
72
  ```
72
73
 
73
- ```diff
74
+ ```diff js
74
75
  {
75
76
  - xml: {
76
77
  - "@version": "1.0",
@@ -90,7 +91,8 @@ Processing instructions (like XML stylesheets) are now parsed the same way as re
90
91
 
91
92
  ### Mixed content support
92
93
 
93
- This breaks any existing code that was expecting mixed content to always be a string. Now mixed content nodes will be parsed as usual, and the `#text` property will contain the "inner text" of the node.
94
+ This breaks any existing code that was expecting mixed content to always be a string.
95
+ Now, mixed content nodes will be parsed as usual, and the `#text` property will contain the "inner text" of the node.
94
96
 
95
97
  Note that `#text` is actually a getter that recursively gets the `#text` of children nodes (ignoring comment nodes), so it'll also handle nested mixed content correctly.
96
98
 
@@ -98,7 +100,7 @@ Note that `#text` is actually a getter that recursively gets the `#text` of chil
98
100
  <root>some <b>bold</b> text</root>
99
101
  ```
100
102
 
101
- ```diff
103
+ ```diff js
102
104
  {
103
105
  - root: "some <b>bold</b> text",
104
106
  + root: {
@@ -110,15 +112,17 @@ Note that `#text` is actually a getter that recursively gets the `#text` of chil
110
112
 
111
113
  ### Comments
112
114
 
113
- Comments have been moved into `"#comments"` property. Note that this property is now always an array, even if there is only one comment.
115
+ Comments have been moved into `"#comments"` property.
116
+ Note that this property is now always an array, even if there is only one comment.
114
117
 
115
- Additionally, you can find comments into the `~children` property by searching for nodes with `"~name": "~comment"`. If you call the `#text` getter on a parent node containing comments, it will return the inner text without comments.
118
+ Additionally, you can find comments into the `~children` property by searching for nodes with `"~name": "~comment"`.
119
+ If you call the `#text` getter on a parent node containing comments, it will return the inner text without comments.
116
120
 
117
121
  ```xml
118
122
  <root><!--some comment--></root>
119
123
  ```
120
124
 
121
- ```diff
125
+ ```diff js
122
126
  {
123
127
  root: {
124
128
  - "#comment": "some comment",
@@ -131,16 +135,17 @@ Additionally, you can find comments into the `~children` property by searching f
131
135
 
132
136
  #### Options
133
137
 
134
- Parse options are categorized into 4 groups:
138
+ Parsing options are categorized into 4 groups:
135
139
 
136
140
  - `clean`, which can remove `attributes`, `comments`, xml `doctype` and `instructions` from the output
137
141
  - `flatten`, which can flatten nodes with only a `text` node, `empty` ones or transform `attributes` only nodes into objects without the `@` prefix
138
142
  - `revive`, which can `trim` content (unless `xml:space="preserve"`), unescape xml `entities`, revive `booleans` and `numbers`
139
143
  - You can also provide a `custom` reviver function (applied after other revivals) that will be called on each attribute and node
140
144
  - _Note that signature of the reviver function has changed_
141
- - `mode`, which can be either `xml` or `html`. Choosing the latter will be more permissive than the former.
145
+ - `mode`, which can be either `xml` or `html`.
146
+ Choosing the latter will be more permissive than the former.
142
147
 
143
- ```diff
148
+ ```diff js
144
149
  const options = {
145
150
  - reviveBooleans: true,
146
151
  - reviveNumbers: true,
@@ -165,13 +170,13 @@ import { parse } from "./parse.ts"
165
170
  parse(await Deno.readTextFile("example.xml"))
166
171
  ```
167
172
 
168
- Async parsing is not supported yet, but might be added in the future.
173
+ Async parsing is not supported yet, but might be added in the future (see [#49](https://github.com/lowlighter/libs/issues/49)).
169
174
 
170
175
  ### Stringifying
171
176
 
172
177
  #### Options
173
178
 
174
- Stringify options are now categorized into 2 groups:
179
+ Stringifying options are now categorized into 2 groups:
175
180
 
176
181
  - `format`, which can configure the `indent` string and automatically `breakline` when a text node is too long
177
182
  - _Since you pass a string rather than a number for indent, it means that you can also use tabs instead of space too_
@@ -179,7 +184,7 @@ Stringify options are now categorized into 2 groups:
179
184
  - You can also provide a `custom` replacer function that will be called on each attribute and node
180
185
  - _Note that signature of the replacer function has changed_
181
186
 
182
- ```diff
187
+ ```diff js
183
188
  const options = {
184
189
  - indentSize: 2,
185
190
  + format: { indent: " " },
@@ -196,9 +201,10 @@ Please refer to the [documentation](https://jsr.io/@libs/xml/doc) for more infor
196
201
 
197
202
  ### Stringifying content
198
203
 
199
- Please refer to the above section about API changes. If you were handling XML document properties, using the `$XML` symbol or `#comment` property, or dealing with mixed nodes content, you'll most likely need to update your code.
204
+ Please refer to the above section about API changes.
205
+ If you were handling XML document properties, using the `$XML` symbol or `#comment` property, or dealing with mixed nodes content, you'll most likely need to update your code.
200
206
 
201
- This library now provides `comment()` and `cdata()` helpers to respectively create comment and CDATA nodes.
207
+ Additionally, the library now provides `comment()` and `cdata()` helpers to respectively create comment and CDATA nodes:
202
208
 
203
209
  ```ts
204
210
  import { cdata, comment, stringify } from "./stringify.ts"
@@ -234,16 +240,31 @@ stringify({
234
240
  </root>
235
241
  ```
236
242
 
237
- Note that while you can theorethically use internal API properties, we strongly advise against it currently. Supporting `~children` might be added in the future ([#57](https://github.com/lowlighter/libs/issues/57)) for mixed content, but its behavior is not well defined yet.
243
+ Note that while you can _theoretically_ use internal API properties, currently, we strongly advise against doing so.
244
+ Supporting `~children` might be added in the future ([#57](https://github.com/lowlighter/libs/issues/57)) for mixed content, but its behavior is not yet well defined.
238
245
  Setting `~name` manually might lead to unexpected behaviors, especially if it differs from the parent key.
239
246
 
247
+ > [!TIP]
248
+ > For more type-safety, write `satisfies Partial<xml_document>` after whatever you pass into `stringify`, like so:
249
+ >
250
+ > <!-- TODO(lishaduck): Add ts highlighting once denoland/deno#24164 is resolved -->
251
+ >
252
+ > ```
253
+ > import { stringify, type xml_document } from "./stringify.ts"
254
+ >
255
+ > const ast = {
256
+ > "@version": "1.0",
257
+ > "@encoding": "UTF-8",
258
+ > "root": {},
259
+ > } satisfies Partial<xml_document>
260
+ > const result = stringify(ast)
261
+ > ```
262
+ >
263
+ > We expose lax typing, but `Partial<xml_document>` uses the stricter typing we use internally.
264
+
240
265
  ## 📜 License and credits
241
266
 
242
- ```
243
- Copyright (c) Lecoq Simon <@lowlighter>. (MIT License)
267
+ ```plaintext
268
+ Copyright (c) Simon Lecoq <@lowlighter>. (MIT License)
244
269
  https://github.com/lowlighter/libs/blob/main/LICENSE
245
270
  ```
246
-
247
- This library used to be published at [deno.land/x/xml](https://deno.land/x/xml) and [jsr.io/@lowlighter/xml](https://jsr.io/@lowlighter/xml). It was moved into [jsr.io/@libs/xml](https://jsr.io/@libs/xml) starting version `5.0.0`.
248
-
249
- Version prior to `5.0.0` used to be fully written in TypeScript but it was rewritten in Rust to improve performances and support more features.
package/_types.ts CHANGED
@@ -25,11 +25,11 @@ export type xml_node = {
25
25
  /** XML document. */
26
26
  export type xml_document = xml_node & {
27
27
  /** XML version. */
28
- ["@version"]?: string
28
+ ["@version"]?: `1.${number}`
29
29
  /** XML character encoding. */
30
30
  ["@encoding"]?: string
31
31
  /** XML standalone. */
32
- ["@standalone"]?: string
32
+ ["@standalone"]?: "yes" | "no"
33
33
  /** XML doctype. */
34
34
  ["#doctype"]?: xml_node
35
35
  /** XML instructions. */
package/deno.jsonc CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "icon": "📃",
3
3
  "name": "@libs/xml",
4
- "version": "5.4.7",
4
+ "version": "5.4.9",
5
5
  "description": "XML parser/stringifier with no dependencies.",
6
6
  "keywords": [
7
7
  "xml",
@@ -33,9 +33,9 @@
33
33
  "./stringify": "./stringify.ts"
34
34
  },
35
35
  "imports": {
36
- "@std/fs/expand-glob": "jsr:@std/fs@0.229.1/expand-glob",
37
- "@std/fs/exists": "jsr:@std/fs@0.229.1/exists",
38
- "@std/path/from-file-url": "jsr:@std/path@0.225.1/from-file-url",
36
+ "@std/fs/expand-glob": "jsr:@std/fs@0.229.3/expand-glob",
37
+ "@std/fs/exists": "jsr:@std/fs@0.229.3/exists",
38
+ "@std/path/from-file-url": "jsr:@std/path@0.225.2/from-file-url",
39
39
  "@libs/typing": "jsr:@libs/typing@2",
40
40
  "@libs/testing": "jsr:@libs/testing@1"
41
41
  },
@@ -89,6 +89,7 @@
89
89
  "**/package-lock.json",
90
90
  "**/wasm_*",
91
91
  "**/*.mjs"
92
- ]
92
+ ],
93
+ "proseWrap": "preserve"
93
94
  }
94
95
  }
package/deno.lock CHANGED
@@ -2,54 +2,89 @@
2
2
  "version": "3",
3
3
  "packages": {
4
4
  "specifiers": {
5
- "jsr:@libs/testing@1": "jsr:@libs/testing@1.0.7",
6
- "jsr:@libs/typing@2": "jsr:@libs/typing@2.1.0",
7
- "jsr:@std/assert@^0.224.0": "jsr:@std/assert@0.224.0",
8
- "jsr:@std/expect@0.224.0": "jsr:@std/expect@0.224.0",
9
- "jsr:@std/fmt@^0.224.0": "jsr:@std/fmt@0.224.0",
10
- "jsr:@std/fs@0.229.1": "jsr:@std/fs@0.229.1",
11
- "jsr:@std/internal@^0.224.0": "jsr:@std/internal@0.224.0",
5
+ "jsr:@libs/logger@1": "jsr:@libs/logger@1.1.2",
6
+ "jsr:@libs/run@1": "jsr:@libs/run@1.0.1",
7
+ "jsr:@libs/testing@1": "jsr:@libs/testing@1.1.0",
8
+ "jsr:@libs/typing@2": "jsr:@libs/typing@2.3.0",
9
+ "jsr:@std/assert@^0.225.3": "jsr:@std/assert@0.225.3",
10
+ "jsr:@std/async@0.224.1": "jsr:@std/async@0.224.1",
11
+ "jsr:@std/bytes@^1.0.0-rc.3": "jsr:@std/bytes@1.0.1",
12
+ "jsr:@std/bytes@^1.0.1-rc.3": "jsr:@std/bytes@1.0.1",
13
+ "jsr:@std/expect@0.224.3": "jsr:@std/expect@0.224.3",
14
+ "jsr:@std/fs@0.229.3": "jsr:@std/fs@0.229.3",
15
+ "jsr:@std/internal@^1.0.0": "jsr:@std/internal@1.0.1",
16
+ "jsr:@std/io@^0.224.0": "jsr:@std/io@0.224.3",
12
17
  "jsr:@std/path@0.225.1": "jsr:@std/path@0.225.1",
13
- "npm:@types/node": "npm:@types/node@18.16.19"
18
+ "jsr:@std/path@0.225.2": "jsr:@std/path@0.225.2",
19
+ "jsr:@std/streams@0.224.2": "jsr:@std/streams@0.224.2"
14
20
  },
15
21
  "jsr": {
16
- "@libs/testing@1.0.7": {
17
- "integrity": "b1a7caa9d2e00569f90b9753eb768ec6b16ff5c859f104b73a6ef4611968892e",
22
+ "@libs/logger@1.1.2": {
23
+ "integrity": "7d718f54c9a5d1c00f570051bee0217e3b282e8c2131144ec55c794a8ebd5d4f"
24
+ },
25
+ "@libs/run@1.0.1": {
26
+ "integrity": "b22b34ae7629179568c44efecb60f69310af013f65c96e447a5ee8743ff53f42",
27
+ "dependencies": [
28
+ "jsr:@libs/logger@1",
29
+ "jsr:@std/async@0.224.1",
30
+ "jsr:@std/streams@0.224.2"
31
+ ]
32
+ },
33
+ "@libs/testing@1.1.0": {
34
+ "integrity": "961fed690ee11a6f0f2cf8ed759b9b3a5c40ca24d319ba6c18cbbdaf73f1b29b",
35
+ "dependencies": [
36
+ "jsr:@libs/run@1",
37
+ "jsr:@std/expect@0.224.3",
38
+ "jsr:@std/path@0.225.1"
39
+ ]
40
+ },
41
+ "@libs/typing@2.3.0": {
42
+ "integrity": "8a03098b2d63763bc3b45b58f6e847d9c085405db83330c588aecb6b670587d0"
43
+ },
44
+ "@std/assert@0.225.3": {
45
+ "integrity": "b3c2847aecf6955b50644cdb9cf072004ea3d1998dd7579fc0acb99dbb23bd4f",
18
46
  "dependencies": [
19
- "jsr:@std/expect@0.224.0"
47
+ "jsr:@std/internal@^1.0.0"
20
48
  ]
21
49
  },
22
- "@libs/typing@2.1.0": {
23
- "integrity": "3c3b93e1da1e4bb45a22dde168fdfd1cc765edbdb371b46bf4ca7873ee79e15d"
50
+ "@std/async@0.224.1": {
51
+ "integrity": "2fda2c8151cc5811a6ca37fe825f1f71c95e02a374abb6ef868e0e19eca814a5"
24
52
  },
25
- "@std/assert@0.224.0": {
26
- "integrity": "8643233ec7aec38a940a8264a6e3eed9bfa44e7a71cc6b3c8874213ff401967f"
53
+ "@std/bytes@1.0.1": {
54
+ "integrity": "e57c9b243932b95a4c3672f8a038cdadea7492efeeb6b8a774844fee70426815"
27
55
  },
28
- "@std/expect@0.224.0": {
29
- "integrity": "54bc071f7edcbd7bb4531f913e466e5ec3642f401dc3771fe5975f0693f25969",
56
+ "@std/expect@0.224.3": {
57
+ "integrity": "eacd71aaa426472bf04ddde7e0765b0b360d3ffa33ad2ca05a96fd7052caea41",
30
58
  "dependencies": [
31
- "jsr:@std/assert@^0.224.0",
32
- "jsr:@std/fmt@^0.224.0",
33
- "jsr:@std/internal@^0.224.0"
59
+ "jsr:@std/assert@^0.225.3",
60
+ "jsr:@std/internal@^1.0.0"
34
61
  ]
35
62
  },
36
- "@std/fmt@0.224.0": {
37
- "integrity": "e20e9a2312a8b5393272c26191c0a68eda8d2c4b08b046bad1673148f1d69851"
63
+ "@std/fs@0.229.3": {
64
+ "integrity": "783bca21f24da92e04c3893c9e79653227ab016c48e96b3078377ebd5222e6eb"
38
65
  },
39
- "@std/fs@0.229.1": {
40
- "integrity": "38d3fb31f0ca0a8c1118e039939188f32e291a3f7f17dc0868fec22024bdfadd"
66
+ "@std/internal@1.0.1": {
67
+ "integrity": "6f8c7544d06a11dd256c8d6ba54b11ed870aac6c5aeafff499892662c57673e6"
41
68
  },
42
- "@std/internal@0.224.0": {
43
- "integrity": "afc50644f9cdf4495eeb80523a8f6d27226b4b36c45c7c195dfccad4b8509291"
69
+ "@std/io@0.224.3": {
70
+ "integrity": "b402edeb99c6b3778d9ae3e9927bc9085b170b41e5a09bbb7064ab2ee394ae2f",
71
+ "dependencies": [
72
+ "jsr:@std/bytes@^1.0.1-rc.3"
73
+ ]
44
74
  },
45
75
  "@std/path@0.225.1": {
46
76
  "integrity": "8c3220635a73730eb51fe43de9e10b79e2724a5bb8638b9355d35ae012fd9429"
47
- }
48
- },
49
- "npm": {
50
- "@types/node@18.16.19": {
51
- "integrity": "sha512-IXl7o+R9iti9eBW4Wg2hx1xQDig183jj7YLn8F7udNceyfkbn1ZxmzZXuak20gR40D7pIkIY1kYGx5VIGbaHKA==",
52
- "dependencies": {}
77
+ },
78
+ "@std/path@0.225.2": {
79
+ "integrity": "0f2db41d36b50ef048dcb0399aac720a5348638dd3cb5bf80685bf2a745aa506"
80
+ },
81
+ "@std/streams@0.224.2": {
82
+ "integrity": "5d437af1423e4f616111b986ea783c15e0bc998b53e23e93b623de7ef0b14c2b",
83
+ "dependencies": [
84
+ "jsr:@std/assert@^0.225.3",
85
+ "jsr:@std/bytes@^1.0.0-rc.3",
86
+ "jsr:@std/io@^0.224.0"
87
+ ]
53
88
  }
54
89
  }
55
90
  },
@@ -58,8 +93,8 @@
58
93
  "dependencies": [
59
94
  "jsr:@libs/testing@1",
60
95
  "jsr:@libs/typing@2",
61
- "jsr:@std/fs@0.229.1",
62
- "jsr:@std/path@0.225.1"
96
+ "jsr:@std/fs@0.229.3",
97
+ "jsr:@std/path@0.225.2"
63
98
  ]
64
99
  }
65
100
  }