initial commit
This commit is contained in:
commit
d799808203
126 changed files with 16265 additions and 0 deletions
22
lib/utils/htmlEscaper.ts
Normal file
22
lib/utils/htmlEscaper.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
const { replace } = ''
|
||||
|
||||
// escape
|
||||
const ca = /[&<>'"]/g
|
||||
|
||||
const esca = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
"'": ''',
|
||||
'"': '"',
|
||||
}
|
||||
const pe = (m: keyof typeof esca) => esca[m]
|
||||
|
||||
/**
|
||||
* Safely escape HTML entities such as `&`, `<`, `>`, `"`, and `'`.
|
||||
* @param {string} es the input to safely escape
|
||||
* @returns {string} the escaped input, and it **throws** an error if
|
||||
* the input type is unexpected, except for boolean and numbers,
|
||||
* converted as string.
|
||||
*/
|
||||
export const escape = (es: string): string => replace.call(es, ca, pe)
|
Loading…
Add table
Add a link
Reference in a new issue