@thi.ng/hiccup 5.1.30 → 5.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/CHANGELOG.md +7 -1
- package/README.md +1 -1
- package/package.json +2 -2
- package/serialize.d.ts +12 -0
- package/serialize.js +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-04-
|
|
3
|
+
- **Last updated**: 2024-04-25T19:44:55Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [5.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup@5.2.0) (2024-04-25)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add `SerializeOpts.xml`, update serializeAttrib ([8fdcab9](https://github.com/thi-ng/umbrella/commit/8fdcab9))
|
|
17
|
+
|
|
12
18
|
### [5.1.29](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup@5.1.29) (2024-04-20)
|
|
13
19
|
|
|
14
20
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/hiccup",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "HTML/SVG/XML serialization of nested data structures, iterables & closures",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -128,5 +128,5 @@
|
|
|
128
128
|
],
|
|
129
129
|
"year": 2016
|
|
130
130
|
},
|
|
131
|
-
"gitHead": "
|
|
131
|
+
"gitHead": "aed3421c21044c005fbcb7cc37965ccf85a870d2\n"
|
|
132
132
|
}
|
package/serialize.d.ts
CHANGED
|
@@ -36,6 +36,18 @@ export interface SerializeOpts {
|
|
|
36
36
|
* @defaultValue false
|
|
37
37
|
*/
|
|
38
38
|
keys: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* If true, some serialization behaviors will be adjusted to target XML
|
|
41
|
+
* output.
|
|
42
|
+
*
|
|
43
|
+
* @remarks
|
|
44
|
+
* Currently, the following aspects are supported:
|
|
45
|
+
*
|
|
46
|
+
* - boolean attributes are serialized as `name=""` rather than just `name`
|
|
47
|
+
*
|
|
48
|
+
* @defaultValue false
|
|
49
|
+
*/
|
|
50
|
+
xml: boolean;
|
|
39
51
|
}
|
|
40
52
|
/**
|
|
41
53
|
* Recursively normalizes and serializes given tree as HTML/SVG/XML string.
|
package/serialize.js
CHANGED
|
@@ -23,8 +23,9 @@ const serialize = (tree, opts, path = [0]) => {
|
|
|
23
23
|
const $opts = {
|
|
24
24
|
escape: false,
|
|
25
25
|
escapeFn: escapeEntitiesNum,
|
|
26
|
-
span: false,
|
|
27
26
|
keys: false,
|
|
27
|
+
span: false,
|
|
28
|
+
xml: false,
|
|
28
29
|
...opts
|
|
29
30
|
};
|
|
30
31
|
if (opts?.keys == null && $opts.span)
|
|
@@ -61,7 +62,7 @@ const serializeAttribs = (attribs, opts) => {
|
|
|
61
62
|
return res;
|
|
62
63
|
};
|
|
63
64
|
const serializeAttrib = (attribs, a, v, opts) => {
|
|
64
|
-
return v == null ? null : isFunction(v) && (/^on\w+/.test(a) || (v = v(attribs)) == null) ? null : v === true ? " " + a : v === false ? null : a === "data" ? serializeDataAttribs(v, opts) : attribPair(a, v, opts);
|
|
65
|
+
return v == null ? null : isFunction(v) && (/^on\w+/.test(a) || (v = v(attribs)) == null) ? null : v === true ? " " + a + (opts.xml ? `=""` : "") : v === false ? null : a === "data" ? serializeDataAttribs(v, opts) : attribPair(a, v, opts);
|
|
65
66
|
};
|
|
66
67
|
const attribPair = (a, v, opts) => {
|
|
67
68
|
v = a === "style" && isPlainObject(v) ? css(v) : a === "prefix" && isPlainObject(v) ? formatPrefixes(v) : isArray(v) ? v.join(ATTRIB_JOIN_DELIMS[a] || " ") : v.toString();
|