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 26 | 2x 1x 1x 1x | /* eslint-disable no-control-regex */ /** * 编码HTML,将HTML字符转为实体字符 * @method str/encodeHTML * @param {String} str 含有HTML字符的字符串 * @returns {String} 经过转换的字符串 * @example * var $encodeHTML = require('@spore-ui/kit/packages/str/encodeHTML'); * $encodeHTML(`&<>"\' `); // '&<>"' ' */ function encodeHTML(str) { if (typeof str !== 'string') { throw new Error('encodeHTML need a string as parameter'); } return str.replace(/&/g, '&') .replace(/"/g, '"') .replace(/</g, '<') .replace(/>/g, '>') .replace(/'/g, ''') .replace(/\u00A0/g, ' ') .replace(/(\u0020|\u000B|\u2028|\u2029|\f)/g, ' '); } module.exports = encodeHTML; |