1.0.0 • Published 2 years ago

trachinoid-bloc v1.0.0

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

使用说明: 该包来自吴氏龙腾集团,如需转载请联系本集团获得授权后方可转载!

安装

npm install trachinoid-bloc

导入

const trach = require('trachinoid');

格式化代码

function dateform(dadastr) {
    const date = new Date(dadastr);
    const y = date.getFullYear();
    const m = date.getMonth() + 1 > 9 ? date.getMonth() + 1 : '0' + (date.getMonth() + 1);
    const d = date.getDay() > 9 ? date.getDay() : '0' + date.getDay();
    const HH = date.getHours() > 9 ? date.getHours() : '0' + date.getHours();
    const MM = date.getMinutes() > 9 ? date.getMinutes() : '0' + date.getMinutes();
    const SS = date.getSeconds() > 9 ? date.getSeconds() : '0' + date.getSeconds();
    return `${y}-${m}-${d} ${HH}:${MM}:${SS}`;
}
// 使用dateform()并传入new date()即可获得标准的时间格式;

转义HTML的特殊字符

function HTMLEscape(htmlstr) {
    if (htmlstr == '') {
        throw Error('请输入要转换的内容!');
        return
    }
    return htmlstr.replace(/<|>|"|&/g, (match) => {
        switch (match) {
            case '<':
                return '&lt;'
            case '>':
                return '&gt;'
            case '"':
                return '&quot;'
            case '&':
                return '&amp;'
        }

    })
}
// 使用HTMLescape() 输入字符串,将<,>,",&符号转换成转义符

开源协议

ISC