@thi.ng/strings 3.3.26 → 3.4.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-02-10T14:03:11Z
3
+ - **Last updated**: 2023-03-02T18:09: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,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
@@ -140,7 +140,7 @@ For Node.js REPL:
140
140
  const strings = await import("@thi.ng/strings");
141
141
  ```
142
142
 
143
- Package sizes (brotli'd, pre-treeshake): ESM: 4.29 KB
143
+ Package sizes (brotli'd, pre-treeshake): ESM: 4.62 KB
144
144
 
145
145
  ## Dependencies
146
146
 
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
  "&": "&amp;",
3
9
  "<": "&lt;",
4
10
  ">": "&gt;",
11
+ "≤": "&le;",
12
+ "≥": "&ge;",
5
13
  '"': "&quot;",
6
14
  "'": "&apos;",
7
15
  "—": "&mdash;",
8
16
  "–": "&ndash;",
9
17
  "…": "&hellip;",
18
+ "⋮": "&vellip;",
19
+ "⋯": "&ctdot;",
10
20
  "¢": "&cent;",
11
21
  "€": "&euro;",
12
22
  "£": "&pound;",
13
23
  "§": "&sect;",
24
+ "¶": "&para;",
14
25
  "©": "&copy;",
15
26
  "®": "&reg;",
16
27
  "™": "&trade;",
28
+ "◂": "&ltrif;",
29
+ "▸": "&rtrif;",
30
+ "▴": "&utrif;",
31
+ "▾": "&dtrif;",
32
+ "←": "&larr;",
33
+ "→": "&rarr;",
34
+ "↑": "&uarr;",
35
+ "↓": "&darr;",
36
+ "↵": "&crarr;",
37
+ "↩": "&larrhk;",
38
+ "⇐": "&lArr;",
39
+ "⇒": "&rArr;",
40
+ "↺": "&olarr;",
41
+ "↻": "&orarr;",
42
+ "¹": "&sup1;",
43
+ "²": "&sup2;",
44
+ "³": "&sup3;",
45
+ α: "&alpha;",
46
+ β: "&beta;",
47
+ γ: "&gamma;",
48
+ δ: "&delta;",
49
+ ε: "&epsi;",
50
+ θ: "&theta;",
51
+ λ: "&lambda;",
52
+ μ: "&mu;",
53
+ π: "&pi;",
54
+ σ: "&sigma;",
55
+ τ: "&tau;",
56
+ φ: "&phi;",
57
+ ω: "&omega;",
58
+ Δ: "&Delta;",
59
+ Ω: "&Omega;",
60
+ "∞": "&infin;",
61
+ "±": "&plusmn;",
62
+ "⨯": "&Cross;",
63
+ "°": "&deg;",
64
+ "∑": "&sum;",
65
+ "∏": "&prod;",
66
+ "∫": "&int;",
67
+ "√": "&radic;",
68
+ "∠": "&angle;",
69
+ "∧": "&and;",
70
+ "∨": "&or;",
71
+ "∩": "&cap;",
72
+ "∪": "&cup;",
73
+ "⊂": "&sub;",
74
+ "⊃": "&sup;",
75
+ "∈": "&isin;",
76
+ "∉": "&notin;",
77
+ "∅": "&empty;",
78
+ "⊕": "&oplus;",
79
+ "⊖": "&ominus;",
80
+ "⊗": "&otimes;",
81
+ "⌖": "&target;",
82
+ "☆": "&star;",
83
+ "★": "&starf;",
84
+ "✓": "&check;",
85
+ "✗": "&cross;",
17
86
  "\xa0": "&nbsp;",
18
87
  };
19
- export const RE_ENTITIES = new RegExp(`[${Object.keys(ENTITIES).join("")}]`, "g");
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.26",
3
+ "version": "3.4.1",
4
4
  "description": "Various string formatting & utility functions",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -34,10 +34,10 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/api": "^8.7.2",
38
- "@thi.ng/errors": "^2.2.11",
37
+ "@thi.ng/api": "^8.7.3",
38
+ "@thi.ng/errors": "^2.2.12",
39
39
  "@thi.ng/hex": "^2.3.6",
40
- "@thi.ng/memoize": "^3.1.25"
40
+ "@thi.ng/memoize": "^3.1.26"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@microsoft/api-extractor": "^7.34.2",
@@ -200,5 +200,5 @@
200
200
  "thi.ng": {
201
201
  "year": 2015
202
202
  },
203
- "gitHead": "cafa4ecea90fb681949dc3885a5bd6ddefa38b51\n"
203
+ "gitHead": "a2915dee637c1b8cd2e11a78a23bd035e4f750e7\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
  };