1.0.3 • Published 11 months ago
nv-json-flatify v1.0.3
nv-json-flatify
- convert a json to two flat array, for compress using
- its for compatible with nvlang-serde, normally USELESS
- nvlang has a non-string-mode(NOT support string(if .byte length >5))
install
- npm install nv-json-flatify
usage
const {creat_flatify,nestify} = require("nv-json-flatify");
var flatify = creat_flatify();
example
var j = {a:[null,true,false,{s:11112222},Infinity,-Infinity,NaN],aa:["","a","\b\t\n\v\f\r","我 你"]}
var flat = flatify(j)
//console.log(flat)
/*
[Object: null prototype] {
typs: [
8, 2147483649, 6,
2, 3, 4,
8, 2147483650, 0,
9, 0, 0,
0, 7, 2147483651,
6, 2147483652, 2147483649,
2147483653, 2147483654, 7,
9
],
f64s: [ 【.f64s AND .typs will be put to a array-of 8-byte, then do compress IF necessary(compress-code NOT included in this package) 】
NaN, NaN, NaN,
NaN, NaN, NaN,
NaN, NaN, 11112222,
NaN, Infinity, -Infinity,
NaN, NaN, NaN,
NaN, NaN, NaN,
NaN, NaN, NaN,
NaN
],
imap: [Object: null prototype] { 【this IS pre-shared between front-end AND back-end, ONLY need to resync IF do app-code update】
'2147483649': 'a',
'2147483650': 's',
'2147483651': 'aa',
'2147483652': '',
'2147483653': '\b\t\n\x0B\f\r',
'2147483654': '我 你'
}
}
*/
console.log(nestify(flat))
/*
{
a: [ null, true, false, { s: 11112222 }, Infinity, -Infinity, NaN ],
aa: [ '', 'a', '\b\t\n\x0B\f\r', '我 你' ]
}
*/
METHODS
APIS
creat_flatify(Spool@nv-string-map | undefined) -> flatify
flatify(j) -> {
spool: Spool@nv-string-map
typs: Array<2|3|4|6|7|8|9| uint32_t@is_valid_nv_smap_id>
f64s: Array<double>
}
nestify(@result_of<flatify>) -> JSON
LICENSE
- ISC