unescape
string
The inverse of escape; this method converts the HTML entities &, <, >, ", and ' in string to their corresponding characters.
Installation
Import
import { unescape } from '@tulx/utils';Source Code
Implementation
/**
* The inverse of escape; this method converts the HTML entities &, <, >, ", and ' in string to their corresponding characters.
*
* @param string - The string to unescape.
* @returns Returns the unescaped string.
*
* @example
* ```ts
* unescape('fred, barney, & pebbles'); // 'fred, barney, & pebbles'
* ```
*/
export function unescape(string: string): string {
const map: Record<string, string> = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
''': "'",
};
return string.replace(
/&|<|>|"|'/g,
(entity) => map[entity] || entity
);
}
Example
import { unescape } from '@tulx/utils';
unescape('fred, barney, & pebbles'); // 'fred, barney, & pebbles'Related Functions
camelCase
Converts string to camel case.
capitalize
Converts the first character of string to upper case and the remaining to lower case.
deburr
Deburrs string by converting Latin-1 Supplement and Latin Extended-A letters to basic Latin letters and removing combining diacritical marks.
endsWith
Checks if string ends with the given target string.
escape
Converts the characters "&", "<", ">", '"', and "'" in string to their corresponding HTML entities.
escapeRegExp
Escapes the RegExp special characters "^", "$", "\", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in string.