@thi.ng/strings 3.3.25 → 3.4.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 +11 -1
- package/README.md +1 -1
- package/entities.d.ts +6 -0
- package/entities.js +70 -1
- package/package.json +7 -7
- package/slugify.d.ts +3 -3
- package/slugify.js +9 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2023-02-
|
|
3
|
+
- **Last updated**: 2023-02-27T21:43:54Z
|
|
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,16 @@ 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
|
+
## [3.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/strings@3.4.0) (2023-02-27)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add more HTML entities ([d617132](https://github.com/thi-ng/umbrella/commit/d617132))
|
|
17
|
+
|
|
18
|
+
#### 🩹 Bug fixes
|
|
19
|
+
|
|
20
|
+
- add emoji ranges for slugify/slugifyGH() ([f5cb210](https://github.com/thi-ng/umbrella/commit/f5cb210))
|
|
21
|
+
|
|
12
22
|
### [3.3.3](https://github.com/thi-ng/umbrella/tree/@thi.ng/strings@3.3.3) (2022-04-07)
|
|
13
23
|
|
|
14
24
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
package/entities.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @remarks
|
|
3
|
+
* References:
|
|
4
|
+
* - https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
|
|
5
|
+
* - https://www.w3.org/TR/xml-entity-names/byalpha.html
|
|
6
|
+
*/
|
|
1
7
|
export declare const ENTITIES: Record<string, string>;
|
|
2
8
|
export declare const RE_ENTITIES: RegExp;
|
|
3
9
|
export declare const ENTITIES_REV: Record<string, string>;
|
package/entities.js
CHANGED
|
@@ -1,22 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @remarks
|
|
3
|
+
* References:
|
|
4
|
+
* - https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
|
|
5
|
+
* - https://www.w3.org/TR/xml-entity-names/byalpha.html
|
|
6
|
+
*/
|
|
1
7
|
export const ENTITIES = {
|
|
2
8
|
"&": "&",
|
|
3
9
|
"<": "<",
|
|
4
10
|
">": ">",
|
|
11
|
+
"≤": "≤",
|
|
12
|
+
"≥": "≥",
|
|
5
13
|
'"': """,
|
|
6
14
|
"'": "'",
|
|
7
15
|
"—": "—",
|
|
8
16
|
"–": "–",
|
|
9
17
|
"…": "…",
|
|
18
|
+
"⋮": "⋮",
|
|
19
|
+
"⋯": "⋯",
|
|
10
20
|
"¢": "¢",
|
|
11
21
|
"€": "€",
|
|
12
22
|
"£": "£",
|
|
13
23
|
"§": "§",
|
|
24
|
+
"¶": "¶",
|
|
14
25
|
"©": "©",
|
|
15
26
|
"®": "®",
|
|
16
27
|
"™": "™",
|
|
28
|
+
"◂": "◂",
|
|
29
|
+
"▸": "▸",
|
|
30
|
+
"▴": "▴",
|
|
31
|
+
"▾": "▾",
|
|
32
|
+
"←": "←",
|
|
33
|
+
"→": "→",
|
|
34
|
+
"↑": "↑",
|
|
35
|
+
"↓": "↓",
|
|
36
|
+
"↵": "↵",
|
|
37
|
+
"↩": "↩",
|
|
38
|
+
"⇐": "⇐",
|
|
39
|
+
"⇒": "⇒",
|
|
40
|
+
"↺": "↺",
|
|
41
|
+
"↻": "↻",
|
|
42
|
+
"¹": "¹",
|
|
43
|
+
"²": "²",
|
|
44
|
+
"³": "³",
|
|
45
|
+
α: "α",
|
|
46
|
+
β: "β",
|
|
47
|
+
γ: "γ",
|
|
48
|
+
δ: "δ",
|
|
49
|
+
ε: "ε",
|
|
50
|
+
θ: "θ",
|
|
51
|
+
λ: "λ",
|
|
52
|
+
μ: "μ",
|
|
53
|
+
π: "π",
|
|
54
|
+
σ: "σ",
|
|
55
|
+
τ: "τ",
|
|
56
|
+
φ: "φ",
|
|
57
|
+
ω: "ω",
|
|
58
|
+
Δ: "Δ",
|
|
59
|
+
Ω: "Ω",
|
|
60
|
+
"∞": "∞",
|
|
61
|
+
"±": "±",
|
|
62
|
+
"⨯": "⨯",
|
|
63
|
+
"°": "°",
|
|
64
|
+
"∑": "∑",
|
|
65
|
+
"∏": "∏",
|
|
66
|
+
"∫": "∫",
|
|
67
|
+
"√": "√",
|
|
68
|
+
"∠": "∠",
|
|
69
|
+
"∧": "∧",
|
|
70
|
+
"∨": "∨",
|
|
71
|
+
"∩": "∩",
|
|
72
|
+
"∪": "∪",
|
|
73
|
+
"⊂": "⊂",
|
|
74
|
+
"⊃": "⊃",
|
|
75
|
+
"∈": "∈",
|
|
76
|
+
"∉": "∉",
|
|
77
|
+
"∅": "∅",
|
|
78
|
+
"⊕": "⊕",
|
|
79
|
+
"⊖": "⊖",
|
|
80
|
+
"⊗": "⊗",
|
|
81
|
+
"⌖": "⌖",
|
|
82
|
+
"☆": "☆",
|
|
83
|
+
"★": "★",
|
|
84
|
+
"✓": "✓",
|
|
85
|
+
"✗": "✗",
|
|
17
86
|
"\xa0": " ",
|
|
18
87
|
};
|
|
19
|
-
export const RE_ENTITIES = new RegExp(`[${Object.keys(ENTITIES).join("")}]`, "
|
|
88
|
+
export const RE_ENTITIES = new RegExp(`[${Object.keys(ENTITIES).join("")}]`, "gu");
|
|
20
89
|
export const ENTITIES_REV = Object.entries(ENTITIES).reduce((acc, [k, v]) => ((acc[v] = k), acc), {});
|
|
21
90
|
export const RE_ENTITIES_REV = new RegExp(`(${Object.keys(ENTITIES_REV).join("|")})`, "g");
|
|
22
91
|
const $esc = (re, index) => (src) => src.replace(re, (x) => index[x]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/strings",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "Various string formatting & utility functions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
"test": "testament test"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@thi.ng/api": "^8.7.
|
|
38
|
-
"@thi.ng/errors": "^2.2.
|
|
39
|
-
"@thi.ng/hex": "^2.3.
|
|
40
|
-
"@thi.ng/memoize": "^3.1.
|
|
37
|
+
"@thi.ng/api": "^8.7.2",
|
|
38
|
+
"@thi.ng/errors": "^2.2.11",
|
|
39
|
+
"@thi.ng/hex": "^2.3.6",
|
|
40
|
+
"@thi.ng/memoize": "^3.1.25"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@microsoft/api-extractor": "^7.34.2",
|
|
44
|
-
"@thi.ng/testament": "^0.3.
|
|
44
|
+
"@thi.ng/testament": "^0.3.11",
|
|
45
45
|
"rimraf": "^4.1.2",
|
|
46
46
|
"tools": "^0.0.1",
|
|
47
47
|
"typedoc": "^0.23.24",
|
|
@@ -200,5 +200,5 @@
|
|
|
200
200
|
"thi.ng": {
|
|
201
201
|
"year": 2015
|
|
202
202
|
},
|
|
203
|
-
"gitHead": "
|
|
203
|
+
"gitHead": "060a3a69281094df70be0e4f326a0ac3bbc3dd1d\n"
|
|
204
204
|
}
|
package/slugify.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { Stringer } from "./api.js";
|
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
7
|
* ```ts
|
|
8
|
-
* slugify("Me, myself (& ëye)
|
|
8
|
+
* slugify("Me, myself (& ëye) 😀!")
|
|
9
9
|
* // "me-myself-and-eye"
|
|
10
10
|
* ```
|
|
11
11
|
*
|
|
@@ -18,8 +18,8 @@ export declare const slugify: Stringer<string>;
|
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* ```ts
|
|
21
|
-
* slugifyGH("Me, myself (& ëye)
|
|
22
|
-
* // "me-myself--ëye"
|
|
21
|
+
* slugifyGH("Me, myself (& ëye) 😀!")
|
|
22
|
+
* // "me-myself--ëye-"
|
|
23
23
|
* ```
|
|
24
24
|
*
|
|
25
25
|
* @param str -
|
package/slugify.js
CHANGED
|
@@ -7,21 +7,23 @@ const re = new RegExp(src.split("").join("|"), "g");
|
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* ```ts
|
|
10
|
-
* slugify("Me, myself (& ëye)
|
|
10
|
+
* slugify("Me, myself (& ëye) 😀!")
|
|
11
11
|
* // "me-myself-and-eye"
|
|
12
12
|
* ```
|
|
13
13
|
*
|
|
14
14
|
* @param str -
|
|
15
15
|
*/
|
|
16
16
|
export const slugify = (str) => {
|
|
17
|
-
return str
|
|
17
|
+
return (str
|
|
18
18
|
.toLowerCase()
|
|
19
19
|
.replace(/\s+/g, "-")
|
|
20
20
|
.replace(re, (c) => dest[src.indexOf(c)])
|
|
21
21
|
.replace(/&+/g, "-and-")
|
|
22
22
|
.replace(/[^\w\-]+/g, "")
|
|
23
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Unicode_Property_Escapes
|
|
24
|
+
.replace(/\p{Emoji_Presentation}/gu, "")
|
|
23
25
|
.replace(/\-{2,}/g, "-")
|
|
24
|
-
.replace(/(^-+)|(-+$)/g, "");
|
|
26
|
+
.replace(/(^-+)|(-+$)/g, ""));
|
|
25
27
|
};
|
|
26
28
|
/**
|
|
27
29
|
* Similar to {@link slugify}, however uses GitHub's anchor naming rules
|
|
@@ -29,8 +31,8 @@ export const slugify = (str) => {
|
|
|
29
31
|
*
|
|
30
32
|
* @example
|
|
31
33
|
* ```ts
|
|
32
|
-
* slugifyGH("Me, myself (& ëye)
|
|
33
|
-
* // "me-myself--ëye"
|
|
34
|
+
* slugifyGH("Me, myself (& ëye) 😀!")
|
|
35
|
+
* // "me-myself--ëye-"
|
|
34
36
|
* ```
|
|
35
37
|
*
|
|
36
38
|
* @param str -
|
|
@@ -44,5 +46,7 @@ export const slugifyGH = (str) => {
|
|
|
44
46
|
// - https://www.unicode.org/charts/PDF/U2700.pdf (dingbats)
|
|
45
47
|
// - https://www.unicode.org/charts/PDF/U2E00.pdf (supplemental)
|
|
46
48
|
.replace(/[!"#$%&'()*+,./:;<=>?@\[\\\]^`{|}~\u0000-\u001f\u2000-\u206f\u2700-\u27bf\u2e00-\u2e7f]/g, "")
|
|
49
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Unicode_Property_Escapes
|
|
50
|
+
.replace(/\p{Emoji_Presentation}/gu, "")
|
|
47
51
|
.replace(/\s/g, "-"));
|
|
48
52
|
};
|