JSFiddle - React, Tailwind, and code Playground
by kmturley
HTML
<script src="http://playground.bynduk.com/compress-new/jsonh.min.js"></script>
JavaScript
function set(key, value) {
var item = JSONH.pack(value);
localStorage.setItem(key, JSON.stringify(item));
return item;
}
function get(key, value) {
var item = JSON.parse(localStorage.getItem(key));
return JSONH.unpack(item);
}
var data = [
{
'firstname': 'Barry',
'lastname': 'Adams',
'age': 30,
'location': 'London'
},
{
'firstname': 'Gemma',
'lastname': 'Simons',
'age': 24,
'location': 'London'
},
{
'firstname': 'Simon',
'lastname': 'Truman',
'age': 18,
'location': 'San Francisco'
},
{
'firstname': 'Yasmine',
'lastname': 'Taylor',
'age': 30,
'location': 'San Francisco'
}
];
console.time('pack');
var packed = set('people', data);
console.timeEnd('pack');
console.time('unpack');
var unpacked = get('people', packed);
console.timeEnd('unpack');
console.log(packed, JSON.stringify(packed).length);
console.log(unpacked, JSON.stringify(unpacked).length);
console.log(Math.round((JSON.stringify(packed).length/JSON.stringify(unpacked).length)*100)+'%');