-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
42 lines (40 loc) · 1.36 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
var assert = require("assert");
var dict = [ "red", "yellow", "orange", "blue", "green", "white",
"Asia", "North America", "South America",
"name", "continent", "flagColors",
"leader", "title", "term", "population", "平" ],
kramer = require("./juri.js")(dict),
data = {
zh: {
name: "China", continent: "Asia",
flagColors: ["red", "yellow"],
leader: { name: "习 近平-习", title: "President", term: 137 },
population: 1434440076830
},
in: {
name: "India", continent: "", a: true, b: false, c: null,
emptyArray: [], emptyObject: {},
flagColors: ["orange", "white", "green"],
leader: { name: "Narendra\nModi.", undef: undefined, title: "Prime Minister", term: 119 },
population: 1.19E9,
nan: NaN,
infi: Infinity,
neginf: -Infinity,
nul: null
},
array: ["asdf", [3, undefined, 4]]
},
encoded = kramer.encodeQString(data),
decoded = kramer.decodeQString(encoded),
json = JSON.stringify(data);
console.log("Original: ", data);
console.log("Encoded: ", encoded);
console.log("Decoded: ", decoded);
assert.deepEqual(data, decoded);
console.log(
"Compressed to " +
Math.round(encoded.length * 10000 / json.length)/100 +
"% of plain JSON and " +
Math.round(encoded.length * 10000 / encodeURIComponent(json).length)/100 +
"% of URL-encoded JSON"
);