shelving
Version:
Toolkit for using data in JavaScript.
16 lines (15 loc) • 957 B
TypeScript
import type { AnyCaller } from "./function.js";
/** Types that can be converted to a `Uint8Array` byte sequence. */
export type PossibleBytes = Uint8Array | ArrayBuffer | string;
/** Assert that an unknown value is a `Uint8Array` byte sequence. */
export declare function assertBytes(value: unknown, min?: number, max?: number, caller?: AnyCaller): asserts value is Uint8Array;
/**
* Convert an unknown value to a `Uint8Array` byte sequence, or `undefined` if the value cannot be converted.
*
* - ArrayBuffers and TypedArrays are converted to `Uint8Array`
* - Strings are encoded as UTF-8.
* - Everything else returns `undefined`
*/
export declare function getBytes(value: unknown): Uint8Array | undefined;
/** Convert an unknown value to a `Uint8Array` byte sequence, or throw `RequiredError` if the value cannot be converted. */
export declare function requireBytes(value: PossibleBytes, min?: number, max?: number, caller?: AnyCaller): Uint8Array;