Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 2x 1x 1x 1x | /**
* 解码HTML,将实体字符转换为HTML字符
* @method str/decodeHTML
* @param {String} str 含有实体字符的字符串
* @returns {String} HTML字符串
* @example
* var $decodeHTML = require('@spore-ui/kit/packages/str/decodeHTML');
* $decodeHTML('&<>"' '); // '&<>"\' '
*/
function decodeHTML(str) {
if (typeof str !== 'string') {
throw new Error('decodeHTML need a string as parameter');
}
return str.replace(/"/g, '"')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/'/g, '\'')
.replace(/ /g, '\u00A0')
.replace(/ /g, '\u0020')
.replace(/&/g, '&');
}
module.exports = decodeHTML;
|