//#region src/decode-codepoint.d.ts /** * Polyfill for `String.fromCodePoint`. It is used to create a string from a Unicode code point. */ declare const fromCodePoint: (...codePoints: number[]) => string; /** * Replace the given code point with a replacement character if it is a * surrogate or is outside the valid range. Otherwise return the code * point unchanged. */ declare function replaceCodePoint(codePoint: number): number; /** * Replace the code point if relevant, then convert it to a string. * * @deprecated Use `fromCodePoint(replaceCodePoint(codePoint))` instead. * @param codePoint The code point to decode. * @returns The decoded code point. */ declare function decodeCodePoint(codePoint: number): string; //#endregion //#region src/generated/decode-data-html.d.ts declare const htmlDecodeTree: Uint16Array; //#endregion //#region src/generated/decode-data-xml.d.ts declare const xmlDecodeTree: Uint16Array; //#endregion //#region src/decode.d.ts declare const CharCodes: { NUM: number; SEMI: number; EQUALS: number; ZERO: number; NINE: number; LOWER_A: number; LOWER_F: number; LOWER_X: number; LOWER_Z: number; UPPER_A: number; UPPER_F: number; UPPER_Z: number; }; declare const BinTrieFlags: { VALUE_LENGTH: number; BRANCH_LENGTH: number; JUMP_TABLE: number; }; declare const DecodingMode: { /** Entities in text nodes that can end with any character. */ readonly Legacy: 0; /** Only allow entities terminated with a semicolon. */ readonly Strict: 1; /** Entities in attributes have limitations on ending characters. */ readonly Attribute: 2; }; type DecodingModeType = (typeof DecodingMode)[keyof typeof DecodingMode]; /** * Producers for character reference errors as defined in the HTML spec. */ interface EntityErrorProducer { missingSemicolonAfterCharacterReference(): void; absenceOfDigitsInNumericCharacterReference(consumedCharacters: number): void; validateNumericCharacterReference(code: number): void; } /** * Token decoder with support of writing partial entities. */ declare class EntityDecoder { /** The tree used to decode entities. */ private readonly decodeTree; /** * The function that is called when a codepoint is decoded. * * For multi-byte named entities, this will be called multiple times, * with the second codepoint, and the same `consumed` value. * * @param codepoint The decoded codepoint. * @param consumed The number of bytes consumed by the decoder. */ private readonly emitCodePoint; /** An object that is used to produce errors. */ private readonly errors?; constructor(/** The tree used to decode entities. */ decodeTree: Uint16Array, /** * The function that is called when a codepoint is decoded. * * For multi-byte named entities, this will be called multiple times, * with the second codepoint, and the same `consumed` value. * * @param codepoint The decoded codepoint. * @param consumed The number of bytes consumed by the decoder. */ emitCodePoint: (cp: number, consumed: number) => void, /** An object that is used to produce errors. */ errors?: EntityErrorProducer | undefined); /** The current state of the decoder. */ private state; /** Characters that were consumed while parsing an entity. */ private consumed; /** * The result of the entity. * * Either the result index of a numeric entity, or the codepoint of a * numeric entity. */ private result; /** The current index in the decode tree. */ private treeIndex; /** The number of characters that were consumed in excess. */ private excess; /** The mode in which the decoder is operating. */ private decodeMode; /** Resets the instance to make it reusable. */ startEntity(decodeMode: DecodingModeType): void; /** * Write an entity to the decoder. This can be called multiple times with partial entities. * If the entity is incomplete, the decoder will return -1. * * Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the * entity is incomplete, and resume when the next string is written. * * @param input The string containing the entity (or a continuation of the entity). * @param offset The offset at which the entity begins. Should be 0 if this is not the first call. * @returns The number of characters that were consumed, or -1 if the entity is incomplete. */ write(input: string, offset: number): number; /** * Switches between the numeric decimal and hexadecimal states. * * Equivalent to the `Numeric character reference state` in the HTML spec. * * @param input The string containing the entity (or a continuation of the entity). * @param offset The current offset. * @returns The number of characters that were consumed, or -1 if the entity is incomplete. */ private stateNumericStart; private addToNumericResult; /** * Parses a hexadecimal numeric entity. * * Equivalent to the `Hexademical character reference state` in the HTML spec. * * @param input The string containing the entity (or a continuation of the entity). * @param offset The current offset. * @returns The number of characters that were consumed, or -1 if the entity is incomplete. */ private stateNumericHex; /** * Parses a decimal numeric entity. * * Equivalent to the `Decimal character reference state` in the HTML spec. * * @param input The string containing the entity (or a continuation of the entity). * @param offset The current offset. * @returns The number of characters that were consumed, or -1 if the entity is incomplete. */ private stateNumericDecimal; /** * Validate and emit a numeric entity. * * Implements the logic from the `Hexademical character reference start * state` and `Numeric character reference end state` in the HTML spec. * * @param lastCp The last code point of the entity. Used to see if the * entity was terminated with a semicolon. * @param expectedLength The minimum number of characters that should be * consumed. Used to validate that at least one digit * was consumed. * @returns The number of characters that were consumed. */ private emitNumericEntity; /** * Parses a named entity. * * Equivalent to the `Named character reference state` in the HTML spec. * * @param input The string containing the entity (or a continuation of the entity). * @param offset The current offset. * @returns The number of characters that were consumed, or -1 if the entity is incomplete. */ private stateNamedEntity; /** * Emit a named entity that was not terminated with a semicolon. * * @returns The number of characters consumed. */ private emitNotTerminatedNamedEntity; /** * Emit a named entity. * * @param result The index of the entity in the decode tree. * @param valueLength The number of bytes in the entity. * @param consumed The number of characters consumed. * * @returns The number of characters consumed. */ private emitNamedEntityData; /** * Signal to the parser that the end of the input was reached. * * Remaining data will be emitted and relevant errors will be produced. * * @returns The number of characters consumed. */ end(): number; } /** * Determines the branch of the current node that is taken given the current * character. This function is used to traverse the trie. * * @param decodeTree The trie. * @param current The current node. * @param nodeIdx The index right after the current node and its value. * @param char The current character. * @returns The index of the next node, or -1 if no branch is taken. */ declare function determineBranch(decodeTree: Uint16Array, current: number, nodeIndex: number, char: number): number; /** * Decodes an HTML string. * * @param htmlString The string to decode. * @param mode The decoding mode. * @returns The decoded string. */ declare function decodeHTML(htmlString: string, mode?: DecodingModeType): string; /** * Decodes an HTML string in an attribute. * * @param htmlAttribute The string to decode. * @returns The decoded string. */ declare function decodeHTMLAttribute(htmlAttribute: string): string; /** * Decodes an HTML string, requiring all entities to be terminated by a semicolon. * * @param htmlString The string to decode. * @returns The decoded string. */ declare function decodeHTMLStrict(htmlString: string): string; /** * Decodes an XML string, requiring all entities to be terminated by a semicolon. * * @param xmlString The string to decode. * @returns The decoded string. */ declare function decodeXML(xmlString: string): string; //#endregion export { BinTrieFlags, CharCodes, DecodingMode, DecodingModeType, EntityDecoder, EntityErrorProducer, decodeCodePoint, decodeHTML, decodeHTMLAttribute, decodeHTMLStrict, decodeXML, determineBranch, fromCodePoint, htmlDecodeTree, replaceCodePoint, xmlDecodeTree }; //# sourceMappingURL=decode-DoZoVGKY.d.ts.map