@nberlette/utf8
Version:
Blazing fast universal ponyfills for TextEncoder and TextDecoder.
42 lines (41 loc) • 1.49 kB
TypeScript
/**
* Represents the result of encoding a string into a `Uint8Array` using the
* {@linkcode TextEncoder.encodeInto} method, with the number of characters
* read from the source and number of bytes written to the destination.
*/
export interface TextEncoderEncodeIntoResult {
/** The number of characters read from the input string. */
read: number;
/** The number of bytes written to the output buffer. */
written: number;
}
/**
* Encode strings into binary data (in the form of a `Uint8Array`) using the
* UTF-8 encoding standard. This is a high performance ponyfill for the native
* `TextEncoder` class.
*
* @category Encoding
* @tags utf-8, encoder
*/
export declare class TextEncoder {
/**
* The encoding standard to use. This is always `"utf-8"`.
* @returns "utf-8"
*/
get encoding(): string;
/**
* Encodes a string into a `Uint8Array` with UTF-8 encoding.
*
* @param input The string to encode. Defaults to an empty string.
* @returns A `Uint8Array` containing the UTF-8 encoded bytes.
*/
encode(input?: string): Uint8Array;
/**
* Encodes a string into a provided Uint8Array using UTF-8 encoding.
*
* @param input The string to encode.
* @param output The Uint8Array to write the encoded bytes into.
* @returns Object containing the number of characters read and bytes written
*/
encodeInto(input: string, output: Uint8Array): TextEncoderEncodeIntoResult;
}