custom-string-formatter
Version:
Customizable String Formatter
62 lines (61 loc) • 2.11 kB
TypeScript
/**
* 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 (text)
*
* @example
* import {sanitizeFilterArgs} from 'custom-string-formatter';
*
* sanitizeFilterArgs('hello', 'there :)'); //=> hello:there :)
*
* @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 `&`, 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:
* - `{` - decimal symbol code (1-6 digits);
* - `ƣ` - 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 (text)'); //=> some (text)
*
* decodeFilterArg('sòmê <téxt>'); //=> sòmê <téxt>
*
* decodeFilterArg('sòmê <téxt>', true); //=> some <text>
*
* @see {@link sanitizeFilterArgs}
*/
export declare function decodeFilterArg(arg: string, removeAccents?: boolean): string;