@thi.ng/strings 3.7.2 → 3.7.3
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 +1 -1
- package/ansi.js +12 -37
- package/api.js +4 -5
- package/case.js +24 -56
- package/center.js +12 -32
- package/currency.js +16 -8
- package/cursor.js +16 -37
- package/entities.js +136 -149
- package/escape.js +39 -62
- package/float.js +26 -45
- package/format.js +19 -27
- package/groups.js +42 -53
- package/hollerith.js +4 -16
- package/initials.js +6 -27
- package/int.js +8 -2
- package/interpolate.js +9 -36
- package/join.js +6 -21
- package/package.json +10 -7
- package/pad-left.js +18 -25
- package/pad-right.js +12 -13
- package/parse.js +10 -6
- package/percent.js +4 -7
- package/radix.js +32 -54
- package/range.js +13 -18
- package/repeat.js +6 -5
- package/ruler.js +12 -63
- package/slugify.js +12 -48
- package/splice.js +15 -29
- package/split.js +17 -28
- package/stringify.js +4 -12
- package/tabs.js +40 -81
- package/trim.js +7 -22
- package/truncate-left.js +6 -3
- package/truncate.js +8 -5
- package/units.js +77 -44
- package/utf8.js +72 -130
- package/uuid.js +4 -14
- package/vector.js +25 -28
- package/word-wrap.js +78 -141
- package/wrap.js +6 -5
package/CHANGELOG.md
CHANGED
package/ansi.js
CHANGED
|
@@ -1,38 +1,13 @@
|
|
|
1
1
|
const RE = /\x1b\[[0-9;]+m/g;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Returns true iff `x` contains ANSI control sequences.
|
|
16
|
-
*
|
|
17
|
-
* @param x -
|
|
18
|
-
*/
|
|
19
|
-
export const isAnsi = (x) => /\x1b\[[0-9;]+m/i.test(x);
|
|
20
|
-
/**
|
|
21
|
-
* Returns true iff `x` starts w/ an ANSI control sequence.
|
|
22
|
-
*
|
|
23
|
-
* @param x -
|
|
24
|
-
*/
|
|
25
|
-
export const isAnsiStart = (x) => /^\x1b\[[0-9;]+m/i.test(x);
|
|
26
|
-
/**
|
|
27
|
-
* Returns true iff `x` ends w/ an ANSI control sequence.
|
|
28
|
-
*
|
|
29
|
-
* @param x -
|
|
30
|
-
*/
|
|
31
|
-
export const isAnsiEnd = (x) => /\x1b\[[0-9;]+m$/i.test(x);
|
|
32
|
-
/**
|
|
33
|
-
* Returns length of `x` excluding any ANSI control sequences (via
|
|
34
|
-
* {@link stripAnsi}).
|
|
35
|
-
*
|
|
36
|
-
* @param x -
|
|
37
|
-
*/
|
|
38
|
-
export const lengthAnsi = (x) => stripAnsi(x).length;
|
|
2
|
+
const stripAnsi = (x) => x.replace(RE, "");
|
|
3
|
+
const isAnsi = (x) => /\x1b\[[0-9;]+m/i.test(x);
|
|
4
|
+
const isAnsiStart = (x) => /^\x1b\[[0-9;]+m/i.test(x);
|
|
5
|
+
const isAnsiEnd = (x) => /\x1b\[[0-9;]+m$/i.test(x);
|
|
6
|
+
const lengthAnsi = (x) => stripAnsi(x).length;
|
|
7
|
+
export {
|
|
8
|
+
isAnsi,
|
|
9
|
+
isAnsiEnd,
|
|
10
|
+
isAnsiStart,
|
|
11
|
+
lengthAnsi,
|
|
12
|
+
stripAnsi
|
|
13
|
+
};
|
package/api.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export const BOM = "\ufeff";
|
|
1
|
+
const BOM = "\uFEFF";
|
|
2
|
+
export {
|
|
3
|
+
BOM
|
|
4
|
+
};
|
package/case.js
CHANGED
|
@@ -1,56 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* kebab("FooBar23Baz");
|
|
26
|
-
* // "foo-bar23-baz"
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @param x -
|
|
30
|
-
* @param delim -
|
|
31
|
-
*/
|
|
32
|
-
export const kebab = (x, delim = "-") => lower(x.replace(
|
|
33
|
-
// TC39
|
|
34
|
-
// /(?<=[a-z0-9\u00e0-\u00fd])(?=[A-Z\u00c0-\u00dd])/g,
|
|
35
|
-
// (_, i) => (i ? delim : "")
|
|
36
|
-
/([a-z0-9\u00e0-\u00fd])([A-Z\u00c0-\u00dd])/g, (_, a, b) => a + delim + b));
|
|
37
|
-
/**
|
|
38
|
-
* Short for {@link kebab} using `_` as delimiter.
|
|
39
|
-
*
|
|
40
|
-
* @param x -
|
|
41
|
-
*/
|
|
42
|
-
export const snake = (x) => kebab(x, "_");
|
|
43
|
-
/**
|
|
44
|
-
* Uppercase version of {@link snake}.
|
|
45
|
-
*
|
|
46
|
-
* @param x -
|
|
47
|
-
*/
|
|
48
|
-
export const upperSnake = (x) => snake(x).toUpperCase();
|
|
49
|
-
/**
|
|
50
|
-
* Converts a kebab-case or snake_case string into CamelCase. Uses `-`
|
|
51
|
-
* as default delimiter.
|
|
52
|
-
*
|
|
53
|
-
* @param x -
|
|
54
|
-
* @param delim -
|
|
55
|
-
*/
|
|
56
|
-
export const camel = (x, delim = "-") => lower(x).replace(new RegExp(`\\${delim}+(\\w)`, "g"), (_, c) => upper(c));
|
|
1
|
+
const upper = (x) => x.toUpperCase();
|
|
2
|
+
const lower = (x) => x.toLowerCase();
|
|
3
|
+
const capitalize = (x) => x.length ? x[0].toUpperCase() + x.substring(1) : x;
|
|
4
|
+
const kebab = (x, delim = "-") => lower(
|
|
5
|
+
x.replace(
|
|
6
|
+
// TC39
|
|
7
|
+
// /(?<=[a-z0-9\u00e0-\u00fd])(?=[A-Z\u00c0-\u00dd])/g,
|
|
8
|
+
// (_, i) => (i ? delim : "")
|
|
9
|
+
/([a-z0-9\u00e0-\u00fd])([A-Z\u00c0-\u00dd])/g,
|
|
10
|
+
(_, a, b) => a + delim + b
|
|
11
|
+
)
|
|
12
|
+
);
|
|
13
|
+
const snake = (x) => kebab(x, "_");
|
|
14
|
+
const upperSnake = (x) => snake(x).toUpperCase();
|
|
15
|
+
const camel = (x, delim = "-") => lower(x).replace(new RegExp(`\\${delim}+(\\w)`, "g"), (_, c) => upper(c));
|
|
16
|
+
export {
|
|
17
|
+
camel,
|
|
18
|
+
capitalize,
|
|
19
|
+
kebab,
|
|
20
|
+
lower,
|
|
21
|
+
snake,
|
|
22
|
+
upper,
|
|
23
|
+
upperSnake
|
|
24
|
+
};
|
package/center.js
CHANGED
|
@@ -1,36 +1,16 @@
|
|
|
1
1
|
import { memoizeJ } from "@thi.ng/memoize/memoizej";
|
|
2
2
|
import { repeat } from "./repeat.js";
|
|
3
3
|
import { truncate } from "./truncate.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* center(20, "<>")(wrap(" ")("thi.ng"))
|
|
17
|
-
* // "<><><> thi.ng <><><>"
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* @param lineWidth - target length
|
|
21
|
-
* @param pad - pad character(s)
|
|
22
|
-
*/
|
|
23
|
-
export const center = memoizeJ((n, pad = " ") => {
|
|
24
|
-
const buf = repeat(String(pad), n);
|
|
25
|
-
return (x) => {
|
|
26
|
-
if (x == null)
|
|
27
|
-
return buf;
|
|
28
|
-
x = x.toString();
|
|
29
|
-
const r = (n - x.length) / 2;
|
|
30
|
-
return x.length < n
|
|
31
|
-
? buf.substring(0, r) +
|
|
32
|
-
x +
|
|
33
|
-
buf.substring(0, r + ((n & 1) === (x.length & 1) ? 0 : 1))
|
|
34
|
-
: truncate(n)(x);
|
|
35
|
-
};
|
|
4
|
+
const center = memoizeJ((n, pad = " ") => {
|
|
5
|
+
const buf = repeat(String(pad), n);
|
|
6
|
+
return (x) => {
|
|
7
|
+
if (x == null)
|
|
8
|
+
return buf;
|
|
9
|
+
x = x.toString();
|
|
10
|
+
const r = (n - x.length) / 2;
|
|
11
|
+
return x.length < n ? buf.substring(0, r) + x + buf.substring(0, r + ((n & 1) === (x.length & 1) ? 0 : 1)) : truncate(n)(x);
|
|
12
|
+
};
|
|
36
13
|
});
|
|
14
|
+
export {
|
|
15
|
+
center
|
|
16
|
+
};
|
package/currency.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { memoizeJ } from "@thi.ng/memoize/memoizej";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const currency = memoizeJ((sym, pre = true, prec = 2) => {
|
|
3
|
+
const ff = (x) => x.toFixed(prec);
|
|
4
|
+
return pre ? (x) => sym + ff(x) : (x) => ff(x) + sym;
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const chf = currency("CHF ");
|
|
7
|
+
const eur = currency("\u20AC");
|
|
8
|
+
const gbp = currency("\xA3");
|
|
9
|
+
const usd = currency("$");
|
|
10
|
+
const yen = currency("\xA5");
|
|
11
|
+
export {
|
|
12
|
+
chf,
|
|
13
|
+
currency,
|
|
14
|
+
eur,
|
|
15
|
+
gbp,
|
|
16
|
+
usd,
|
|
17
|
+
yen
|
|
18
|
+
};
|
package/cursor.js
CHANGED
|
@@ -1,38 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* // [ 12, 4 ]
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* @param str -
|
|
21
|
-
* @param pos -
|
|
22
|
-
* @param delim -
|
|
23
|
-
* @param offset -
|
|
24
|
-
*/
|
|
25
|
-
export const computeCursorPos = (str, pos, delim = "\n", offset = [1, 1]) => {
|
|
26
|
-
if (!str.length)
|
|
27
|
-
return [1, 1];
|
|
28
|
-
pos = Math.min(Math.max(0, pos), str.length);
|
|
29
|
-
const lines = str.split(delim);
|
|
30
|
-
const n = lines.length;
|
|
31
|
-
for (let i = 0; i < n; i++) {
|
|
32
|
-
const l = lines[i];
|
|
33
|
-
if (pos <= l.length)
|
|
34
|
-
return [i + offset[0], pos + offset[1]];
|
|
35
|
-
pos -= l.length + 1;
|
|
36
|
-
}
|
|
37
|
-
return [n + offset[0] - 1, offset[1]];
|
|
1
|
+
const computeCursorPos = (str, pos, delim = "\n", offset = [1, 1]) => {
|
|
2
|
+
if (!str.length)
|
|
3
|
+
return [1, 1];
|
|
4
|
+
pos = Math.min(Math.max(0, pos), str.length);
|
|
5
|
+
const lines = str.split(delim);
|
|
6
|
+
const n = lines.length;
|
|
7
|
+
for (let i = 0; i < n; i++) {
|
|
8
|
+
const l = lines[i];
|
|
9
|
+
if (pos <= l.length)
|
|
10
|
+
return [i + offset[0], pos + offset[1]];
|
|
11
|
+
pos -= l.length + 1;
|
|
12
|
+
}
|
|
13
|
+
return [n + offset[0] - 1, offset[1]];
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
computeCursorPos
|
|
38
17
|
};
|
package/entities.js
CHANGED
|
@@ -1,151 +1,138 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
"⌖": "⌖",
|
|
107
|
-
"☆": "☆",
|
|
108
|
-
"★": "★",
|
|
109
|
-
"✓": "✓",
|
|
110
|
-
"✗": "✗",
|
|
111
|
-
"\xa0": " ",
|
|
1
|
+
const ENTITIES = {
|
|
2
|
+
"&": "&",
|
|
3
|
+
"<": "<",
|
|
4
|
+
">": ">",
|
|
5
|
+
"\u2264": "≤",
|
|
6
|
+
"\u2265": "≥",
|
|
7
|
+
'"': """,
|
|
8
|
+
"'": "'",
|
|
9
|
+
"\u2014": "—",
|
|
10
|
+
"\u2013": "–",
|
|
11
|
+
"\u2026": "…",
|
|
12
|
+
"\u22EE": "⋮",
|
|
13
|
+
"\u22EF": "⋯",
|
|
14
|
+
"\xA2": "¢",
|
|
15
|
+
"\u20AC": "€",
|
|
16
|
+
"\xA3": "£",
|
|
17
|
+
"\xA5": "¥",
|
|
18
|
+
"\u20B9": "₹",
|
|
19
|
+
\u5143: "元",
|
|
20
|
+
"\xA7": "§",
|
|
21
|
+
"\xB6": "¶",
|
|
22
|
+
"\xA9": "©",
|
|
23
|
+
"\xAE": "®",
|
|
24
|
+
"\u2122": "™",
|
|
25
|
+
"\u2103": "℃",
|
|
26
|
+
"\u2109": "℉",
|
|
27
|
+
K: "K",
|
|
28
|
+
"\u25C2": "◂",
|
|
29
|
+
"\u25B8": "▸",
|
|
30
|
+
"\u25B4": "▴",
|
|
31
|
+
"\u25BE": "▾",
|
|
32
|
+
"\u2190": "←",
|
|
33
|
+
"\u2192": "→",
|
|
34
|
+
"\u2191": "↑",
|
|
35
|
+
"\u2193": "↓",
|
|
36
|
+
"\u21B5": "↵",
|
|
37
|
+
"\u21A9": "↩",
|
|
38
|
+
"\u21D0": "⇐",
|
|
39
|
+
"\u21D2": "⇒",
|
|
40
|
+
"\u21BA": "↺",
|
|
41
|
+
"\u21BB": "↻",
|
|
42
|
+
"\xB9": "¹",
|
|
43
|
+
"\xB2": "²",
|
|
44
|
+
"\xB3": "³",
|
|
45
|
+
"\xBD": "½",
|
|
46
|
+
"\u2153": "⅓",
|
|
47
|
+
"\u2154": "⅔",
|
|
48
|
+
"\xBC": "¼",
|
|
49
|
+
"\xBE": "¾",
|
|
50
|
+
"\u2155": "⅕",
|
|
51
|
+
"\u2159": "⅙",
|
|
52
|
+
"\u215B": "⅛",
|
|
53
|
+
\u00C4: "Ä",
|
|
54
|
+
\u00CB: "Ë",
|
|
55
|
+
\u00CF: "Ï",
|
|
56
|
+
\u00D6: "Ö",
|
|
57
|
+
\u00DC: "Ü",
|
|
58
|
+
\u00E4: "ä",
|
|
59
|
+
\u00EB: "ë",
|
|
60
|
+
\u00EF: "ï",
|
|
61
|
+
\u00F6: "ö",
|
|
62
|
+
\u00FC: "ü",
|
|
63
|
+
\u00DF: "ß",
|
|
64
|
+
\u03B1: "α",
|
|
65
|
+
\u03B2: "β",
|
|
66
|
+
\u03B3: "γ",
|
|
67
|
+
\u03B4: "δ",
|
|
68
|
+
\u03B5: "ε",
|
|
69
|
+
\u03B8: "θ",
|
|
70
|
+
\u03BB: "λ",
|
|
71
|
+
\u03BC: "μ",
|
|
72
|
+
\u03C0: "π",
|
|
73
|
+
\u03C3: "σ",
|
|
74
|
+
\u03C4: "τ",
|
|
75
|
+
\u03C6: "φ",
|
|
76
|
+
\u03C9: "ω",
|
|
77
|
+
\u0394: "Δ",
|
|
78
|
+
\u03A9: "Ω",
|
|
79
|
+
"\u221E": "∞",
|
|
80
|
+
"\xB1": "±",
|
|
81
|
+
"\u2A2F": "⨯",
|
|
82
|
+
"\xB0": "°",
|
|
83
|
+
"\u2211": "∑",
|
|
84
|
+
"\u220F": "∏",
|
|
85
|
+
"\u222B": "∫",
|
|
86
|
+
"\u221A": "√",
|
|
87
|
+
"\u2220": "∠",
|
|
88
|
+
"\u2227": "∧",
|
|
89
|
+
"\u2228": "∨",
|
|
90
|
+
"\u2229": "∩",
|
|
91
|
+
"\u222A": "∪",
|
|
92
|
+
"\u2282": "⊂",
|
|
93
|
+
"\u2283": "⊃",
|
|
94
|
+
"\u2208": "∈",
|
|
95
|
+
"\u2209": "∉",
|
|
96
|
+
"\u2205": "∅",
|
|
97
|
+
"\u2295": "⊕",
|
|
98
|
+
"\u2296": "⊖",
|
|
99
|
+
"\u2297": "⊗",
|
|
100
|
+
"\u2316": "⌖",
|
|
101
|
+
"\u2606": "☆",
|
|
102
|
+
"\u2605": "★",
|
|
103
|
+
"\u2713": "✓",
|
|
104
|
+
"\u2717": "✗",
|
|
105
|
+
"\xA0": " "
|
|
112
106
|
};
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
* `<`, `>`, `'`, `"` and numeric entities for all others.
|
|
131
|
-
*
|
|
132
|
-
* @remarks
|
|
133
|
-
* This function is used as default by thi.ng/hiccup `serialize()` to escape
|
|
134
|
-
* characters and ensure compatibility with XML (which by default only supports
|
|
135
|
-
* named entities for the above 5 characters).
|
|
136
|
-
*
|
|
137
|
-
* @param src
|
|
138
|
-
*/
|
|
139
|
-
export const escapeEntitiesNum = (src) => src.replace(RE_ENTITIES, (x) => {
|
|
140
|
-
const code = x.charCodeAt(0);
|
|
141
|
-
return code < 128 ? ENTITIES[x] : `&#x${code.toString(16)};`;
|
|
107
|
+
const RE_ENTITIES = new RegExp(
|
|
108
|
+
`[${Object.keys(ENTITIES).join("")}]`,
|
|
109
|
+
"gu"
|
|
110
|
+
);
|
|
111
|
+
const ENTITIES_REV = Object.entries(ENTITIES).reduce(
|
|
112
|
+
(acc, [k, v]) => (acc[v] = k, acc),
|
|
113
|
+
{}
|
|
114
|
+
);
|
|
115
|
+
const RE_ENTITIES_REV = new RegExp(
|
|
116
|
+
`(${Object.keys(ENTITIES_REV).join("|")})`,
|
|
117
|
+
"g"
|
|
118
|
+
);
|
|
119
|
+
const RE_ENTITIES_NUM = /&#(x?)([0-9a-f]+);/gi;
|
|
120
|
+
const escapeEntities = (src) => src.replace(RE_ENTITIES, (x) => ENTITIES[x]);
|
|
121
|
+
const escapeEntitiesNum = (src) => src.replace(RE_ENTITIES, (x) => {
|
|
122
|
+
const code = x.charCodeAt(0);
|
|
123
|
+
return code < 128 ? ENTITIES[x] : `&#x${code.toString(16)};`;
|
|
142
124
|
});
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
125
|
+
const unescapeEntities = (src) => src.replace(RE_ENTITIES_REV, (x) => ENTITIES_REV[x]).replace(
|
|
126
|
+
RE_ENTITIES_NUM,
|
|
127
|
+
(_, hex, x) => String.fromCharCode(parseInt(x, hex ? 16 : 10))
|
|
128
|
+
);
|
|
129
|
+
export {
|
|
130
|
+
ENTITIES,
|
|
131
|
+
ENTITIES_REV,
|
|
132
|
+
RE_ENTITIES,
|
|
133
|
+
RE_ENTITIES_NUM,
|
|
134
|
+
RE_ENTITIES_REV,
|
|
135
|
+
escapeEntities,
|
|
136
|
+
escapeEntitiesNum,
|
|
137
|
+
unescapeEntities
|
|
138
|
+
};
|