@thi.ng/strings 3.4.13 → 3.6.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 +17 -1
- package/README.md +11 -8
- package/entities.d.ts +29 -0
- package/entities.js +61 -3
- package/package.json +2 -2
- package/units.d.ts +1 -0
- package/units.js +13 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2023-
|
|
3
|
+
- **Last updated**: 2023-09-19T10:42:50Z
|
|
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,22 @@ 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.6.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/strings@3.6.0) (2023-09-19)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add escapeEntitiesNum() ([f921491](https://github.com/thi-ng/umbrella/commit/f921491))
|
|
17
|
+
|
|
18
|
+
## [3.5.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/strings@3.5.0) (2023-09-15)
|
|
19
|
+
|
|
20
|
+
#### 🚀 Features
|
|
21
|
+
|
|
22
|
+
- add more HTML entities ([9fa5d91](https://github.com/thi-ng/umbrella/commit/9fa5d91))
|
|
23
|
+
- add support for numeric HTML entities ([8d942ba](https://github.com/thi-ng/umbrella/commit/8d942ba))
|
|
24
|
+
- add `RE_ENTITIES_NUM`
|
|
25
|
+
- update unescapeEntities() to also support numeric entities
|
|
26
|
+
- add unitless() formatter ([d5025ce](https://github.com/thi-ng/umbrella/commit/d5025ce))
|
|
27
|
+
|
|
12
28
|
### [3.4.12](https://github.com/thi-ng/umbrella/tree/@thi.ng/strings@3.4.12) (2023-08-22)
|
|
13
29
|
|
|
14
30
|
#### 🩹 Bug fixes
|
package/README.md
CHANGED
|
@@ -141,7 +141,7 @@ For Node.js REPL:
|
|
|
141
141
|
const strings = await import("@thi.ng/strings");
|
|
142
142
|
```
|
|
143
143
|
|
|
144
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 4.
|
|
144
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 4.86 KB
|
|
145
145
|
|
|
146
146
|
## Dependencies
|
|
147
147
|
|
|
@@ -158,13 +158,16 @@ directory are using this package.
|
|
|
158
158
|
|
|
159
159
|
A selection:
|
|
160
160
|
|
|
161
|
-
| Screenshot | Description
|
|
162
|
-
|
|
163
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/
|
|
164
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/
|
|
165
|
-
|
|
|
166
|
-
|
|
|
167
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/
|
|
161
|
+
| Screenshot | Description | Live demo | Source |
|
|
162
|
+
|:---------------------------------------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------|:----------------------------------------------------------|:---------------------------------------------------------------------------------------|
|
|
163
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/ascii-raymarch.jpg" width="240"/> | ASCII art raymarching with thi.ng/shader-ast & thi.ng/text-canvas | [Demo](https://demo.thi.ng/umbrella/ascii-raymarch/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/ascii-raymarch) |
|
|
164
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/big-font.png" width="240"/> | Large ASCII font text generator using @thi.ng/rdom | [Demo](https://demo.thi.ng/umbrella/big-font/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/big-font) |
|
|
165
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/crypto-chart.png" width="240"/> | Basic crypto-currency candle chart with multiple moving averages plots | [Demo](https://demo.thi.ng/umbrella/crypto-chart/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/crypto-chart) |
|
|
166
|
+
| | Basic SPA example with atom-based UI router | [Demo](https://demo.thi.ng/umbrella/login-form/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/login-form) |
|
|
167
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/mastodon-feed.jpg" width="240"/> | Mastodon API feed reader with support for different media types, fullscreen media modal, HTML rewriting | [Demo](https://demo.thi.ng/umbrella/mastodon-feed/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/mastodon-feed) |
|
|
168
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/render-audio.png" width="240"/> | Generative audio synth offline renderer and WAV file export | [Demo](https://demo.thi.ng/umbrella/render-audio/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/render-audio) |
|
|
169
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rstream-spreadsheet.png" width="240"/> | rstream based spreadsheet w/ S-expression formula DSL | [Demo](https://demo.thi.ng/umbrella/rstream-spreadsheet/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rstream-spreadsheet) |
|
|
170
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/xml-converter.png" width="240"/> | XML/HTML/SVG to hiccup/JS conversion | [Demo](https://demo.thi.ng/umbrella/xml-converter/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/xml-converter) |
|
|
168
171
|
|
|
169
172
|
## API
|
|
170
173
|
|
package/entities.d.ts
CHANGED
|
@@ -8,6 +8,35 @@ export declare const ENTITIES: Record<string, string>;
|
|
|
8
8
|
export declare const RE_ENTITIES: RegExp;
|
|
9
9
|
export declare const ENTITIES_REV: Record<string, string>;
|
|
10
10
|
export declare const RE_ENTITIES_REV: RegExp;
|
|
11
|
+
export declare const RE_ENTITIES_NUM: RegExp;
|
|
12
|
+
/**
|
|
13
|
+
* Replaces all occurrences of character keys in {@link ENTITIES} with their
|
|
14
|
+
* named HTML entities.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Only use this function when targetting HTML output. For XML/SVG etc. use
|
|
18
|
+
* {@link escapeEntitiesNum}.
|
|
19
|
+
*
|
|
20
|
+
* @param src
|
|
21
|
+
*/
|
|
11
22
|
export declare const escapeEntities: (src: string) => string;
|
|
23
|
+
/**
|
|
24
|
+
* Similar to {@link escapeEntities}, but only uses _named_ entities for `&`,
|
|
25
|
+
* `<`, `>`, `'`, `"` and numeric entities for all others.
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* This function is used as default by thi.ng/hiccup `serialize()` to escape
|
|
29
|
+
* characters and ensure compatibility with XML (which by default only supports
|
|
30
|
+
* named entities for the above 5 characters).
|
|
31
|
+
*
|
|
32
|
+
* @param src
|
|
33
|
+
*/
|
|
34
|
+
export declare const escapeEntitiesNum: (src: string) => string;
|
|
35
|
+
/**
|
|
36
|
+
* Replace all known named and numeric entities with their original characters.
|
|
37
|
+
* Opposite op of {@link escapeEntities} and {@link escapeEntitiesNum}.
|
|
38
|
+
*
|
|
39
|
+
* @param src
|
|
40
|
+
*/
|
|
12
41
|
export declare const unescapeEntities: (src: string) => string;
|
|
13
42
|
//# sourceMappingURL=entities.d.ts.map
|
package/entities.js
CHANGED
|
@@ -20,11 +20,17 @@ export const ENTITIES = {
|
|
|
20
20
|
"¢": "¢",
|
|
21
21
|
"€": "€",
|
|
22
22
|
"£": "£",
|
|
23
|
+
"¥": "¥",
|
|
24
|
+
"₹": "₹",
|
|
25
|
+
元: "元",
|
|
23
26
|
"§": "§",
|
|
24
27
|
"¶": "¶",
|
|
25
28
|
"©": "©",
|
|
26
29
|
"®": "®",
|
|
27
30
|
"™": "™",
|
|
31
|
+
"℃": "℃",
|
|
32
|
+
"℉": "℉",
|
|
33
|
+
K: "K",
|
|
28
34
|
"◂": "◂",
|
|
29
35
|
"▸": "▸",
|
|
30
36
|
"▴": "▴",
|
|
@@ -42,6 +48,25 @@ export const ENTITIES = {
|
|
|
42
48
|
"¹": "¹",
|
|
43
49
|
"²": "²",
|
|
44
50
|
"³": "³",
|
|
51
|
+
"½": "½",
|
|
52
|
+
"⅓": "⅓",
|
|
53
|
+
"⅔": "⅔",
|
|
54
|
+
"¼": "¼",
|
|
55
|
+
"¾": "¾",
|
|
56
|
+
"⅕": "⅕",
|
|
57
|
+
"⅙": "⅙",
|
|
58
|
+
"⅛": "⅛",
|
|
59
|
+
Ä: "Ä",
|
|
60
|
+
Ë: "Ë",
|
|
61
|
+
Ï: "Ï",
|
|
62
|
+
Ö: "Ö",
|
|
63
|
+
Ü: "Ü",
|
|
64
|
+
ä: "ä",
|
|
65
|
+
ë: "ë",
|
|
66
|
+
ï: "ï",
|
|
67
|
+
ö: "ö",
|
|
68
|
+
ü: "ü",
|
|
69
|
+
ß: "ß",
|
|
45
70
|
α: "α",
|
|
46
71
|
β: "β",
|
|
47
72
|
γ: "γ",
|
|
@@ -88,6 +113,39 @@ export const ENTITIES = {
|
|
|
88
113
|
export const RE_ENTITIES = new RegExp(`[${Object.keys(ENTITIES).join("")}]`, "gu");
|
|
89
114
|
export const ENTITIES_REV = Object.entries(ENTITIES).reduce((acc, [k, v]) => ((acc[v] = k), acc), {});
|
|
90
115
|
export const RE_ENTITIES_REV = new RegExp(`(${Object.keys(ENTITIES_REV).join("|")})`, "g");
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
116
|
+
export const RE_ENTITIES_NUM = /&#(x?)([0-9a-f]+);/gi;
|
|
117
|
+
/**
|
|
118
|
+
* Replaces all occurrences of character keys in {@link ENTITIES} with their
|
|
119
|
+
* named HTML entities.
|
|
120
|
+
*
|
|
121
|
+
* @remarks
|
|
122
|
+
* Only use this function when targetting HTML output. For XML/SVG etc. use
|
|
123
|
+
* {@link escapeEntitiesNum}.
|
|
124
|
+
*
|
|
125
|
+
* @param src
|
|
126
|
+
*/
|
|
127
|
+
export const escapeEntities = (src) => src.replace(RE_ENTITIES, (x) => ENTITIES[x]);
|
|
128
|
+
/**
|
|
129
|
+
* Similar to {@link escapeEntities}, but only uses _named_ entities for `&`,
|
|
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)};`;
|
|
142
|
+
});
|
|
143
|
+
/**
|
|
144
|
+
* Replace all known named and numeric entities with their original characters.
|
|
145
|
+
* Opposite op of {@link escapeEntities} and {@link escapeEntitiesNum}.
|
|
146
|
+
*
|
|
147
|
+
* @param src
|
|
148
|
+
*/
|
|
149
|
+
export const unescapeEntities = (src) => src
|
|
150
|
+
.replace(RE_ENTITIES_REV, (x) => ENTITIES_REV[x])
|
|
151
|
+
.replace(RE_ENTITIES_NUM, (_, hex, x) => String.fromCharCode(parseInt(x, hex ? 16 : 10)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/strings",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "Various string formatting & utility functions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -200,5 +200,5 @@
|
|
|
200
200
|
"thi.ng": {
|
|
201
201
|
"year": 2015
|
|
202
202
|
},
|
|
203
|
-
"gitHead": "
|
|
203
|
+
"gitHead": "c22e8996cee284ebe8ea88582beb1ab5fc6ee503\n"
|
|
204
204
|
}
|
package/units.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ export declare const bytes: Stringer<number>;
|
|
|
6
6
|
export declare const seconds: Stringer<number>;
|
|
7
7
|
export declare const meters: Stringer<number>;
|
|
8
8
|
export declare const grams: Stringer<number>;
|
|
9
|
+
export declare const unitless: Stringer<number>;
|
|
9
10
|
export {};
|
|
10
11
|
//# sourceMappingURL=units.d.ts.map
|
package/units.js
CHANGED
|
@@ -66,3 +66,16 @@ export const grams = units([
|
|
|
66
66
|
[1e9, " kt"],
|
|
67
67
|
[1e12, " Mt"],
|
|
68
68
|
], " g", 2);
|
|
69
|
+
export const unitless = units([
|
|
70
|
+
[1e-15, "f", 1],
|
|
71
|
+
[1e-12, "p", 1],
|
|
72
|
+
[1e-9, "n", 1],
|
|
73
|
+
[1e-6, "µ", 1],
|
|
74
|
+
[1e-3, "m", 1],
|
|
75
|
+
[1, ""],
|
|
76
|
+
[1e3, "k", 1],
|
|
77
|
+
[1e6, "M", 1],
|
|
78
|
+
[1e9, "G", 1],
|
|
79
|
+
[1e12, "T", 1],
|
|
80
|
+
[1e15, "P", 1],
|
|
81
|
+
], "", 0);
|