@atproto/lex-data 0.0.13 → 0.0.15
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 +20 -0
- package/dist/blob.d.ts +118 -39
- package/dist/blob.d.ts.map +1 -1
- package/dist/blob.js +73 -10
- package/dist/blob.js.map +1 -1
- package/dist/lib/nodejs-buffer.d.ts +1 -0
- package/dist/lib/nodejs-buffer.d.ts.map +1 -1
- package/dist/lib/nodejs-buffer.js.map +1 -1
- package/dist/utf8-from-bytes.d.ts +3 -0
- package/dist/utf8-from-bytes.d.ts.map +1 -0
- package/dist/utf8-from-bytes.js +19 -0
- package/dist/utf8-from-bytes.js.map +1 -0
- package/dist/utf8.d.ts +18 -0
- package/dist/utf8.d.ts.map +1 -1
- package/dist/utf8.js +20 -1
- package/dist/utf8.js.map +1 -1
- package/package.json +1 -1
- package/src/blob.test.ts +38 -25
- package/src/blob.ts +198 -53
- package/src/lib/nodejs-buffer.ts +5 -0
- package/src/utf8-from-bytes.test.ts +43 -0
- package/src/utf8-from-bytes.ts +21 -0
- package/src/utf8.ts +20 -0
package/src/utf8.ts
CHANGED
|
@@ -3,10 +3,30 @@ import {
|
|
|
3
3
|
utf8FromBase64Node,
|
|
4
4
|
utf8FromBase64Ponyfill,
|
|
5
5
|
} from './utf8-from-base64.js'
|
|
6
|
+
import { utf8FromBytesNative, utf8FromBytesNode } from './utf8-from-bytes.js'
|
|
6
7
|
import { graphemeLenNative, graphemeLenPonyfill } from './utf8-grapheme-len.js'
|
|
7
8
|
import { utf8LenCompute, utf8LenNode } from './utf8-len.js'
|
|
8
9
|
import { utf8ToBase64Node, utf8ToBase64Ponyfill } from './utf8-to-base64.js'
|
|
9
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Converts a Uint8Array to a UTF-8 string.
|
|
13
|
+
*
|
|
14
|
+
* Uses Node.js Buffer when available for performance, falling back to
|
|
15
|
+
* TextDecoder in environments without Buffer support.
|
|
16
|
+
*
|
|
17
|
+
* @param bytes - The binary data to decode
|
|
18
|
+
* @returns The decoded string (as UTF-16 JavaScript string)
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { utf8FromBytes } from '@atproto/lex-data'
|
|
23
|
+
*
|
|
24
|
+
* const bytes = new Uint8Array([72, 101, 108, 108, 111])
|
|
25
|
+
* utf8FromBytes(bytes) // 'Hello'
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export const utf8FromBytes = utf8FromBytesNode ?? utf8FromBytesNative
|
|
29
|
+
|
|
10
30
|
/**
|
|
11
31
|
* Counts the number of grapheme clusters (user-perceived characters) in a string.
|
|
12
32
|
*
|