1.0.0 • Published 3 years ago

wjcdiyige v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

使用说明

1.下载

npm i D2021x-utils

2.下载

2.1 格式化时间

function dateFormat(dtStr) {
    var date = new Date(dtStr)
    var y = date.getFullYear()
    var m = padZero(date.getMonth() + 1)
    var d = padZero(date.getDate())

    return y + "-" + m + "-" + d

}

function padZero(n) {
    if (n < 10) {
        return '0' + n
    }
    return n
}

// module.exports = {
//     dateFormat
// }

2.2 转义HTML

function htmlEscape(htmlStr) {
    return htmlStr.replace(/&lt;|&gt;|&quot;|&amp;/g, (match) => {
        switch (match) {
            case '&lt;':
                return '<'
            case '&gt;':
                return '>'
            case '&quot;':
                return '"'
            case '&amp;':
                return '&'
        }
    })
}

2.3 还原HTML

function htmlUnEscape(htmlStr) {
    return htmlStr.replace(/<|>|"|&/g, (mathch) => {
        switch (match) {
            case '<':
                return '&lt;'
            case '>':
                return '&gt;'
            case '"':
                return '&quot;'
            case '&':
                return '&amp;'
        }
    })
}