-
Notifications
You must be signed in to change notification settings - Fork 2
/
test-old.js
33 lines (29 loc) · 1.01 KB
/
test-old.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
var options = {
dict: ['red', 'blue', 'green', 'white',
'Asia', 'North America', 'South America'],
pset: [
['name', 'continent', 'flagColors', 'leader'],
['name', 'title', 'term']
]
},
kramer = require('./kramer-old.js')() /* (options) */,
data = {
zh: {
name: "China", continent: "Asia",
flagColors: ["red", "yellow"],
leader: { name: "Xi Jinping", title: "President" }
},
in: {
name: "India", continent: "Asia",
flagColors: ["orange", "white", "green"],
leader: { name: "Narendra Modi", title: "Prime Minister", term: 5 }
}
},
encoded = kramer.encode(data),
decoded = kramer.decode(encoded),
json = JSON.stringify(data);
console.log("Original: ", data);
console.log("Encoded: ", encoded);
console.log("Decoded: ", decoded);
console.log(json == JSON.stringify(decoded)? "Correct": "Incorrect");
console.log("Crammed into ", Math.round(encoded.length * 10000 / json.length)/100 + '% of URL encoded JSON');