-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
80 lines (70 loc) · 1.49 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var kvm = require('./'),
compress = kvm.compress,
decompress = kvm.decompress
// kvm.debugMode(true)
// kvm.disableGzip()
data = [{
class: "motogp",
rider: [{
name: "Valentino Rossi",
age: 39,
bike_number: 46,
world_champion: 7
}, {
name: "Marc Márquez",
age: 25,
bike_number: 93,
world_champion: 5
}, {
name: "Jorge Lorenzo",
age: 31,
bike_number: 99,
world_champion: 3
}]
}, {
class: "moto2",
rider: [{
name: "Francesco Bagnaia",
age: 21,
bike_number: 63,
world_champion: 1
}, {
name: "Franco Morbidelli",
age: 24,
bike_number: 21,
world_champion: 1
}, {
name: "Pol Espargaró",
age: 27,
bike_number: 44,
world_champion: 1
}]
}]
printJSON(data, false, true)
compressed = compress(data)
printJSON(compressed, false, true)
printJSON(decompress(compressed), false, true)
function print(data) {
console.log(data)
}
function printJSON(data, beutify = false, showSize = false) {
if (beutify) {
print(JSON.stringify(data, null, 2))
} else {
jsonString = JSON.stringify(data)
print(jsonString)
}
if (showSize) {
print("=> " + jsonSize(data) + " byte")
}
}
function sizeOf(string) {
try {
return string.length
} catch {
return 0
}
}
function jsonSize(data) {
return sizeOf(JSON.stringify(data))
}