Skip to content

Commit cec9b4f

Browse files
outslept43081j
andauthored
feat: add utf8 to the preferred manifest (#251)
* feat: add `utf8` * docs: update to new format --------- Co-authored-by: James Garbutt <43081j@users.noreply.github.com>
1 parent 9b6b2dd commit cec9b4f

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

docs/modules/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ESLint plugin.
2121
- [`buffer-equals`](./buffer-equals.md)
2222
- [`builtin-modules`](./builtin-modules.md)
2323
- [`chalk`](./chalk.md)
24-
| [`core-util-is`](./core-util-is.md)
24+
- [`core-util-is`](./core-util-is.md)
2525
- [`cpx`](./cpx.md)
2626
- [`crypto-js`](./crypto-js.md)
2727
- [`deep-equal`](./deep-equal.md)
@@ -77,4 +77,5 @@ ESLint plugin.
7777
- [`tempy`](./tempy.md)
7878
- [`traverse`](./traverse.md)
7979
- [`uri-js`](./uri-js.md)
80-
- [`xmldom`](./xmldom.md)
80+
- [`utf8`](./utf8.md)
81+
- [`xmldom`](./xmldom.md)

docs/modules/utf8.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
description: Modern alternatives to the utf8 package for UTF-8 encoding and decoding
3+
---
4+
5+
# Replacements for `utf8`
6+
7+
Modern Node and browsers provide native UTF-8 APIs, so this dependency is rarely needed.
8+
9+
## TextEncoder/TextDecoder (built-in)
10+
11+
The built-in [`TextEncoder`](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder) and [`TextDecoder`](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder) APIs provide a native way to handle UTF-8 encoding and decoding.
12+
13+
```ts
14+
const text = "";
15+
const encoder = new TextEncoder();
16+
const utf8Bytes = encoder.encode(text); // Uint8Array of UTF-8 bytes
17+
18+
// and to decode:
19+
20+
const decoder = new TextDecoder('utf-8', { fatal: true });
21+
const decodedText = decoder.decode(utf8Bytes); // "€"
22+
```
23+
24+
## Buffer (Node.js)
25+
26+
Node's built-in [`Buffer`](https://nodejs.org/api/buffer.html) provides both `Buffer.from(str, 'utf8')` and `buf.toString('utf8')` methods for UTF-8 encoding and decoding.
27+
28+
```ts
29+
const text = "";
30+
const utf8Buffer = Buffer.from(text, 'utf8'); // Buffer of UTF-8 bytes
31+
```

manifests/preferred.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,6 +2376,12 @@
23762376
"docPath": "uri-js",
23772377
"category": "preferred"
23782378
},
2379+
{
2380+
"type": "documented",
2381+
"moduleName": "utf8",
2382+
"docPath": "utf8",
2383+
"category": "preferred"
2384+
},
23792385
{
23802386
"type": "documented",
23812387
"moduleName": "xmldom",

0 commit comments

Comments
 (0)