nvvson
v1.0.2
Published
nvvson ======================= - a json-like array-only structure - for readonly config-file using
Downloads
3
Readme
nvvson
- a json-like array-only structure
- for readonly config-file using
install
- npm install nvvson
usage
const {der,ser} = require("nvvson");
#(....) MEANS a comment; "(" AND ")" must be escaped \( \)
begin with "." means a key, key MUST be [_a-z][_a-z0-9]+
begin with "'" means:
'u undefined
'n null
't true
'f false
others are INVALID
literal value only support <positive-int> OR <positive-bigint> OR 0, NOT support <negtive>, NOT support <double>
@<s|d|b|n|j|v|t>(...)
@s(...) MEANS a string: "(" AND ")" must be escaped \( \)
@d(...) MEANS a double
@b(...) MEANS a bigint
@n(...) MEANS a double OR bigint
@t(...) MEANS Date
@j(...) MEANS JSON "(" AND ")" must be escaped \( \)
comma CAN be "," | ";" | <white-space> | <newline>
colon CAN be ":" | "=" | <white-space> | <newline>
block CAN only be "[" "]" , can NOT be "{" "}"
NOT support quote : '"' "'" "`" all are INVALID
example
deserialize
var code = `
[
'u, 'n, 't, 'f,
1, @d(1.1), 123456789123456789123456789123456789, @t(2024-01-21T05:49:07.948Z), @s(a b c d e f g h),
.k0 : 1,
.kl : @d(1.1),
.k2 : 123456789123456789123456789123456789,
.k3 : @j([1,2,3,4]), #(this is a comment)
.k4 : [
'u, 'n, 't,'f,
1, @d(1.1), 123456789123456789123456789123456789, @t(2024-01-21T05:49:07.948Z), @s(a b c d e f g h),
.k0 : 1,
.kl : @d(1.1),
]
]
`;
var val = der(code);
[
undefined,
null,
true,
false,
1,
1.1,
123456789123456789123456789123456789n,
2024-01-21T05:49:07.948Z,
'a b c d e f g h',
1,
1.1,
123456789123456789123456789123456789n,
[ 1, 2, 3, 4 ],
[
undefined,
null,
true,
false,
1,
1.1,
123456789123456789123456789123456789n,
2024-01-21T05:49:07.948Z,
'a b c d e f g h',
1,
1.1,
k0: [Getter/Setter],
kl: [Getter/Setter]
],
k0: [Getter/Setter],
kl: [Getter/Setter],
k2: [Getter/Setter],
k3: [Getter/Setter],
k4: [Getter/Setter]
]
> val[9]
1
> val.k0
1
>
> val[9] === val.k0
true
> val[9]=1000
1000
> val.k0
1000
>
> val.k0 = 1111
1111
> val[9]
1111
>
serialize NOT symmetric WITH deserialize: the key will be dropped by default, vson is mainly for deser,
> ser(val)
"['u,'n,'t,'f,@d(1),@d(1.1),@b(123456789123456789123456789123456789),@t(2024-01-21T05:49:07.948Z),@s(a b c d e f g h),@d(1),@d(1.1),@b(123456789123456789123456789123456789),[@d(1),@d(2),@d(3),@d(4),],['u,'n,'t,'f,@d(1),@d(1.1),@b(123456789123456789123456789123456789),@t(2024-01-21T05:49:07.948Z),@s(a b c d e f g h),@d(1),@d(1.1),],]"
>
> console.log(ser(val))
['u,'n,'t,'f,@d(1),@d(1.1),@b(123456789123456789123456789123456789),@t(2024-01-21T05:49:07.948Z),@s(a b c d e f g h),@d(1),@d(1.1),@b(123456789123456789123456789123456789),[@d(1),@d(2),@d(3),@d(4),],['u,'n,'t,'f,@d(1),@d(1.1),@b(123456789123456789123456789123456789),@t(2024-01-21T05:49:07.948Z),@s(a b c d e f g h),@d(1),@d(1.1),],]
>
> der(ser(val))
[
undefined,
null,
true,
false,
1,
1.1,
123456789123456789123456789123456789n,
2024-01-21T05:49:07.948Z,
'a b c d e f g h',
1,
1.1,
123456789123456789123456789123456789n,
[ 1, 2, 3, 4 ],
[
undefined,
null,
true,
false,
1,
1.1,
123456789123456789123456789123456789n,
2024-01-21T05:49:07.948Z,
'a b c d e f g h',
1,
1.1
]
]
>
METHODS
APIS
der(String) -> NamedTuple
ser(NamedTuple, treat_ary_as_named_tuple=false, enable_circular_check = false) -> String
LICENSE
- ISC