1.0.1 • Published 2 years ago
nv-facutil-json-readonly-visitor v1.0.1
nv-facutil-json-readonly-visitor
- nv-facutil-json-readonly-visitor
- simplified version of nvjson, BUT only support read-only
- flatten json
- json read-only visitor
- bfs
- pre-dfs
- post-dfs
- begin-end-dfs
install
- npm install nv-facutil-json-readonly-visitor
usage
example
const {
empty,
bfs,
pre_dfs,
post_dfs,
begin_end_dfs,
plbfs,
pre_pldfs,
post_pldfs,
begin_end_pldfs,
////
bfs_gen,
pre_dfs_gen,
post_dfs_gen,
begin_end_dfs_gen,
} = require("nv-facutil-json-readonly-visitor");
var o = {
a:[1,2,3],
b:"text"
}
generator
var g = pre_dfs_gen(o)
for(let nd of g) {
console.log("key",nd.key);
console.log("pl",nd.$pl_)
console.log("value",nd.value);
console.log("parent",nd.$parent_.value,"\n");
}
key Symbol(empty)
pl []
value { a: [ 1, 2, 3 ], b: 'text' }
parent undefined
key a
pl [ 'a' ]
value [ 1, 2, 3 ]
parent { a: [ 1, 2, 3 ], b: 'text' }
key 0
pl [ 'a', '0' ]
value 1
parent [ 1, 2, 3 ]
key 1
pl [ 'a', '1' ]
value 2
parent [ 1, 2, 3 ]
key 2
pl [ 'a', '2' ]
value 3
parent [ 1, 2, 3 ]
key b
pl [ 'b' ]
value text
parent { a: [ 1, 2, 3 ], b: 'text' }
flat array
bfs(o)
> bfs(o)
[
[ Symbol(empty), { a: [Array], b: 'text' } ],
[ 'a', [ 1, 2, 3 ] ],
[ 'b', 'text' ],
[ '0', 1 ],
[ '1', 2 ],
[ '2', 3 ]
]
> plbfs(o)
[
[ [], { a: [Array], b: 'text' } ],
[ [ 'a' ], [ 1, 2, 3 ] ],
[ [ 'b' ], 'text' ],
[ [ 'a', '0' ], 1 ],
[ [ 'a', '1' ], 2 ],
[ [ 'a', '2' ], 3 ]
]
>
pre_dfs(o)
> pre_dfs(o)
[
[ Symbol(empty), { a: [Array], b: 'text' } ],
[ 'a', [ 1, 2, 3 ] ],
[ '0', 1 ],
[ '1', 2 ],
[ '2', 3 ],
[ 'b', 'text' ]
]
> pre_pldfs(o)
[
[ [], { a: [Array], b: 'text' } ],
[ [ 'a' ], [ 1, 2, 3 ] ],
[ [ 'a', '0' ], 1 ],
[ [ 'a', '1' ], 2 ],
[ [ 'a', '2' ], 3 ],
[ [ 'b' ], 'text' ]
]
>
post_dfs(o)
> post_dfs(o)
[
[ '0', 1 ],
[ '1', 2 ],
[ '2', 3 ],
[ 'a', [ 1, 2, 3 ] ],
[ 'b', 'text' ],
[ Symbol(empty), { a: [Array], b: 'text' } ]
]
>
> o
{ a: [ 1, 2, 3 ], b: 'text' }
>
> post_pldfs(o)
[
[ [ 'a', '0' ], 1 ],
[ [ 'a', '1' ], 2 ],
[ [ 'a', '2' ], 3 ],
[ [ 'a' ], [ 1, 2, 3 ] ],
[ [ 'b' ], 'text' ],
[ [], { a: [Array], b: 'text' } ]
]
>
begin_end_dfs(o)
> begin_end_dfs(o)
[
[ Symbol(empty), { a: [Array], b: 'text' } ],
[ 'a', [ 1, 2, 3 ] ],
[ '0', 1 ],
[ '0', 1 ],
[ '1', 2 ],
[ '1', 2 ],
[ '2', 3 ],
[ '2', 3 ],
[ 'a', [ 1, 2, 3 ] ],
[ 'b', 'text' ],
[ 'b', 'text' ],
[ Symbol(empty), { a: [Array], b: 'text' } ]
]
>
> begin_end_pldfs(o)
[
[ [], { a: [Array], b: 'text' } ],
[ [ 'a' ], [ 1, 2, 3 ] ],
[ [ 'a', '0' ], 1 ],
[ [ 'a', '0' ], 1 ],
[ [ 'a', '1' ], 2 ],
[ [ 'a', '1' ], 2 ],
[ [ 'a', '2' ], 3 ],
[ [ 'a', '2' ], 3 ],
[ [ 'a' ], [ 1, 2, 3 ] ],
[ [ 'b' ], 'text' ],
[ [ 'b' ], 'text' ],
[ [], { a: [Array], b: 'text' } ]
]
>
API
{
jdcp: //deepcopy json
empty: Symbol(empty),
bfs: [Function: bfs],
plbfs: [Function: plbfs],
bfs_gen: [GeneratorFunction: wfs_gen_engine],
pre_dfs: [Function: sdfs],
pre_pldfs: [Function: plsdfs],
pre_dfs_gen: [GeneratorFunction: sdfs_gen_engine],
post_dfs: [Function: edfs],
post_pldfs: [Function: pledfs],
post_dfs_gen: [GeneratorFunction: edfs_gen_engine],
begin_end_dfs: [Function: sedfs],
begin_end_pldfs: [Function: plsedfs],
begin_end_dfs_gen: [GeneratorFunction: sedfs_gen_engine],
map_gen_to_plentry: [Function: map_gen_to_plentry],
tool: {
is_undefined: [Function: is_undefined],
is_null: [Function: is_null],
is_symbol: [Function: is_symbol],
is_boolean: [Function: is_boolean],
is_number: [Function: is_number],
is_str: [Function: is_str],
is_primitive: [Function: is_primitive],
is_ary: [Function: is_ary],
is_dict: [Function: is_dict],
is_leaf_ary: [Function: is_leaf_ary],
is_nonleaf_ary: [Function: is_nonleaf_ary],
is_leaf_dict: [Function: is_leaf_dict],
is_nonleaf_dict: [Function: is_nonleaf_dict],
is_leaf: [Function: is_leaf],
is_non_leaf: [Function: is_non_leaf]
}
}
LICENSE
- ISC