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 | 1x 1x 1x | /* eslint-disable no-control-regex */
/**
* 编码HTML,将HTML字符转为实体字符
* @method encodeHTML
* @param {String} str 含有HTML字符的字符串
* @return {String} 经过转换的字符串
* @example
* import { encodeHTML } from '@spore-ui/tskit';
* encodeHTML(`&<>"\' `); // '&<>"' '
*/
export function encodeHTML(str: string): string {
return str.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/'/g, ''')
.replace(/\u00A0/g, ' ')
.replace(/(\u0020|\u000B|\u2028|\u2029|\f)/g, ' ');
}
export default encodeHTML;
|