nvzson
v1.0.7
Published
nvzson ====================== - nvzson - zson is a simple format to describe nest-structure - which is used for test z-dsl of nvlang, normally USELESS
Downloads
3
Readme
nvzson
nvzson
zson is a simple format to describe nest-structure
which is used for test z-dsl of nvlang, normally USELESS
only z AND [ AND ] AND { AND } AND <digit> is valid char other-chars treated as white-space
z is a placeholder
[ and ] means array
<number> means repeated times
[z[zzz][z]] means [ any, [any,any,any], [any ] ]
[z[3z][z2] means [ any, [ ...REPEAT(z,3)], [any ...REPEAT(']',2)
[ any, [any,any,any], [any ] ]
for example
{
a: {
b0:100
b1:101
},
x:[10,20,30]
}
cant be map to {{zz}[zzz]} with z AS:
struct {
uint8_t type; // dict ary int
uint8_t key[2]; // max-length of 'a','b','b0','b1' if '' means its a array-element
uint8_t val; // 100 101 10 20 30
}
install
- npm install nvzson
usage
const {
parse_from_str,
stringify
} = require("nvzson");
example
> parse_from_str(`[z[zzz][z]]`)
[ 'z', [ 'z', 'z', 'z' ], [ 'z' ] ]
> parse_from_str(`[z[3z][z2]`)
[ 'z', [ 'z', 'z', 'z' ], [ 'z' ] ]
> console.dir({a:[10,[20,{x:11,y:22},[40]],50],b:300,c:400},{depth:null})
{
a: [ 10, [ 20, { x: 11, y: 22 }, [ 40 ] ], 50 ],
b: 300,
c: 400
}
> var j = parse_from_str(`{
[
z
[
z
{2z}
[z]
]
z
]
z
z
}`)
> console.dir(j,{depth:null})
{
':0': [ 'z', [ 'z', { ':0': 'z', ':1': 'z' }, [ 'z' ] ], 'z' ],
':1': 'z',
':2': 'z'
}
> stringify({a:[10,[20,{x:11,y:22},[40]],50],b:300,c:400},true/*compress block*/)
'{[z[z{2z}[z2]z]2z}'
> stringify({a:[10,[20,{x:11,y:22},[40]],50],b:300,c:400},false/*do NOT compress block*/)
'{[z[z{2z}[z]]z]2z}'
APIS
{
_glb: { _un: undefined, _nu: null, _t: true, _f: false },
_char: {
Z: 'z',
ALB: '[',
ARB: ']',
DLB: '{',
DRB: '}',
is_lower_z: [Function: is_lower_z],
is_bracket: [Function: is_bracket],
is_lbk: [Function: is_lbk],
is_rbk: [Function: is_rbk],
is_brace: [Function: is_brace],
is_lbc: [Function: is_lbc],
is_rbc: [Function: is_rbc],
is_blk: [Function: is_blk],
is_lblk: [Function: is_lblk],
is_rblk: [Function: is_rblk],
is_digit: [Function: is_digit],
is_valid: [Function: is_valid]
},
_ser: { stringify: [Function: from_json] },
_tok: {
Mach: [class Mach extends Array],
mach: Mach(2) [ 0, ___Box___(0) [] ],
creat_mach: [Function: creat_mach],
from_codes: [Function: from_codes],
from_str: [Function: from_str],
from_sg: [Function: from_sg],
from_ag: [AsyncFunction: from_ag]
},
_parse: {
Mach: [class Mach extends Array],
creat_mach: [Function: creat_mach],
mach: Mach(4) [ [], undefined, undefined, 0 ],
from_codes: [Function: from_codes],
from_str: [Function: from_str],
from_sg: [Function: from_sg],
from_ag: [AsyncFunction: from_ag]
},
parse_from_str: [Function: parse_from_str],
stringify: [Function: from_json]
}
LICENSE
- ISC