UNPKG

itxiaoyou-tools

Version:

提供了格式化时间、HTMLEscape相关的功能

38 lines (33 loc) 923 B
## Installation ``` npm install itxiaoyou-tools ``` ## Import ```js const itxiaoyou = require('itxiaoyou-tools') ``` ## Format Time ```js // Call dateFormat to format the time const dt = itxiaoyou.dateFormat(new Date()) // Result: 2025-05-16 01:59:12 console.log(dt) ``` ## Escape special characters in HTML ```js // HTML string to be escaped const htmlStr = '<h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>' // Call htmlEscape method to escape const newhtmlSrt = itxiaoyou.htmlEscape(htmlStr) // Result: &lt;h1 title=&quot;abc&quot;&gt;这是h1标签&lt;span&gt;123&amp;nbsp;&lt;/spangt;&lt;/h1&gt; console.log(newhtmlSrt) ``` ## Unescape special characters in HTML ```js // HTML string to be unescaped const newhtmlStrs = itxiaoyou.htmlUnEscape(htmlStr) // Result: <h1 title="abc">这是h1标签<span>123&nbsp;</span></h1> console.log(newhtmlStrs) ``` ## License ISC