nv-json-jshape
v1.0.16
Published
nv-json-jshape ======================= - simple version of nvjson
Downloads
24
Readme
nv-json-jshape
- simple version of nvjson
- for test class code-generator in nvlang
install
- npm install nv-json-jshape
usage
const jshape = require("nv-json-jshape");
example
shape
// ignore data-type(to null) , only keep key
> var rt = jshape({a:"ssss",b:[1,{k:"v"},3,[true,false,null]]})
> rt.shape_
{ a: null, b: [ null, { k: null }, null, [ null, null, null ] ] }
>
> rt.$children_[0].shape_
null
> rt.$children_[0].K
'a'
> rt.$children_[1].shape_
[ null, { k: null }, null, [ null, null, null ] ]
> rt.$children_[1].K
'b'
> rt.$sdfs_.map(nd=>nd.shape_)
[
{ a: null, b: [ null, [Object], null, [Array] ] },
null,
[ null, { k: null }, null, [ null, null, null ] ],
null,
{ k: null },
null,
null,
[ null, null, null ],
null,
null,
null
]
>
tshape
n: null //null will be tanslated to a <void*> in nvlang
S: string //string will be translated to a special-structure(similar to std::string just with utf8-support) in nvlang
N: number //number will be translated to <double>
B: boolean //bool will be translated to <bool>
// A and D ONLY appeared IF be treated AS leaf
A: array //array will be translated to <std::tuple>(nvlang ONLY has list(dynamic length) AND tuple(fixed length))
D: dict //dict will be translated to <struct>
// by default, expand all
> rt.tshape_
{
a: 'S',
b: [ 'N', { k: 'S' }, 'N', [ 'B', 'B', 'n' ] ],
c: [ { k: 'S' }, [ 'B', 'B', 'n' ] ]
}
>
cshape
//for generate declaration from data
var rt = jshape(
{
"a": "ssss", //0
"b": [
1, //1
{
"k": "v" //2
}, //3
3, //4
[
true, //5
false, //6
null //7
] //8
], //9
c: [
{
k:"vvv" //10
},//11
[
false,//12
true, //13
null //14
] //15
] //16
} //17
)
> rt.cshape_
[
[ 3, { k: 'S' } ],
[ 8, [ 'B', 'B', 'n' ] ],
[ 9, [ 'N', 3, 'N', 8 ] ],
[ 16, [ 3, 8 ] ],
[ 17, { a: 'S', b: 9, c: 16 } ]
]
>
METHODS
APIS
LICENSE
- ISC