forked from lukeed/worktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.d.ts
77 lines (66 loc) · 2.25 KB
/
utils.d.ts
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
/**
* All 256 hexadecimal pairs
* @NOTE Maximum index is `255`
*/
export const HEX: readonly string[];
/**
* Convert an `ArrayBuffer` to a hexadecimal string.
* @param {ArrayBuffer} input
*/
export function toHEX(input: ArrayBuffer): string;
/**
* Decode a hexadecimal string into an `Uint8Array` instance.
* @NOTE Pass output through `decode()` for string conversion.
* @param {string} input
*/
export function viaHEX(input: string): Uint8Array;
/**
* Generate a unique string of `len` length.
* @NOTE Relies on `crypto` to produce cryptographically secure (CSPRNG) values.
* @param {number} [len] The desired length (defaults to `11`)
*/
export function uid<N extends number = 11>(len?: N): UID<N>;
export type UID<N extends number> = { 0: string; length: N } & string;
/**
* Generate a new UUID.V4 value.
* @NOTE Relies on `crypto` to produce cryptographically secure (CSPRNG) values.
*/
export function uuid(): UUID;
export type UUID = { 0: string; length: 36 } & string;
/**
* Generate a universally unique lexicographically sortable identifier (ulid).
* @NOTE Relies on `crypto` to produce cryptographically secure (CSPRNG) values.
* @see https://github.com/ulid/spec
*/
export function ulid(): ULID;
export type ULID = { 0: string; length: 26 } & string;
/**
* Generate a specified number of cryptographically strong random values.
* @NOTE Throws a `QuotaExceededError` error if `length` exceeds 65,536 bytes.
*/
export function randomize(length: number): Uint8Array;
/**
* Reusable `TextEncoder` instance.
*/
export const Encoder: TextEncoder;
/**
* Reusable `TextDecoder` instance.
* @NOTE Initialized with UTF-8 encoding.
*/
export const Decoder: TextDecoder;
/**
* Encode a string as an `Uint8Array` containing UTF-8 encoded text.
* @param {string} input
*/
export function encode(input: string): Uint8Array;
/**
* Decode a UTF-8 text string from an `ArrayBuffer` or an `ArrayBufferView` input.
* @param {string} input
* @param {boolean} [isStream] Additional data will follow in subsequent calls to decode.
*/
export function decode(input: ArrayBufferView | ArrayBuffer, isStream?: boolean): string;
/**
* Calculate the length (in bytes) of an input string.
* @param {string} [input]
*/
export function byteLength(input?: string): number;