1.0.0 • Published 5 years ago

yjx-itheima-tools v1.0.0

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

itheima-tools 使用说明

安装

npm i itheima-tools

导入

const itheima = require('itheima-tools');

格式化时间

// 调用 dateFormat() 格式化时间方法
const dt = itheima.dateFormat(new Date());
// 2020-03-04 16:01:47
console.log(dt);

html特殊字符转义 <, >, ", &

// 需要转义的字符
const htmlStr = '<h1 style="color: red;">我是一个<span>傻逼&</span></h1>'
// 调用 htmlEscape() 方法
const str = itheima.htmlEscape(htmlStr);
// &lt;h1 style=&quot;color: red;&quot;&gt;我是一个&lt;span&gt;傻逼&amp;&lt;/span&gt;&lt;/h1&gt;
console.log(str);

html特殊字符还原 <, >, ", &

// 需要转义的字符
const str = '&lt;h1 style=&quot;color: red;&quot;&gt;我是一个&lt;span&gt;傻逼&amp;&lt;/span&gt;&lt;/h1&gt;'
// 调用 htmlEscape() 方法
const htmlStr = itheima.htmlEscape(htmlStr);
// &lt;h1 style=&quot;color: red;&quot;&gt;我是一个&lt;span&gt;傻逼&amp;&lt;/span&gt;&lt;/h1&gt;
console.log(htmlStr);

开源协议

https://img.shields.io/npm/l/express?registry_uri=https%3A%2F%2Fregistry.npmjs.com

1.0.0

5 years ago