@kayahr/text-encoding
Version:
Text encoder and decoder
35 lines (34 loc) • 1.32 kB
TypeScript
/**
* The TextEncoder represents an encoder for a specific text encoding, such as UTF-8, ISO-8859-2, KOI8-R, GBK, etc.
* An encoder takes a string and emits an array of encoded bytes.
*/
export declare class TextEncoder implements globalThis.TextEncoder {
private readonly enc;
private encoder;
/**
* Creates a new encoder for the given encoding.
*
* @param label - The encoding label. Defaults to UTF-8
*/
constructor(label?: string);
/** @returns The name of the encoding. */
get encoding(): string;
/**
* Encodes the given string and returns the encoded bytes.
*
* @param input - The string to encode.
* @returns The encoded bytes.
*/
encode(input?: string): Uint8Array<ArrayBuffer>;
/** @inheritdoc */
encodeInto(source: string, destination: Uint8Array): TextEncoderEncodeIntoResult;
}
/**
* Creates and returns a new text encoder for the given encoding. When encoding is utf-8 then the built-in
* text encoder (which only supports utf-8) is returned. Otherwise our own implementation is returned for this
* specific encoding.
*
* @param label - The encoding label. Defaults to "utf-8".
* @returns The created text encoder.
*/
export declare function createTextEncoder(label?: string): globalThis.TextEncoder | TextEncoder;