All files / str decodeHTML.ts

100% Statements 3/3
100% Branches 0/0
100% Functions 1/1
100% Lines 3/3

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                    1x 1x                 1x  
/**
 * 解码HTML,将实体字符转换为HTML字符
 * @method decodeHTML
 * @param {String} str 含有实体字符的字符串
 * @return {String} HTML字符串
 * @example
 * import { decodeHTML } from '@spore-ui/tskit';
 * decodeHTML('&amp;&lt;&gt;&quot;&#39;&#32;'); // '&<>"\' '
 */
 
export function decodeHTML(str: string): string {
  return str.replace(/&quot;/g, '"')
    .replace(/&lt;/g, '<')
    .replace(/&gt;/g, '>')
    .replace(/&#39;/g, '\'')
    .replace(/&nbsp;/g, '\u00A0')
    .replace(/&#32;/g, '\u0020')
    .replace(/&amp;/g, '&');
}
 
export default decodeHTML;