Import escape function locally from html-escaper

This commit is contained in:
Ahmad Al Maaz 2021-06-19 12:02:56 +03:00
parent 4c1b4fbd78
commit 0119d23567
4 changed files with 24 additions and 13 deletions

View File

@ -1,4 +1,4 @@
import { escape } from 'html-escaper'
import { escape } from '@/lib/utils/htmlEscaper'
import siteMetadata from '@/data/siteMetadata'

23
lib/utils/htmlEscaper.js Normal file
View File

@ -0,0 +1,23 @@
const { replace } = ''
// escape
const es = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g
const ca = /[&<>'"]/g
const esca = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
"'": '&#39;',
'"': '&quot;',
}
const pe = (m) => 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) => replace.call(es, ca, pe)

11
package-lock.json generated
View File

@ -12,7 +12,6 @@
"@tailwindcss/typography": "^0.4.0",
"autoprefixer": "^10.2.5",
"gray-matter": "^4.0.2",
"html-escaper": "^3.0.3",
"image-size": "1.0.0",
"next": "10.2.3",
"next-mdx-remote": "^3.0.1",
@ -5274,11 +5273,6 @@
"minimalistic-crypto-utils": "^1.0.1"
}
},
"node_modules/html-escaper": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-3.0.3.tgz",
"integrity": "sha512-RuMffC89BOWQoY0WKGpIhn5gX3iI54O6nRA0yC124NYVtzjmFWBIiFd8M0x+ZdX0P9R4lADg1mgP8C7PxGOWuQ=="
},
"node_modules/html-tags": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/html-tags/-/html-tags-3.1.0.tgz",
@ -14648,11 +14642,6 @@
"minimalistic-crypto-utils": "^1.0.1"
}
},
"html-escaper": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-3.0.3.tgz",
"integrity": "sha512-RuMffC89BOWQoY0WKGpIhn5gX3iI54O6nRA0yC124NYVtzjmFWBIiFd8M0x+ZdX0P9R4lADg1mgP8C7PxGOWuQ=="
},
"html-tags": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/html-tags/-/html-tags-3.1.0.tgz",

View File

@ -16,7 +16,6 @@
"@tailwindcss/typography": "^0.4.0",
"autoprefixer": "^10.2.5",
"gray-matter": "^4.0.2",
"html-escaper": "^3.0.3",
"image-size": "1.0.0",
"next": "10.2.3",
"next-mdx-remote": "^3.0.1",