-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathutf32.d.ts
More file actions
89 lines (82 loc) · 3.34 KB
/
utf32.d.ts
File metadata and controls
89 lines (82 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* UTF-32 encoding/decoding
*
* ```js
* import { utf32fromString, utf32toString } from '@exodus/bytes/utf32.js'
*
* // loose
* import { utf32fromStringLoose, utf32toStringLoose } from '@exodus/bytes/utf32.js'
* ```
*
* _These methods by design encode/decode BOM (codepoint `U+FEFF` Byte Order Mark) as-is._
*
* @module @exodus/bytes/utf32.js
*/
/// <reference types="node" />
import type { Uint8ArrayBuffer, Uint32ArrayBuffer } from './array.js';
/**
* Output format for UTF-32 encoding
*/
export type Utf32Format = 'uint32' | 'uint8-le' | 'uint8-be';
/**
* Encode a string to UTF-32 bytes (strict mode)
*
* Throws on invalid Unicode (unpaired surrogates)
*
* @param string - The string to encode
* @param format - Output format (default: 'uint32')
* @returns The encoded bytes
*/
export function utf32fromString(string: string, format?: 'uint32'): Uint32ArrayBuffer;
export function utf32fromString(string: string, format: 'uint8-le'): Uint8ArrayBuffer;
export function utf32fromString(string: string, format: 'uint8-be'): Uint8ArrayBuffer;
export function utf32fromString(string: string, format?: Utf32Format): Uint32ArrayBuffer | Uint8ArrayBuffer;
/**
* Encode a string to UTF-32 bytes (loose mode)
*
* Replaces invalid Unicode (unpaired surrogates) with replacement codepoints `U+FFFD`.
*
* _Such replacement is a non-injective function, is irreversible and causes collisions.\
* Prefer using strict throwing methods for cryptography applications._
*
* @param string - The string to encode
* @param format - Output format (default: 'uint32')
* @returns The encoded bytes
*/
export function utf32fromStringLoose(string: string, format?: 'uint32'): Uint32ArrayBuffer;
export function utf32fromStringLoose(string: string, format: 'uint8-le'): Uint8ArrayBuffer;
export function utf32fromStringLoose(string: string, format: 'uint8-be'): Uint8ArrayBuffer;
export function utf32fromStringLoose(string: string, format?: Utf32Format): Uint32ArrayBuffer | Uint8ArrayBuffer;
/**
* Decode UTF-32 bytes to a string (strict mode)
*
* Throws on invalid UTF-32 byte sequences
*
* Throws on byte length not a multiple of 4.
*
* @param arr - The bytes to decode
* @param format - Input format (default: 'uint32')
* @returns The decoded string
*/
export function utf32toString(arr: Uint32Array, format?: 'uint32'): string;
export function utf32toString(arr: Uint8Array, format: 'uint8-le'): string;
export function utf32toString(arr: Uint8Array, format: 'uint8-be'): string;
export function utf32toString(arr: Uint32Array | Uint8Array, format?: Utf32Format): string;
/**
* Decode UTF-32 bytes to a string (loose mode)
*
* Replaces invalid UTF-32 byte sequences with replacement codepoints `U+FFFD`.
*
* _Such replacement is a non-injective function, is irreversible and causes collisions.\
* Prefer using strict throwing methods for cryptography applications._
*
* Throws on byte length not a multiple of 4.
*
* @param arr - The bytes to decode
* @param format - Input format (default: 'uint32')
* @returns The decoded string
*/
export function utf32toStringLoose(arr: Uint32Array, format?: 'uint32'): string;
export function utf32toStringLoose(arr: Uint8Array, format: 'uint8-le'): string;
export function utf32toStringLoose(arr: Uint8Array, format: 'uint8-be'): string;
export function utf32toStringLoose(arr: Uint32Array | Uint8Array, format?: Utf32Format): string;