Skip to content

Commit cc3e76b

Browse files
committed
增加说明
1 parent 89860c7 commit cc3e76b

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

README.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,61 @@
1-
# json-pack
1+
# @kscript/json-pack
22
A simple JSON packer/unpacker
3+
4+
# example
5+
6+
``` javascript
7+
const jsonPack = require('@kscript/json-pack');
8+
const user = {
9+
a: 1,
10+
aa: 11,
11+
aaa: 111,
12+
aaaa: {
13+
b: 2,
14+
bb: 22,
15+
bbb: 222,
16+
bbbb: {
17+
a: 3,
18+
aa: 33,
19+
aa: 333
20+
}
21+
},
22+
d: [
23+
{
24+
a: 1,
25+
d: 4
26+
},
27+
{
28+
aa: 11,
29+
dd: 44
30+
},
31+
{
32+
aaa: 111,
33+
ddd: 444
34+
},
35+
{
36+
aaaa: 1111,
37+
dddd: 4444
38+
},
39+
{
40+
aaaa: 1111,
41+
dddd: 4444
42+
},
43+
{
44+
aaaa: 1111,
45+
dddd: 4444
46+
}
47+
]
48+
}
49+
// keys的引用不会丢失, 可以是一个公共的key数组, 用于多文件压缩
50+
// 单文件压缩时, keys会一起压缩, 每个文件都可以直接解压
51+
// 多文件压缩时, keys是公共的, 动态增加的, 需要自行保存好
52+
const options = { keys: [] }
53+
console.log([
54+
// 压缩
55+
jsonPack.compress(user),
56+
// 压缩 + 解压
57+
// 压缩时不传keys数组, 返回压缩后的content
58+
// 传入keys数组, 返回的是[content, options]数组(与解压函数的参数一一对应)
59+
jsonPack.decompress(...jsonPack.compress(user, options))
60+
])
61+
```

0 commit comments

Comments
 (0)