@thi.ng/strings 3.5.0 → 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 +7 -1
- package/README.md +3 -1
- package/entities.d.ts +28 -0
- package/entities.js +32 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2023-09-
|
|
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,12 @@ 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
|
+
|
|
12
18
|
## [3.5.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/strings@3.5.0) (2023-09-15)
|
|
13
19
|
|
|
14
20
|
#### 🚀 Features
|
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
|
|
|
@@ -160,10 +160,12 @@ A selection:
|
|
|
160
160
|
|
|
161
161
|
| Screenshot | Description | Live demo | Source |
|
|
162
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) |
|
|
163
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) |
|
|
164
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) |
|
|
165
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) |
|
|
166
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) |
|
|
167
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) |
|
|
168
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) |
|
|
169
171
|
|
package/entities.d.ts
CHANGED
|
@@ -9,6 +9,34 @@ 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
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
|
+
*/
|
|
12
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
|
+
*/
|
|
13
41
|
export declare const unescapeEntities: (src: string) => string;
|
|
14
42
|
//# sourceMappingURL=entities.d.ts.map
|
package/entities.js
CHANGED
|
@@ -114,8 +114,38 @@ export const RE_ENTITIES = new RegExp(`[${Object.keys(ENTITIES).join("")}]`, "gu
|
|
|
114
114
|
export const ENTITIES_REV = Object.entries(ENTITIES).reduce((acc, [k, v]) => ((acc[v] = k), acc), {});
|
|
115
115
|
export const RE_ENTITIES_REV = new RegExp(`(${Object.keys(ENTITIES_REV).join("|")})`, "g");
|
|
116
116
|
export const RE_ENTITIES_NUM = /&#(x?)([0-9a-f]+);/gi;
|
|
117
|
-
|
|
118
|
-
|
|
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
|
+
*/
|
|
119
149
|
export const unescapeEntities = (src) => src
|
|
120
150
|
.replace(RE_ENTITIES_REV, (x) => ENTITIES_REV[x])
|
|
121
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
|
}
|