@kayahr/text-encoding
Version:
Text encoder and decoder
76 lines (75 loc) • 2.64 kB
TypeScript
import type { Decoder, DecoderConstructor } from "./Decoder.ts";
import type { Encoder, EncoderConstructor } from "./Encoder.ts";
/**
* Registers an encoding.
*
* @param name - The encoding name.
* @param labels - The list of encoding labels.
* @param decoder - The constructor of the decoder which can decode this encoding.
* @param encoder - The constructor of the encoder which can encode this encoding.
* @returns The created and registered encoding.
*/
export declare function registerEncoding(name: string, labels: readonly string[], decoder: DecoderConstructor, encoder: EncoderConstructor): Encoding;
/**
* Returns the encoding for the specified label.
*
* @param label - The label of the encoding to look for.
* @returns The found encoding.
* @throws RangeError - When encoding was not found.
*/
export declare function getEncoding(label: string): Encoding;
/**
* Encoding.
*/
export declare class Encoding {
/** The encoding name. */
private readonly name;
/** The list of encoding labels. */
private readonly labels;
/** The constructor of the decoder which can decode this encoding. */
private readonly decoder;
/** The constructor of the encoder which can encode this encoding. */
private readonly encoder;
/**
* Creates a new encoding.
*
* @param name - The encoding name.
* @param labels - The list of encoding labels.
* @param decoder - The constructor of the decoder which can decode this encoding.
* @param encoder - The constructor of the encoder which can encode this encoding.
*/
constructor(name: string, labels: readonly string[], decoder: DecoderConstructor, encoder: EncoderConstructor);
/**
* Returns the encoding name.
*
* @returns The encoding name.
*/
getName(): string;
/**
* Checks if encoding has the given label.
*
* @param label - The label to check.
* @returns True if encoding has the label, false if not.
*/
hasLabel(label: string): boolean;
/**
* Returns the labels of this encoding.
*
* @returns The encoding labels.
*/
getLabels(): readonly string[];
/**
* Creates a new decoder for this encoding.
*
* @param fatal - True to throw exception on decoding errors, false to use replacement characters instead for
* characters which can't be decoded.
* @returns The created decoder.
*/
createDecoder(fatal?: boolean): Decoder;
/**
* Creates a new encoder for this encoding.
*
* @returns The created encoder.
*/
createEncoder(): Encoder;
}