1.1.16 • Published 6 months ago

blue-tools v1.1.16

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

安装

npm install blue-tools

导入

import { blueTools } from 'blue-tools'

格式化时间

const time = new Date() // 时间
const timeStr = new Date().getTime() // 时间戳
console.log(blueTools.dateFormat(time))
console.log(blueTools.dateFormat(timeStr))

转义 HTML 中的特殊字符

const htmlStr = '<h1 title="abc">这是h1标签<span>123&nbsp;</span></h1>'
console.log(blueTools.htmlEscape(htmlStr))

还原 HTML 中的特殊字符

const str = '&lt;h1 title=&quot;abc&quot;&gt;这是h1标签&lt;span&gt;123&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;'
console.log(blueTools.htmlUnEscape(str))

深度解构对象赋值

使用场景:在做对象赋值,数组赋值时,所修改的是映射地址,导致修改新对象时旧对象内的值也会被改变,所以写了一个解构方法进行新对象的生成。

const a = { x: 1, y: 2 }
const b = blueTools.deepDeconstruction(a)
b.x = 3
console.log(a)
console.log(b)

深度解构对象对比数据是否相同

使用场景:在做对象比较时比较的是地址,导致对象内部就算值一模一样,比对结果也是 false,所以用此方法进行比对,并对该方法进行了拓展。

const a = { x: 1, y: 2 }
const b = { y: 2, x: 1 }
console.log(blueTools.isDeepStrictEqual(a, b))

blob 文件下载

// blueTools.fileDown(blob,'filename.txt')
// 文件名不添加后缀默认为txt

开源协议

ISC
1.1.9

8 months ago

1.1.8

8 months ago

1.1.7

8 months ago

1.1.6

8 months ago

1.1.5

8 months ago

1.1.4

8 months ago

1.1.3

8 months ago

1.1.2

10 months ago

1.1.12

7 months ago

1.1.11

7 months ago

1.1.10

7 months ago

1.1.16

6 months ago

1.1.15

6 months ago

1.1.14

7 months ago

1.1.13

7 months ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago