UNPKG

custom-string-formatter

Version:
62 lines (61 loc) 2.11 kB
/** * Sanitizes text for one or more filter arguments by replacing symbols `:|{}()<>` * with their corresponding HTML-encoded strings (hexadecimal). * * When multiple arguments are provided, they are sanitized separately and then joined with `:`. * * Using this function on the same text multiple times will sanitize the text only once. * * @param args * Filter argument(s) text to be sanitized. * * @returns * Sanitized string that's safe to use as a filter argument. * * @example * import {sanitizeFilterArgs} from 'custom-string-formatter'; * * sanitizeFilterArgs('some (text)'); //=> some &#x28;text&#x29; * * @example * import {sanitizeFilterArgs} from 'custom-string-formatter'; * * sanitizeFilterArgs('hello', 'there :)'); //=> hello:there &#x3a;&#x29; * * @see {@link decodeFilterArg} */ export declare function sanitizeFilterArgs(...args: string[]): string; /** * Helper for decoding HTML-encoded symbols inside a string. * * This is almost a generic decoder for HTML-encoded symbols, * supporting decimal and hexadecimal codes, plus optional removal * of accents (diacritical marks) from letters. However, it does not * support HTML entity names, like `&amp;`, etc., as its main purpose * is to decode filter arguments (not full HTML documents), so it * prioritizes performance over universality. * * @param arg * A string that contains HTML-encoded symbols, like this: * - `&#123;` - decimal symbol code (1-6 digits); * - `&#x1a3;` - hexadecimal symbol code (1-5 hex digits, case-insensitive); * * @param removeAccents * Optional accents (diacritical marks) removal from letters, if truthy. * Default is `false`. * * @returns * Decoded string. * * @example * import {decodeFilterArg} from 'custom-string-formatter'; * * decodeFilterArg('some &#x28;text&#x29;'); //=> some (text) * * decodeFilterArg('sòmê &#60;téxt&#62;'); //=> sòmê <téxt> * * decodeFilterArg('sòmê &#60;téxt&#62;', true); //=> some <text> * * @see {@link sanitizeFilterArgs} */ export declare function decodeFilterArg(arg: string, removeAccents?: boolean): string;