@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/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
  *