object-compressor
this module provide two functions compress
and decompress
.
The function compress
is good for compressing object that contains repeated keys and string values.
Good case for compressing
type : '[ADD] Ball' payload : targetId : 'longTargetIdOfBall1' maker : 'longUserIdOfMaker1' value : x : 12312 y : 1123 type : '[ADD] Ball' payload : targetId : 'longTargetIdOfBall1' maker : 'longUserIdOfMaker1' value : x : 2382 y : 1823 type : '[ADD] Ball' payload : targetId : 'longTargetIdOfBall1' maker : 'longUserIdOfMaker1' value : x : 82312 y : 2183 // ...
Result of above example
"o" : // compressed object "a" : "b" "c" : "d" : "e" "f" : "g" "h" : "i" : 12312 "j" : 1123 "a" : "b" "c" : "d" : "e" "f" : "g" "h" : "i" : 2382 "j" : 1823 "a" : "b" "c" : "d" : "e" "f" : "g" "h" : "i" : 82312 "j" : 2183 // ... "d" : // dictionary for decompressing "a" : "type" "b" : "[ADD] Ball" "c" : "payload" "d" : "targetId" "e" : "longTargetIdOfBall1" "f" : "maker" "g" : "longUserIdOfMaker1" "h" : "value" "i" : "x" "j" : "y"
Install
$ npm install --save object-compressor
Usage
TypeScript
; ;// store compressed data into DB or send the data via network... ;
JavaScript
const ObjComp = ; const rawObj // raw, verbose object let compressedResult = ObjComp;// store compressed data into DB or send the data via network... let originalObj = ObjComp;
Feedback Please
I'm looking forward to your pull-request, issue, email or any kind of feedback.