speedy-entities
Version:
The fastest XML/HTML entities decoder.
34 lines (33 loc) • 1.24 kB
TypeScript
/**
* The options recognized by {@linkcode createEntityDecoder}.
*/
export interface EntityDecoderOptions {
/**
* Mapping from an [character entity reference](https://www.w3.org/TR/html4/charset.html#h-5.3.2) to its decoded value.
* Entity references should contain only [a-zA-Z] and may optionally start with an ampersand "&" and end with
* a semicolon ";".
*
* ```json
* {
* "Δ": "\u0394",
* "LongRightArrow;": "\u27F6"
* }
* ```
*/
entities?: Record<string, string>;
/**
* If `true` then [numeric character references](https://www.w3.org/TR/html4/charset.html#h-5.3.1) must be terminated
* with a semicolon to be decoded. Otherwise, numeric character references are recognized even if they aren't
* terminated with a semicolon.
*
* @default false
*/
isNumericReferenceSemicolonRequired?: boolean;
}
/**
* Creates an entity decoder that rewrites numeric and named entities found in input to their respective values.
*
* @param options The decoder options.
* @returns A function that decodes entities in the string.
*/
export declare function createEntityDecoder(options?: EntityDecoderOptions): (input: string) => string;