/** * A function that returns a replacement string for an individual escape character (i.e. the character immediately * following a backslash character) represented by the specified Unicode `code` point, if any. * * If an empty string is returned, the escape sequence will be removed from the returned string. If either `null` or * `undefined` are returned, the escape sequence will be included in the returned string as-is. * * This function is only passed `u` if not part of a valid Unicode escape sequence. * * @param code The Unicode code unit to be potentially replaced. * @param char The Unicode character to be potentially replaced. * @return A replacement string for an escape sequence for `code` or `null` or `undefined` to retain the escape * sequence. */ export type Replacer = (code: number, char: string) => string | null | undefined; /** * Returns a {@link Replacer} composed of the specified `replacers` that returns the replacement string returned from * the first {@link Replacer} to return a string, where possible. * * @example * const replacer = composeReplacer( * replaceChars({ f: "\f", n: "\n", r: "\r", t: "\t" }), * replaceUnescaped(), * ); * unescapeUnicode("I\\t\\u2665\\tUnicode\\\\!", { replacer }); * //=> "I ♥ Unicode\\!" * @param replacers The {@link Replacer} functions to be composed. * @return A {@link Replacer} composed of multiple `replacers`. */ export declare const composeReplacer: (...replacers: Replacer[]) => Replacer; /** * Returns a {@link Replacer} that always returns the specified `replacement`. * * @example * unescapeUnicode("I\\t\\u2665\\tUnicode!", { replacer: replaceConstant("?") }); * //=> "I?♥?Unicode!" * @param replacement The replacement string to always be returned. * @return A {@link Replacer} that always returns `replacement`. */ export declare const replaceConstant: (replacement: string) => Replacer; /** * Returns a {@link Replacer} that returns the specified `replacement` string for the individual escape character (i.e. * the character immediately following a backslash character) provided. * * @example * unescapeUnicode("I\\t\\u2665\\tUnicode!", { replacer: replaceChar("t", "\t") }); * //=> "I ♥ Unicode!" * @param char The individual escape character. * @param replacement The replacement string to be returned for `char`. * @return A {@link Replacer} that returns `replacement` string only for `char`. */ export declare const replaceChar: (char: string, replacement: string) => Replacer; /** * Returns a {@link Replacer} that returns replacement strings looked up from the specified `replacements`, where * possible. * * The keys within `replacements` are expected to be the individual escape characters (i.e. the character immediately * following a backslash character). * * @example Providing replacements in a map * const replacements = new Map([ * ["f", "\f"], * ["n", "\n"], * ["r", "\r"], * ["t", "\t"], * ]); * unescapeUnicode("I\\t\\u2665\\tUnicode!", { replacer: replaceChars(replacements) }); * //=> "I ♥ Unicode!" * @example Providing replacements in an object * const replacements = { * f: "\f", * n: "\n", * r: "\r", * t: "\t", * }; * unescapeUnicode("I\\t\\u2665\\tUnicode!", { replacer: replaceChars(replacements) }); * //=> "I ♥ Unicode!" * @param replacements A map/object containing individual escape characters mapped to their replacement strings. * @return A {@link Replacer} that returns replacement strings looked up from `replacements`. */ export declare const replaceChars: (replacements: Map | Record) => Replacer; /** * Returns a {@link Replacer} that returns the specified `replacement` string for the Unicode code point representing * the individual escape character (i.e. the character immediately following a backslash character) provided. * * @example * unescapeUnicode("I\\t\\u2665\\tUnicode!", { replacer: replaceCode(0x0074, "\t") }); * //=> "I ♥ Unicode!" * @param code The Unicode code point representing the individual escape character. * @param replacement The replacement string to be returned for `char`. * @return A {@link Replacer} that returns `replacement` string only for `code`. */ export declare const replaceCode: (code: number, replacement: string) => Replacer; /** * Returns a {@link Replacer} that returns replacement strings looked up from the specified `replacements`, where * possible. * * The keys within `replacements` are expected to be Unicode code points representing the individual escape characters * (i.e. the character immediately following a backslash character). * * @example Providing replacements in a map * const replacements = new Map([ * [0x0066, "\f"], * [0x006e, "\n"], * [0x0072, "\r"], * [0x0074, "\t"], * ]); * unescapeUnicode("I\\t\\u2665\\tUnicode!", { replacer: replaceCodes(replacements) }); * //=> "I ♥ Unicode!" * @example Providing replacements in an object * const replacements = { * 0x0066: "\f", * 0x006e: "\n", * 0x0072: "\r", * 0x0074: "\t", * }; * unescapeUnicode("I\\t\\u2665\\tUnicode!", { replacer: replaceCodes(replacements) }); * //=> "I ♥ Unicode!" * @param replacements A map/object containing Unicode code points representing individual escape characters mapped to * their replacement strings. * @return A {@link Replacer} that returns replacement strings looked up from `replacements`. */ export declare const replaceCodes: (replacements: Map | Record) => Replacer; /** * Returns a {@link Replacer} that always returns the individual escape character (i.e. the character immediately * following a backslash character) as the replacement string. * * @example * unescapeUnicode("I\\t\\u2665\\tUnicode!", { replacer: replaceUnescaped() }); * //=> "It♥tUnicode!" * @return A {@link Replacer} that returns the individual escape character. */ export declare const replaceUnescaped: () => Replacer; //# sourceMappingURL=replacer.d.ts.map