Add HTML encode/decode methods

This commit is contained in:
pyoor 2018-08-29 17:51:20 -04:00
parent ac7f4b3580
commit 2f87374476
2 changed files with 20 additions and 0 deletions

View File

@ -1,6 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const htmlentities = require('htmlentities')
const jsesc = require('jsesc')
const utils = require('../utils')
@ -72,6 +73,24 @@ class common extends utils {
}
}
/**
* Escape special characters using HTML entities
* @param {string} str
* @returns {string}
*/
static htmlEncode (str) {
return htmlentities.encode(str)
}
/**
* Remove HTML entities from string
* @param {string} str
* @returns {string}
*/
static htmlDencode (str) {
return htmlentities.decode(str)
}
/**
* Remove duplicate items from a list
* @param {Array} list

View File

@ -79,6 +79,7 @@
"webpack-cli": "^3.1.0"
},
"dependencies": {
"htmlentities": "^1.0.0",
"jsesc": "^2.5.1"
}
}