@thi.ng/hiccup
Advanced tools
Comparing version 5.0.9 to 5.1.0
/** | ||
* Takes a space separated string of existing CSS class names and merges | ||
* it with `val`, which is either another string of class names, an | ||
* object of booleans or an `IDeref` evaluating to either. Returns | ||
* updated class string. | ||
* Takes a space separated string of existing CSS class names and merges it with | ||
* `val`, which is either another string or string array of class names, an | ||
* object of booleans or an `IDeref` evaluating to either. Returns updated class | ||
* string. | ||
* | ||
@@ -10,6 +10,8 @@ * @remarks | ||
* | ||
* If `val` is an object, its keys are used as class names and their | ||
* values indicate if the class should be added or removed from the | ||
* existing set. | ||
* If `val` is an array, it will be joined as space-separated string and | ||
* concatenated to the existing one. | ||
* | ||
* If `val` is an object, its keys are used as class names and their values | ||
* indicate if the class should be added or removed from the existing set. | ||
* | ||
* @example | ||
@@ -20,4 +22,7 @@ * ```ts | ||
* | ||
* mergeClasses("foo", ["bar", "baz"]); | ||
* // "foo bar baz" | ||
* | ||
* mergeClasses("foo bar", "baz"); | ||
* // "baz" | ||
* // "foo bar baz" | ||
* ``` | ||
@@ -24,0 +29,0 @@ * |
import { deref } from "@thi.ng/api/deref"; | ||
import { isArray } from "@thi.ng/checks/is-array"; | ||
import { isString } from "@thi.ng/checks/is-string"; | ||
/** | ||
* Takes a space separated string of existing CSS class names and merges | ||
* it with `val`, which is either another string of class names, an | ||
* object of booleans or an `IDeref` evaluating to either. Returns | ||
* updated class string. | ||
* Takes a space separated string of existing CSS class names and merges it with | ||
* `val`, which is either another string or string array of class names, an | ||
* object of booleans or an `IDeref` evaluating to either. Returns updated class | ||
* string. | ||
* | ||
@@ -12,6 +13,8 @@ * @remarks | ||
* | ||
* If `val` is an object, its keys are used as class names and their | ||
* values indicate if the class should be added or removed from the | ||
* existing set. | ||
* If `val` is an array, it will be joined as space-separated string and | ||
* concatenated to the existing one. | ||
* | ||
* If `val` is an object, its keys are used as class names and their values | ||
* indicate if the class should be added or removed from the existing set. | ||
* | ||
* @example | ||
@@ -22,4 +25,7 @@ * ```ts | ||
* | ||
* mergeClasses("foo", ["bar", "baz"]); | ||
* // "foo bar baz" | ||
* | ||
* mergeClasses("foo bar", "baz"); | ||
* // "baz" | ||
* // "foo bar baz" | ||
* ``` | ||
@@ -34,5 +40,7 @@ * | ||
return existing; | ||
if (isArray(val)) | ||
val = val.join(" "); | ||
if (isString(val)) | ||
return existing + " " + val; | ||
const classes = new Set(existing.split(" ")); | ||
return existing ? existing + " " + val : val; | ||
const classes = new Set(existing ? existing.split(" ") : undefined); | ||
for (let id in val) { | ||
@@ -39,0 +47,0 @@ deref(val[id]) ? classes.add(id) : classes.delete(id); |
# Change Log | ||
- **Last updated**: 2023-12-03T12:13:31Z | ||
- **Last updated**: 2023-12-09T19:12:03Z | ||
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub) | ||
@@ -12,2 +12,14 @@ | ||
## [5.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup@5.1.0) (2023-12-09) | ||
#### 🚀 Features | ||
- allow `class` attrib as string array ([448edd0](https://github.com/thi-ng/umbrella/commit/448edd0)) | ||
- update mergeClasses() | ||
- update docs & tests | ||
#### 🩹 Bug fixes | ||
- fix mergeClasses(), add tests ([c734794](https://github.com/thi-ng/umbrella/commit/c734794)) | ||
### [5.0.6](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup@5.0.6) (2023-11-09) | ||
@@ -14,0 +26,0 @@ |
{ | ||
"name": "@thi.ng/hiccup", | ||
"version": "5.0.9", | ||
"version": "5.1.0", | ||
"description": "HTML/SVG/XML serialization of nested data structures, iterables & closures", | ||
@@ -36,11 +36,10 @@ "type": "module", | ||
"dependencies": { | ||
"@thi.ng/api": "^8.9.10", | ||
"@thi.ng/checks": "^3.4.10", | ||
"@thi.ng/errors": "^2.4.4", | ||
"@thi.ng/strings": "^3.7.1" | ||
"@thi.ng/api": "^8.9.11", | ||
"@thi.ng/checks": "^3.4.11", | ||
"@thi.ng/errors": "^2.4.5", | ||
"@thi.ng/strings": "^3.7.2" | ||
}, | ||
"devDependencies": { | ||
"@microsoft/api-extractor": "^7.38.3", | ||
"@thi.ng/atom": "^5.2.16", | ||
"@thi.ng/testament": "^0.4.3", | ||
"@thi.ng/atom": "^5.2.17", | ||
"rimraf": "^5.0.5", | ||
@@ -130,3 +129,3 @@ "tools": "^0.0.1", | ||
}, | ||
"gitHead": "04d1de79f256d7a53c6b5fd157b37f49bc88e11d\n" | ||
"gitHead": "25f2ac8ff795a432a930119661b364d4d93b59a0\n" | ||
} |
@@ -176,3 +176,3 @@ <!-- This file is generated - DO NOT EDIT! --> | ||
Package sizes (brotli'd, pre-treeshake): ESM: 2.14 KB | ||
Package sizes (brotli'd, pre-treeshake): ESM: 2.17 KB | ||
@@ -179,0 +179,0 @@ ## Dependencies |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
81949
6
745
259
3
5
51
+ Added@thi.ng/api@8.11.11(transitive)
+ Added@thi.ng/checks@3.6.13(transitive)
+ Added@thi.ng/errors@2.5.17(transitive)
+ Added@thi.ng/hex@2.3.55(transitive)
+ Added@thi.ng/memoize@4.0.1(transitive)
+ Added@thi.ng/strings@3.8.9(transitive)
- Removed@thi.ng/api@8.11.12(transitive)
- Removed@thi.ng/checks@3.6.14(transitive)
- Removed@thi.ng/errors@2.5.18(transitive)
- Removed@thi.ng/hex@2.3.56(transitive)
- Removed@thi.ng/memoize@4.0.2(transitive)
- Removed@thi.ng/strings@3.8.10(transitive)
Updated@thi.ng/api@^8.9.11
Updated@thi.ng/checks@^3.4.11
Updated@thi.ng/errors@^2.4.5
Updated@thi.ng/strings@^3.7.2