UNPKG

2.3 kBTypeScriptView Raw
1/**
2 * All 256 hexadecimal pairs
3 * @NOTE Maximum index is `255`
4 */
5export const HEX: readonly string[];
6
7/**
8 * Convert an `ArrayBuffer` to a hexadecimal string.
9 * @param {ArrayBuffer} input
10 */
11export function toHEX(input: ArrayBuffer): string;
12
13/**
14 * Decode a hexadecimal string into an `Uint8Array` instance.
15 * @NOTE Pass output through `decode()` for string conversion.
16 * @param {string} input
17 */
18export function viaHEX(input: string): Uint8Array;
19
20/**
21 * Generate a unique string of `len` length.
22 * @NOTE Relies on `crypto` to produce cryptographically secure (CSPRNG) values.
23 * @param {number} [len] The desired length (defaults to `11`)
24 */
25export function uid<N extends number = 11>(len?: N): UID<N>;
26export type UID<N extends number> = { 0: string; length: N } & string;
27
28/**
29 * Generate a new UUID.V4 value.
30 * @NOTE Relies on `crypto` to produce cryptographically secure (CSPRNG) values.
31 */
32export function uuid(): UUID;
33export type UUID = { 0: string; length: 36 } & string;
34
35/**
36 * Generate a universally unique lexicographically sortable identifier (ulid).
37 * @NOTE Relies on `crypto` to produce cryptographically secure (CSPRNG) values.
38 * @see https://github.com/ulid/spec
39 */
40export function ulid(): ULID;
41export type ULID = { 0: string; length: 26 } & string;
42
43/**
44 * Generate a specified number of cryptographically strong random values.
45 * @NOTE Throws a `QuotaExceededError` error if `length` exceeds 65,536 bytes.
46 */
47export function randomize(length: number): Uint8Array;
48
49/**
50 * Reusable `TextEncoder` instance.
51 */
52export const Encoder: TextEncoder;
53
54/**
55 * Reusable `TextDecoder` instance.
56 * @NOTE Initialized with UTF-8 encoding.
57 */
58export const Decoder: TextDecoder;
59
60/**
61 * Encode a string as an `Uint8Array` containing UTF-8 encoded text.
62 * @param {string} input
63 */
64export function encode(input: string): Uint8Array;
65
66/**
67 * Decode a UTF-8 text string from an `ArrayBuffer` or an `ArrayBufferView` input.
68 * @param {string} input
69 * @param {boolean} [isStream] Additional data will follow in subsequent calls to decode.
70 */
71export function decode(input: ArrayBufferView | ArrayBuffer, isStream?: boolean): string;
72
73/**
74 * Calculate the length (in bytes) of an input string.
75 * @param {string} [input]
76 */
77export function byteLength(input?: string): number;