htmlDecode.mjs

import isestr from './isestr.mjs'
import he from 'he'


/**
 * Html特殊字元(Html entities)字串反編碼
 *
 * Unit Test: {@link https://github.com/yuda-lyu/wsemi/blob/master/test/htmlDecode.test.mjs Github}
 * @memberOf wsemi
 * @param {String} str 輸入編碼後html字串
 * @returns {String} 回傳html字串
 * @example
 *
 * console.log(htmlDecode('foo&bar'))
 * // => foo&bar
 *
 * console.log(htmlDecode('foo © bar ≠ baz 𝌆 qux'))
 * // => foo © bar ≠ baz 𝌆 qux
 *
 * console.log(htmlDecode('<img src="x"" onerror="prompt(1)">'))
 * // => <img src="x"" onerror="prompt(1)">
 *
 */
function htmlDecode(str, opt = {}) {

    //check
    if (!isestr(str)) {
        return ''
    }

    //decode
    let r = he.decode(str, opt)

    return r
}


export default htmlDecode