Repository navigation
Expand file tree
/
Copy pathencode.ts
More file actions
46 lines (44 loc) · 1.55 KB
/
Copy pathencode.ts
File metadata and controls
46 lines (44 loc) · 1.55 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
import * as Internal from '@app/internal/index.ts'
/** Shared UTF-8 encoder instance */
const encoder = new TextEncoder()
/**
* Encode text into bytes.
* @description Converts a string into a UTF-8 byte buffer.
* @param input - String to encode
* @returns UTF-8 byte buffer
*/
export default function encode(input: string): Uint8Array
/**
* Encode a string vector into bytes.
* @description Converts a vector of strings into UTF-8 byte buffers.
* @param input - Vector of strings to encode
* @returns Vector of byte buffers
*/
export default function encode(input: string[]): Uint8Array[]
/**
* Encode a string matrix into bytes.
* @description Converts a matrix of strings into UTF-8 byte buffers.
* @param input - Matrix of strings to encode
* @returns Matrix of byte buffers
*/
export default function encode(input: string[][]): Uint8Array[][]
/**
* Encode text into bytes.
* @description Converts strings into UTF-8 byte buffers.
* @param input - String, vector, or matrix of strings to encode
* @returns Byte buffers matching the input shape
*/
export default function encode(
input: string | string[] | string[][]
): Uint8Array | Uint8Array[] | Uint8Array[][]
/**
* Encode text into bytes.
* @description Converts strings into UTF-8 byte buffers.
* @param input - String, vector, or matrix of strings to encode
* @returns Byte buffers matching the input shape
*/
export default function encode(
input: string | string[] | string[][]
): Uint8Array | Uint8Array[] | Uint8Array[][] {
return Internal.mapper(input, (value) => encoder.encode(value ?? ''))
}