1.0.0 • Published 3 years ago

zyhtd-tools v1.0.0

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

安装

npm install zyhtd-tools

导入

let str = require('zyhtd-tools')

格式化日期

//获取日期对象
let data = new Date();
//调用 dateFormate 进行日期格式化操作
var str = str.dateFormate(data)
//结果 2021-11-05 14:47:25

转义 HTML 中的特殊字符

//获取需要转义的字符串
let htmlStr = '<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title></head><body><h2>使用vscode来版本管理</h2></body></html>'
//调用 htmlEscape 转义 htmlStr 中的特殊字符
var str1 = shizhong.htmlEscape(htmlStr);
//结果  &lt;!DOCTYPE html&gt;&lt;html lang=&quot;en&quot;&gt;&lt;head&gt;&lt;meta charset=&quot;UTF-8&quot;&gt;&lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;&lt;title&gt;Document&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;使用vscode来版本管理&lt;/h2&gt;&lt;/body&gt;&lt;/html&gt;

还原 HTML 中的特殊字符

//获取需要转义的特殊字符
var str1 = &lt;!DOCTYPE html&gt;&lt;html lang=&quot;en&quot;&gt;&lt;head&gt;&lt;meta charset=&quot;UTF-8&quot;&gt;&lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;&lt;title&gt;Document&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;使用vscode来版本管理&lt;/h2&gt;&lt;/body&gt;&lt;/html&gt;
//调用 htmlUnescape 转义 str1 中的特殊字符
var str2 = shizhong.htmlUnescape(str1);
//结果 <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title></head><body><h2>使用vscode来版本管理</h2></body></html>

开源协议

ISC