@thi.ng/hiccup 5.0.9 → 5.1.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 +13 -1
- package/README.md +1 -1
- package/attribs.d.ts +13 -8
- package/attribs.js +18 -10
- package/package.json +7 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2023-12-
|
|
3
|
+
- **Last updated**: 2023-12-09T19:12:03Z
|
|
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,18 @@ 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.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup@5.1.0) (2023-12-09)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- allow `class` attrib as string array ([448edd0](https://github.com/thi-ng/umbrella/commit/448edd0))
|
|
17
|
+
- update mergeClasses()
|
|
18
|
+
- update docs & tests
|
|
19
|
+
|
|
20
|
+
#### 🩹 Bug fixes
|
|
21
|
+
|
|
22
|
+
- fix mergeClasses(), add tests ([c734794](https://github.com/thi-ng/umbrella/commit/c734794))
|
|
23
|
+
|
|
12
24
|
### [5.0.6](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup@5.0.6) (2023-11-09)
|
|
13
25
|
|
|
14
26
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
package/attribs.d.ts
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Takes a space separated string of existing CSS class names and merges
|
|
3
|
-
*
|
|
4
|
-
* object of booleans or an `IDeref` evaluating to either. Returns
|
|
5
|
-
*
|
|
2
|
+
* Takes a space separated string of existing CSS class names and merges it with
|
|
3
|
+
* `val`, which is either another string or string array of class names, an
|
|
4
|
+
* object of booleans or an `IDeref` evaluating to either. Returns updated class
|
|
5
|
+
* string.
|
|
6
6
|
*
|
|
7
7
|
* @remarks
|
|
8
8
|
* If `val` evaluates to a string, it will be appended to `existing`.
|
|
9
9
|
*
|
|
10
|
-
* If `val` is an
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* If `val` is an array, it will be joined as space-separated string and
|
|
11
|
+
* concatenated to the existing one.
|
|
12
|
+
*
|
|
13
|
+
* If `val` is an object, its keys are used as class names and their values
|
|
14
|
+
* indicate if the class should be added or removed from the existing set.
|
|
13
15
|
*
|
|
14
16
|
* @example
|
|
15
17
|
* ```ts
|
|
16
18
|
* mergeClasses("foo bar", { foo: false, baz: true })
|
|
17
19
|
* // "bar baz"
|
|
18
20
|
*
|
|
21
|
+
* mergeClasses("foo", ["bar", "baz"]);
|
|
22
|
+
* // "foo bar baz"
|
|
23
|
+
*
|
|
19
24
|
* mergeClasses("foo bar", "baz");
|
|
20
|
-
* // "baz"
|
|
25
|
+
* // "foo bar baz"
|
|
21
26
|
* ```
|
|
22
27
|
*
|
|
23
28
|
* @param existing -
|
package/attribs.js
CHANGED
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
import { deref } from "@thi.ng/api/deref";
|
|
2
|
+
import { isArray } from "@thi.ng/checks/is-array";
|
|
2
3
|
import { isString } from "@thi.ng/checks/is-string";
|
|
3
4
|
/**
|
|
4
|
-
* Takes a space separated string of existing CSS class names and merges
|
|
5
|
-
*
|
|
6
|
-
* object of booleans or an `IDeref` evaluating to either. Returns
|
|
7
|
-
*
|
|
5
|
+
* Takes a space separated string of existing CSS class names and merges it with
|
|
6
|
+
* `val`, which is either another string or string array of class names, an
|
|
7
|
+
* object of booleans or an `IDeref` evaluating to either. Returns updated class
|
|
8
|
+
* string.
|
|
8
9
|
*
|
|
9
10
|
* @remarks
|
|
10
11
|
* If `val` evaluates to a string, it will be appended to `existing`.
|
|
11
12
|
*
|
|
12
|
-
* If `val` is an
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* If `val` is an array, it will be joined as space-separated string and
|
|
14
|
+
* concatenated to the existing one.
|
|
15
|
+
*
|
|
16
|
+
* If `val` is an object, its keys are used as class names and their values
|
|
17
|
+
* indicate if the class should be added or removed from the existing set.
|
|
15
18
|
*
|
|
16
19
|
* @example
|
|
17
20
|
* ```ts
|
|
18
21
|
* mergeClasses("foo bar", { foo: false, baz: true })
|
|
19
22
|
* // "bar baz"
|
|
20
23
|
*
|
|
24
|
+
* mergeClasses("foo", ["bar", "baz"]);
|
|
25
|
+
* // "foo bar baz"
|
|
26
|
+
*
|
|
21
27
|
* mergeClasses("foo bar", "baz");
|
|
22
|
-
* // "baz"
|
|
28
|
+
* // "foo bar baz"
|
|
23
29
|
* ```
|
|
24
30
|
*
|
|
25
31
|
* @param existing -
|
|
@@ -29,9 +35,11 @@ export const mergeClasses = (existing, val) => {
|
|
|
29
35
|
val = deref(val);
|
|
30
36
|
if (val == null)
|
|
31
37
|
return existing;
|
|
38
|
+
if (isArray(val))
|
|
39
|
+
val = val.join(" ");
|
|
32
40
|
if (isString(val))
|
|
33
|
-
return existing + " " + val;
|
|
34
|
-
const classes = new Set(existing.split(" "));
|
|
41
|
+
return existing ? existing + " " + val : val;
|
|
42
|
+
const classes = new Set(existing ? existing.split(" ") : undefined);
|
|
35
43
|
for (let id in val) {
|
|
36
44
|
deref(val[id]) ? classes.add(id) : classes.delete(id);
|
|
37
45
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/hiccup",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "HTML/SVG/XML serialization of nested data structures, iterables & closures",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -33,15 +33,14 @@
|
|
|
33
33
|
"test": "bun test"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@thi.ng/api": "^8.9.
|
|
37
|
-
"@thi.ng/checks": "^3.4.
|
|
38
|
-
"@thi.ng/errors": "^2.4.
|
|
39
|
-
"@thi.ng/strings": "^3.7.
|
|
36
|
+
"@thi.ng/api": "^8.9.11",
|
|
37
|
+
"@thi.ng/checks": "^3.4.11",
|
|
38
|
+
"@thi.ng/errors": "^2.4.5",
|
|
39
|
+
"@thi.ng/strings": "^3.7.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@microsoft/api-extractor": "^7.38.3",
|
|
43
|
-
"@thi.ng/atom": "^5.2.
|
|
44
|
-
"@thi.ng/testament": "^0.4.3",
|
|
43
|
+
"@thi.ng/atom": "^5.2.17",
|
|
45
44
|
"rimraf": "^5.0.5",
|
|
46
45
|
"tools": "^0.0.1",
|
|
47
46
|
"typedoc": "^0.25.4",
|
|
@@ -126,5 +125,5 @@
|
|
|
126
125
|
],
|
|
127
126
|
"year": 2016
|
|
128
127
|
},
|
|
129
|
-
"gitHead": "
|
|
128
|
+
"gitHead": "25f2ac8ff795a432a930119661b364d4d93b59a0\n"
|
|
130
129
|
}
|