nv-buf-data-to-code
v0.0.6
Published
nv-buf-data-to-code ======================= - convert a js\_value to js\_code - support most js\_value, but NOT include: function, class, lambda, generator, iterator, promise, weakmap,weakset,weakref-if-deref-failed, native-func - for generate coding-
Downloads
1
Readme
nv-buf-data-to-code
convert a js_value to js_code
support most js_value, but NOT include: function, class, lambda, generator, iterator, promise, weakmap,weakset,weakref-if-deref-failed, native-func
for generate coding-template AND fast-copy FIXED-DATA
this is used for collecting data IN your application, AND then insert the generated code to a DATABASE
IF you collected enough, you can use them to creat FIXED-SHAPE-FILE
install
- npm install nv-buf-data-to-code
usage
nodejs cp ./DIST/nd.js
const {to_code,to_script) = require("./DIST/nd.js");
to_code(any_js_value,indent=" ") -> string;
to_script(any_js_value,write_to_file_name,indent=" ") -> void
/*
> to_script(d,"circular")
dict_1_1686161646339.js
module.exports = ()=>{
let dict_1 = {};
let ary_2 = [];
ary_2.push(dict_1);
ary_2.push(-1);
ary_2.push(1);
ary_2.push(1.1);
ary_2.push(1n);
ary_2.push("string");
let st_8 = new Set();
st_8.add(undefined);
st_8.add(null);
st_8.add(true);
st_8.add(false);
st_8.add(dict_1);
st_8.add(ary_2);
ary_2["attr1"] = st_8;
let mp_13 = new Map();
mp_13.set(dict_1,ary_2);
mp_13.set(ary_2,dict_1);
mp_13.set(st_8,mp_13);
mp_13.set(mp_13,st_8);
ary_2["attr2"] = mp_13;
dict_1["ary"] = ary_2;
return(dict_1);
}
TEST# ls -l | egrep dict
-rw-r--r-- 1 root root 570 Jun 7 18:14 dict_1_1686161646339.js
TEST#
> x=require("./dict_1_1686161646339.js")()
<ref *1> {
ary: <ref *2> [
[Circular *1],
-1,
1,
1.1,
1n,
'string',
attr1: Set(6) {
undefined,
null,
true,
false,
[Circular *1],
[Circular *2]
},
attr2: <ref *3> Map(4) {
[Circular *1] => [Circular *2],
[Circular *2] => [Circular *1],
[Set] => [Circular *3],
[Circular *3] => [Set]
}
]
}
>
*/
browser cp ./DIST/bw.js global-name is nv_buf_data_to_code
const {to_code,to_script) = window.nv_buf_data_to_code;
to_code(any_js_value,name,indent=" ") -> string;
to_script(any_js_value,name,indent=" ") -> [window_name,creat_func]
//this will insert a <script> to window, the prop-name is window_name, the content is creat_func
// use window[window_name]() OR creat_func();
/*
nv_buf_data_to_code.to_script(d,"my_data");
/*
['dict_1_1686162848224', undefined]
var dupe = window.dict_1_1686162848224()
*/
*/
IF the browser tell you : Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment.
SO you CANT use .to_script JUST use .to_code AND manual eval("("+code+")") TO test it
for test
const _creat = require("nv-buf-data-to-code");
var code = _creat(<js_value>)[1]
console.log(code)
example
empty-slot-ary-expr-element
> var a = [,,1,,]
> a
[ <2 empty items>, 1, <1 empty item> ]
>
> _creat(a)
[
'ary_1',
'\n' +
'()=>{\n' +
' let ary_1 = [];\n' +
' ary_1.length =4;\n' +
' ary_1[2] =1;\n' +
' return(ary_1);\n' +
'}\n' +
' '
]
> console.log(x(a)[1])
()=>{
let ary_1 = [];
ary_1.length =4;
ary_1[2] =1;
return(ary_1);
}
> var f = ()=>{
... let ary_1 = [];
... ary_1.length =4;
... ary_1[2] =1;
... return(ary_1);
... }
> f()
[ <2 empty items>, 1, <1 empty item> ]
>
>
circular
const eq = require("assert").deepStrictEqual;
const _creat = require("nv-buf-data-to-code");
const tst = (v) => {
var code= _creat(v)[1];
console.log(v,":",code);
var f = eval("("+code+")")
eq(f(),v)
}
var d = {}
d.ary = []
var a = d.ary
a[0] = d ;
a.push(-1,1,1.1,1n,"string");
var st = new Set([undefined,null,true,false])
var mp = new Map();
a.attr1 = st;
a.attr2 = mp;
mp.set(d,a)
mp.set(a,d);
mp.set(st,mp);
mp.set(mp,st);
st.add(d);
st.add(a)
tst(d)
/*
<ref *1> {
ary: <ref *2> [
[Circular *1],
-1,
1,
1.1,
1n,
'string',
attr1: Set(6) {
undefined,
null,
true,
false,
[Circular *1],
[Circular *2]
},
attr2: <ref *3> Map(4) {
[Circular *1] => [Circular *2],
[Circular *2] => [Circular *1],
[Set] => [Circular *3],
[Circular *3] => [Set]
}
]
}
*/
//---generated code,
/*
()=>{
let dict_1 = {};
let ary_2 = [];
ary_2.push(dict_1);
ary_2.push(-1);
ary_2.push(1);
ary_2.push(1.1);
ary_2.push(1n);
ary_2.push("string");
let st_8 = new Set();
st_8.add(undefined);
st_8.add(null);
st_8.add(true);
st_8.add(false);
st_8.add(dict_1);
st_8.add(ary_2);
ary_2["attr1"] = st_8;
let mp_13 = new Map();
mp_13.set(dict_1,ary_2);
mp_13.set(ary_2,dict_1);
mp_13.set(st_8,mp_13);
mp_13.set(mp_13,st_8);
ary_2["attr2"] = mp_13;
dict_1["ary"] = ary_2;
return(dict_1);
}
*/
multi array-buffer-view share the-same-array-buffer
const tst = (v) => {
var code= _creat(v)[1];
console.log(v,":",code);
console.log("-----------------------------------------------------")
var f = eval("("+code+")");
var abs = f();
let u8a = new Uint8Array(ab);
for(let nv of abs) {
let nu8a = new Uint8Array(nv.buffer);
if(u8a.length === nu8a.length) {
for(let i=0;i<u8a.length;++i) {
if(u8a[i] !== nu8a[i]) {
throw([i,u8a[i],nu8a[i]])
} else {
}
}
} else {
throw([u8a.length,nu8a.length])
}
}
}
var ab = new ArrayBuffer(100)
var u8a = new Uint8Array(ab,0,2);
u8a[0] = 1
u8a[1] = 2
var u8ca = new Uint8ClampedArray(ab,2,2);
u8ca[0] = 3
u8ca[1] = 4
var i8a = new Int8Array(ab,4,2);
i8a[0] = -1
i8a[1] = -2
var u16a = new Uint16Array(ab,6,2);
u16a[0] = 65534
u16a[1] = 65535
var i16a = new Int16Array(ab,10,3);
i16a[0] = -3
i16a[1] = -4
i16a[2] = 0
var u32a = new Uint32Array(ab,16,2);
u32a[0] = 2**32-2
u32a[1] = 2**32-1
var i32a = new Int32Array(ab,24,2);
i32a[0] = -5
i32a[1] = -6
var u64a = new BigUint64Array(ab,32,2);
u64a[0] = 2n**64n-1n
u64a[1] = 2n**64n-2n
var i64a = new BigInt64Array(ab,48,2);
i64a[0] = -7n
i64a[1] = -8n
var f32a = new Float32Array(ab,64,2);
f32a[0] = 1.1
f32a[1] = -1.1
var f64a = new Float64Array(ab,80,2);
f64a[0] = 2.2
f64a[1] = 2.2
var dv = new DataView(ab,96,4);
dv.setUint32(0,555)
abs = [u8a,u8ca,i8a,u16a,i16a,u32a,i32a,u64a,i64a,f32a,f64a,dv]
/*
[
Uint8Array(2) [ 1, 2 ],
Uint8ClampedArray(2) [ 3, 4 ],
Int8Array(2) [ -1, -2 ],
Uint16Array(2) [ 65534, 65535 ],
Int16Array(3) [ -3, -4, 0 ],
Uint32Array(2) [ 4294967294, 4294967295 ],
Int32Array(2) [ -5, -6 ],
BigUint64Array(2) [ 18446744073709551615n, 18446744073709551614n ],
BigInt64Array(2) [ -7n, -8n ],
Float32Array(2) [ 1.100000023841858, -1.100000023841858 ],
Float64Array(2) [ 2.2, 2.2 ],
DataView {
byteLength: 4,
byteOffset: 96,
buffer: ArrayBuffer {
[Uint8Contents]: <01 02 03 04 ff fe fe ff ff ff fd ff fc ff 00 00 fe ff ff ff ff ff ff ff fb ff ff ff fa ff ff ff ff ff ff ff ff ff ff ff fe ff ff ff ff ff ff ff f9 ff ff ff ff ff ff ff f8 ff ff ff ff ff ff ff cd cc 8c 3f cd cc 8c bf 00 00 00 00 00 00 00 00 9a 99 99 99 99 99 01 40 9a 99 99 99 99 99 01 40 00 00 02 2b>,
byteLength: 100
}
}
]
*/
tst(abs);
// will generate code as below :
/*
()=>{
let ary_1 = [];
let ab_2 = new ArrayBuffer(100);
{
let _2_ary_for_fill = [1,2,3,4,255,254,254,255,255,255,253,255,252,255,0,0,254,255,255,255,255,255,255,255,251,255,255,255,250,255,255,255,255,255,255,255,255,255,255,255,254,255,255,255,255,255,255,255,249,255,255,255,255,255,255,255,248,255,255,255,255,255,255,255,205,204,140,63,205,204,140,191,0,0,0,0,0,0,0,0,154,153,153,153,153,153,1,64,154,153,153,153,153,153,1,64,0,0,2,43];
let _2_u8a_for_fill = new Uint8Array(ab_2);
for(let i=0;i<_2_ary_for_fill.length;++i) {
_2_u8a_for_fill[i] = _2_ary_for_fill[i];
}
}
let u8a_3 = new Uint8Array(ab_2,0,2);
ary_1.push(u8a_3);
let u8ca_4 = new Uint8ClampedArray(ab_2,2,2);
ary_1.push(u8ca_4);
let i8a_5 = new Int8Array(ab_2,4,2);
ary_1.push(i8a_5);
let u16a_6 = new Uint16Array(ab_2,6,2);
ary_1.push(u16a_6);
let i16a_7 = new Int16Array(ab_2,10,3);
ary_1.push(i16a_7);
let u32a_8 = new Uint32Array(ab_2,16,2);
ary_1.push(u32a_8);
let i32a_9 = new Int32Array(ab_2,24,2);
ary_1.push(i32a_9);
let u64a_10 = new BigUint64Array(ab_2,32,2);
ary_1.push(u64a_10);
let i64a_11 = new BigInt64Array(ab_2,48,2);
ary_1.push(i64a_11);
let f32a_12 = new Float32Array(ab_2,64,2);
ary_1.push(f32a_12);
let f64a_13 = new Float64Array(ab_2,80,2);
ary_1.push(f64a_13);
let dv_14 = new DataView(ab_2,96,4);
ary_1.push(dv_14);
return(ary_1);
}
*/
errors
const tst = (v) => {
var code= _creat(v)[1];
console.log(v,":",code);
console.log("-----------------------------------------------------")
var f = eval("("+code+")")
var narr = f();
if(v.length === narr.length) {
for(let i=0;i< v.length;++i) {
let err = v[i];
let nerr = narr[i];
if(
err.message === nerr.message &&
err.stack === nerr.stack &&
(err.cause === nerr.cause) || (JSON.stringify(err.cause) === JSON.stringify(nerr.cause))
) {
} else {
throw(i)
}
}
} else {
throw([v,length,narr.length])
}
}
var evl_err = new EvalError("evl");
var rng_err = new RangeError("rng");
var ref_err = new ReferenceError("ref");
var uri_err = new URIError("uri");
var typ_err = new TypeError("typ");
var agg_errs = new AggregateError([evl_err,rng_err,ref_err,uri_err,typ_err],"agg");
var err = new Error("err",{cause:"cause"});
var errs =[
evl_err,rng_err,ref_err,uri_err,typ_err,agg_errs,err
]
tst(errs)
// will generate code as below :
/*
()=>{
let ary_1 = [];
let evl_err_2 = new EvalError("evl");
{
evl_err_2.stack =
"EvalError: evl" +
" at REPL29:1:15" +
" at Script.runInThisContext (node:vm:122:12)" +
" at REPLServer.defaultEval (node:repl:570:29)" +
" at bound (node:domain:433:15)" +
" at REPLServer.runBound [as eval] (node:domain:444:12)" +
" at REPLServer.onLine (node:repl:900:10)" +
" at REPLServer.emit (node:events:523:35)" +
" at REPLServer.emit (node:domain:489:12)" +
" at [_onLine] [as _onLine] (node:internal/readline/interface:415:12)" +
" at [_line] [as _line] (node:internal/readline/interface:886:18)" +
"";
}
ary_1.push(evl_err_2);
let rng_err_3 = new RangeError("rng");
{
rng_err_3.stack =
"RangeError: rng" +
" at REPL30:1:15" +
" at Script.runInThisContext (node:vm:122:12)" +
" at REPLServer.defaultEval (node:repl:570:29)" +
" at bound (node:domain:433:15)" +
" at REPLServer.runBound [as eval] (node:domain:444:12)" +
" at REPLServer.onLine (node:repl:900:10)" +
" at REPLServer.emit (node:events:523:35)" +
" at REPLServer.emit (node:domain:489:12)" +
" at [_onLine] [as _onLine] (node:internal/readline/interface:415:12)" +
" at [_line] [as _line] (node:internal/readline/interface:886:18)" +
"";
}
ary_1.push(rng_err_3);
let ref_err_4 = new ReferenceError("ref");
{
ref_err_4.stack =
"ReferenceError: ref" +
" at REPL31:1:15" +
" at Script.runInThisContext (node:vm:122:12)" +
" at REPLServer.defaultEval (node:repl:570:29)" +
" at bound (node:domain:433:15)" +
" at REPLServer.runBound [as eval] (node:domain:444:12)" +
" at REPLServer.onLine (node:repl:900:10)" +
" at REPLServer.emit (node:events:523:35)" +
" at REPLServer.emit (node:domain:489:12)" +
" at [_onLine] [as _onLine] (node:internal/readline/interface:415:12)" +
" at [_line] [as _line] (node:internal/readline/interface:886:18)" +
"";
}
ary_1.push(ref_err_4);
let uri_err_5 = new URIError("uri");
{
uri_err_5.stack =
"URIError: uri" +
" at REPL32:1:15" +
" at Script.runInThisContext (node:vm:122:12)" +
" at REPLServer.defaultEval (node:repl:570:29)" +
" at bound (node:domain:433:15)" +
" at REPLServer.runBound [as eval] (node:domain:444:12)" +
" at REPLServer.onLine (node:repl:900:10)" +
" at REPLServer.emit (node:events:523:35)" +
" at REPLServer.emit (node:domain:489:12)" +
" at [_onLine] [as _onLine] (node:internal/readline/interface:415:12)" +
" at [_line] [as _line] (node:internal/readline/interface:886:18)" +
"";
}
ary_1.push(uri_err_5);
let typ_err_6 = new TypeError("typ");
{
typ_err_6.stack =
"TypeError: typ" +
" at REPL33:1:15" +
" at Script.runInThisContext (node:vm:122:12)" +
" at REPLServer.defaultEval (node:repl:570:29)" +
" at bound (node:domain:433:15)" +
" at REPLServer.runBound [as eval] (node:domain:444:12)" +
" at REPLServer.onLine (node:repl:900:10)" +
" at REPLServer.emit (node:events:523:35)" +
" at REPLServer.emit (node:domain:489:12)" +
" at [_onLine] [as _onLine] (node:internal/readline/interface:415:12)" +
" at [_line] [as _line] (node:internal/readline/interface:886:18)" +
"";
}
ary_1.push(typ_err_6);
let ary_7 = [];
ary_7.push(evl_err_2);
ary_7.push(rng_err_3);
ary_7.push(ref_err_4);
ary_7.push(uri_err_5);
ary_7.push(typ_err_6);
let agg_err_8 = new AggregateError(ary_7, "agg");
{
agg_err_8.stack =
"AggregateError: agg" +
" at REPL34:1:16" +
" at Script.runInThisContext (node:vm:122:12)" +
" at REPLServer.defaultEval (node:repl:570:29)" +
" at bound (node:domain:433:15)" +
" at REPLServer.runBound [as eval] (node:domain:444:12)" +
" at REPLServer.onLine (node:repl:900:10)" +
" at REPLServer.emit (node:events:523:35)" +
" at REPLServer.emit (node:domain:489:12)" +
" at [_onLine] [as _onLine] (node:internal/readline/interface:415:12)" +
" at [_line] [as _line] (node:internal/readline/interface:886:18)" +
"";
}
ary_1.push(agg_err_8);
let err_10 = new Error("err", {cause:"cause"});
{
err_10.stack =
"Error: err" +
" at REPL35:1:16" +
" at Script.runInThisContext (node:vm:122:12)" +
" at REPLServer.defaultEval (node:repl:570:29)" +
" at bound (node:domain:433:15)" +
" at REPLServer.runBound [as eval] (node:domain:444:12)" +
" at REPLServer.onLine (node:repl:900:10)" +
" at REPLServer.emit (node:events:523:35)" +
" at REPLServer.emit (node:domain:489:12)" +
" at [_onLine] [as _onLine] (node:internal/readline/interface:415:12)" +
" at [_line] [as _line] (node:internal/readline/interface:886:18)" +
"";
}
ary_1.push(err_10);
return(ary_1);
}
*/
weakref IF can be deref
const eq = require("assert").deepStrictEqual;
const tst = (v) => {
var code= _creat(v)[1];
console.log(v,":",code);
console.log("-----------------------------------------------------")
var f = eval("("+code+")")
eq(f(),v)
}
var a = [];
var wkref =new WeakRef(a)
tst(wkref);
/*
()=>{
let ary_1 = [];
let wkref_ref_can_be_deref_2 = new WeakRef(ary_1);
return(wkref_ref_can_be_deref_2);
}
*/
odds
undefined null true false Infinity NaN -Infinity -0 (this is special)
const eq = require("assert").deepStrictEqual;
const tst = (v) => {
var code= _creat(v)[1];
console.log(v,":",code);
console.log("-----------------------------------------------------")
var f = eval("("+code+")")
eq(f(),v)
}
[-0,undefined,null,true,false,Infinity,-Infinity,NaN].forEach(v=>tst(v))
date
+275760-09-13T00:00:00.000Z :
()=>{
let dt_1 = new Date("+275760-09-13T00:00:00.000Z");
return(dt_1);
}
-----------------------------------------------------
2023-06-07T18:00:44.011Z :
()=>{
let dt_1 = new Date("2023-06-07T18:00:44.011Z");
return(dt_1);
}
-----------------------------------------------------
-271821-04-20T00:00:00.000Z :
()=>{
let dt_1 = new Date("-271821-04-20T00:00:00.000Z");
return(dt_1);
}
regexp
/./ :
()=>{
let rgx_1 = /./;
return(rgx_1);
}
-----------------------------------------------------
/.*/gi :
()=>{
let rgx_1 = /.*/gi;
return(rgx_1);
}
-----------------------------------------------------
literal :
number | string | bigint
const tst = (v) => {
var code= _creat(v)[1];
console.log(v,":",code);
console.log("-----------------------------------------------------")
var f = eval("("+code+")")
eq(f(),v)
}
[
Number.MIN_VALUE, Number.MAX_VALUE,
Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER,
-1, -0, 0, 1,
+Infinity,NaN,-Infinity,
1.1,
////
-1n, 0n, 1n,
2n**64n -1n,
-(2n**64n), 2n**64n,
////
'\b\t\n\\x0b\f\r', 'aÿ我𝑒',
////
].forEach(v=>tst(v))
prim-wrap
const tst = (v) => {
var code= _creat(v)[1];
console.log(v,":",code);
console.log("-----------------------------------------------------")
var f = eval("("+code+")")
eq(f(),v)
}
var truo = new Boolean(true);
var flso = new Boolean(false);
var numos = [
Number.MIN_VALUE, Number.MAX_VALUE,
Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER,
-1, -0, 0, 1,
+Infinity,NaN,-Infinity,
1.1
].map(r=>new Number(r));
var stros = [
'\b\t\n\\x0b\f\r', 'aÿ我𝑒',
].map(r=>new String(r));
var primos = [
truo,
flso,
...numos,
...stros
]
primos.forEach(v=>tst(v))
/*
...
[Number: -0] :
()=>{
let numo_1 = new Number(-0);
return(numo_1);
}
...
*/
symbol this is special IF using Symbol.for
const tst = (v) => {
var code= _creat(v)[1];
console.log(v,":",code);
console.log("-----------------------------------------------------")
var f = eval("("+code+")")
eq(f().description,v.description)
}
var syms = [
Symbol(),
Symbol.for(),
Symbol("sym")
]
syms.map(v=>tst(v));
/*
Symbol() :
()=>{
let sym_1 = Symbol();
return(sym_1);
}
-----------------------------------------------------
Symbol(undefined) :
()=>{
let sym_1 = Symbol("undefined");
return(sym_1);
}
-----------------------------------------------------
Symbol(sym) :
()=>{
let sym_1 = Symbol("sym");
return(sym_1);
}
-----------------------------------------------------
*/
unsupported
other data-type will be convert to a special object(weakref-cant-be-deref IS belong to unsupported)
#!node --expose-gc
const eq = require("assert").deepStrictEqual;
const _creat = require("../index");
const tst = (v) => {
var code= _creat(v)[1];
console.log(v,":",code);
console.log("-----------------------------------------------------")
}
var unsupported = []
var d = {}
const wkmp = new WeakMap();
wkmp.set(d,0);
unsupported.push(wkmp);
const wkst = new WeakSet();
wkst.add(d);
unsupported.push(wkst);
function sfunc() {}
unsupported.push(sfunc);
async function afunc() {}
unsupported.push(afunc);
function * sgen() {}
unsupported.push(sgen);
async function * agen(){}
unsupported.push(agen);
const slmbd = ()=> {}
unsupported.push(slmbd);
const almbd = async()=> {}
unsupported.push(almbd);
const native_code = Reflect.isExtensible;
unsupported.push(native_code);
const wkref = new WeakRef(d);
unsupported.push(wkref);
d= null
gc(); // this is for make wkref's reference: d be released immediately
gc();
tst(unsupported)
/*
[
WeakMap { <items unknown> },
WeakSet { <items unknown> },
[Function: sfunc],
[AsyncFunction: afunc],
[GeneratorFunction: sgen],
[AsyncGeneratorFunction: agen],
[Function: slmbd],
[AsyncFunction: almbd],
[Function: isExtensible],
WeakRef {}
] :
()=>{
let ary_1 = [];
let wkmp_2 = {
___unsupported___:true,
Ctor:"WeakMap",
hint:"\"\"",
str:"\"[object WeakMap]\""
};
ary_1.push(wkmp_2);
let wkst_3 = {
___unsupported___:true,
Ctor:"WeakSet",
hint:"\"\"",
str:"\"[object WeakSet]\""
};
ary_1.push(wkst_3);
let sfunc_4 = {
___unsupported___:true,
Ctor:"Function",
hint:"\"\"",
str:"\"function sfunc() {}\""
};
ary_1.push(sfunc_4);
let almbd_or_amthd_5 = {
___unsupported___:true,
Ctor:"AsyncFunction",
hint:"\"\"",
str:"\"async function afunc() {}\""
};
ary_1.push(almbd_or_amthd_5);
let agen_6 = {
___unsupported___:true,
Ctor:"GeneratorFunction",
hint:"\"\"",
str:"\"function * sgen() {}\""
};
ary_1.push(agen_6);
let agen_7 = {
___unsupported___:true,
Ctor:"AsyncGeneratorFunction",
hint:"\"\"",
str:"\"async function * agen(){}\""
};
ary_1.push(agen_7);
let cls_8 = {
___unsupported___:true,
Ctor:"Function",
hint:"\"maybe_mthd\"",
str:"\"()=> {}\""
};
ary_1.push(cls_8);
let almbd_or_amthd_9 = {
___unsupported___:true,
Ctor:"AsyncFunction",
hint:"maybe_amthd",
str:"\"async()=> {}\""
};
ary_1.push(almbd_or_amthd_9);
let native_code_10 = {
___unsupported___:true,
Ctor:"Function",
hint:"\"\"",
str:"\"function isExtensible() { [native code] }\""
};
ary_1.push(native_code_10);
let dict_11 = {};
let wkref_ref_can_be_deref_12 = new WeakRef(dict_11);
ary_1.push(wkref_ref_can_be_deref_12);
return(ary_1);
}
*/
perf
small circular
var d = {}
d.ary = []
var a = d.ary
a[0] = d ;
a.push(-1,1,1.1,1n,"string");
var st = new Set([undefined,null,true,false])
var mp = new Map();
a.attr1 = st;
a.attr2 = mp;
mp.set(d,a)
mp.set(a,d);
mp.set(st,mp);
mp.set(mp,st);
st.add(d);
st.add(a)
const {to_code,to_script}=require("../DIST/nd.js");
let name = to_script(d);
const load = require("./"+name);
const {sync} = require("nv-facutil-simple-test");
var dupe;
var from_structured_clone = (o)=> {
dupe = structuredClone(o)
}
var from_load = (o) => {
dupe = load(o)
}
const eq = require("assert").deepStrictEqual;
eq(from_structured_clone(d),from_load(d))
console.log(sync(1000000,from_structured_clone,d));
console.log(sync(1000000,from_load,d));
const fs =require("fs")
fs.rmSync(name)
/*
{
rounds: 1000000,
f: [Function: from_structured_clone],
costed: 5622.591341018677
}
{
rounds: 1000000,
f: [Function: from_load],
costed: 416.41017508506775
}
*/
4k-json
TEST# ls -l tst.json
-rw-r--r-- 1 root root 4041 Jun 7 18:41 tst.json
/*
const d = require("./tst.json")
const {to_code,to_script}=require("../DIST/nd.js");
let name = to_script(d);
const load = require("./"+name);
const {sync} = require("nv-facutil-simple-test");
var dupe;
var s = JSON.stringify(d);
var from_json = (o)=> {
dupe = JSON.parse(s)
}
var from_load = (o) => {
dupe = load(o)
}
const eq = require("assert").deepStrictEqual;
eq(from_json(d),from_load(d))
console.log(sync(1000000,from_json,d));
console.log(sync(1000000,from_load,d));
const fs =require("fs")
*/
/* ---- generated code
module.exports = ()=>{
let dict_1 = {};
dict_1["name"] = "nv-buf-data-to-code";
dict_1["lockfileVersion"] = 3;
dict_1["requires"] = true;
let dict_5 = {};
let dict_6 = {};
let dict_7 = {};
dict_7["nv-facutil-istis"] = "^1.0.8";
dict_7["nv-facutil-jswitch"] = "^1.0.10";
dict_7["nv-facutil-ppgflike-is"] = "^1.0.3";
dict_6["dependencies"] = dict_7;
let dict_11 = {};
dict_11["nv-facutil-simple-test"] = "^0.0.13";
dict_6["devDependencies"] = dict_11;
dict_5[""] = dict_6;
let dict_13 = {};
dict_13["version"] = "3.3.6";
dict_13["resolved"] = "https://registry.npmmirror.com/nanoid/-/nanoid-3.3.6.tgz";
dict_13["integrity"] = "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==";
let dict_17 = {};
dict_17["nanoid"] = "bin/nanoid.cjs";
dict_13["bin"] = dict_17;
let dict_19 = {};
dict_19["node"] = "^10 || ^12 || ^13.7 || ^14 || >=15.0.1";
dict_13["engines"] = dict_19;
dict_5["node_modules/nanoid"] = dict_13;
let dict_21 = {};
dict_21["version"] = "1.0.2";
dict_21["resolved"] = "https://registry.npmmirror.com/nv-error-simple-trace/-/nv-error-simple-trace-1.0.2.tgz";
dict_21["integrity"] = "sha512-/jXWrcoyGg3r61lDKmJhKYuDlZbxbqBK4RHwsJfeZ7C/9udL1WqpWyiNiEDbAGa1CzqARELaDB37qGlb4Yyx2Q==";
dict_5["node_modules/nv-error-simple-trace"] = dict_21;
let dict_25 = {};
dict_25["version"] = "1.3.20";
dict_25["resolved"] = "https://registry.npmmirror.com/nv-facutil-basic/-/nv-facutil-basic-1.3.20.tgz";
dict_25["integrity"] = "sha512-eGkAie/avH6ApghzuVApbszkwD8OX9d4u3Vl0pZnm0sV9etwdHn1trAFVTeMzadP9KMANCDI+ICwVY/a/KBKvw==";
dict_25["deprecated"] = "all-test-builtin-features-has-been-implemented-in-nvlang_this-is-useless-now";
let dict_30 = {};
dict_30["nanoid"] = "^3.1.22";
dict_30["nv-facutil-notandor"] = "^1.0.5";
dict_25["dependencies"] = dict_30;
dict_5["node_modules/nv-facutil-basic"] = dict_25;
let dict_33 = {};
dict_33["version"] = "1.0.8";
dict_33["resolved"] = "https://registry.npmjs.org/nv-facutil-istis/-/nv-facutil-istis-1.0.8.tgz";
dict_33["integrity"] = "sha512-/BbL8gW/Bv6KeFG5oL5lhxUntPtnYN6OWEJq5iCe2AQ9S+EeD/ubLEYEkwf8nys0XKdda5LiLBYcFfqL1AByog==";
let dict_37 = {};
dict_37["nv-facutil-simple-test"] = "^0.0.13";
dict_37["nv-facutil-typis"] = "^1.0.3";
dict_33["dependencies"] = dict_37;
dict_5["node_modules/nv-facutil-istis"] = dict_33;
let dict_40 = {};
dict_40["version"] = "1.0.10";
dict_40["resolved"] = "https://registry.npmmirror.com/nv-facutil-jswitch/-/nv-facutil-jswitch-1.0.10.tgz";
dict_40["integrity"] = "sha512-9yhta3e+R6antLtJydh0+LmVsicvfSodi1AWaSHNr9OqmJ8b1ECvZZf83rgfdgFh0XenTViRzs/cT0tVrz0X0w==";
let dict_44 = {};
dict_44["nv-facutil-typis"] = "^1.0.3";
dict_44["nv-facutil-untf"] = "^1.0.2";
dict_40["dependencies"] = dict_44;
dict_5["node_modules/nv-facutil-jswitch"] = dict_40;
let dict_47 = {};
dict_47["version"] = "1.0.5";
dict_47["resolved"] = "https://registry.npmmirror.com/nv-facutil-notandor/-/nv-facutil-notandor-1.0.5.tgz";
dict_47["integrity"] = "sha512-29H+w/g+VecoxPHtcm3ZNrhZgIDbUeoSbo9i/wvNnOWjfC7em0ZKboOJuLpV4WNUb3v+Z01AdKEz/AIJxIOe8Q==";
dict_5["node_modules/nv-facutil-notandor"] = dict_47;
let dict_51 = {};
dict_51["version"] = "1.0.3";
dict_51["resolved"] = "https://registry.npmmirror.com/nv-facutil-ppgflike-is/-/nv-facutil-ppgflike-is-1.0.3.tgz";
dict_51["integrity"] = "sha512-LlqYWxCQvtfsYzPUCO4ALGA8yy0m2jn9b3PF5u4sQzMFIXsfROC0sU+PlpDxcvm/B9EAikoKXsp4yez9mhK/DA==";
let dict_55 = {};
dict_55["nv-facutil-typis"] = "^1.0.5";
dict_55["nv-facutil-untf"] = "^1.0.2";
dict_51["dependencies"] = dict_55;
dict_5["node_modules/nv-facutil-ppgflike-is"] = dict_51;
let dict_58 = {};
dict_58["version"] = "0.0.13";
dict_58["resolved"] = "https://registry.npmjs.org/nv-facutil-simple-test/-/nv-facutil-simple-test-0.0.13.tgz";
dict_58["integrity"] = "sha512-0P/iqMrS7XLv4Od0Gfgur+5lVBUqS1fd4Jea9Bqz3rVunnnVuHvV0cOmSb07rq/RUrAw+iESiF70VJl7vYeV7Q==";
let dict_62 = {};
dict_62["nv-error-simple-trace"] = "^1.0.2";
dict_62["nv-facutil-basic"] = "^1.3.20";
dict_58["dependencies"] = dict_62;
dict_5["node_modules/nv-facutil-simple-test"] = dict_58;
let dict_65 = {};
dict_65["version"] = "1.0.5";
dict_65["resolved"] = "https://registry.npmmirror.com/nv-facutil-typis/-/nv-facutil-typis-1.0.5.tgz";
dict_65["integrity"] = "sha512-fnj+3DrNL7OhCSb5xISAOpf+i/zaJbg1ExCPCXWrtWdryyzY23VcjaRdf8Hl2qlmDQocyDg3x235wCcRyhAy8w==";
dict_5["node_modules/nv-facutil-typis"] = dict_65;
let dict_69 = {};
dict_69["version"] = "1.0.2";
dict_69["resolved"] = "https://registry.npmmirror.com/nv-facutil-untf/-/nv-facutil-untf-1.0.2.tgz";
dict_69["integrity"] = "sha512-gMF6gDLReo/kY4m4SSK7DwJ6ODIYy9WZl0EI6IsIa9czbs1tvOJimJBLNEGJFhsnNVsacf7EGKPrTdPqmclv5Q==";
dict_5["node_modules/nv-facutil-untf"] = dict_69;
dict_1["packages"] = dict_5;
return(dict_1);
}
*/
{ rounds: 1000000, f: [Function: from_json], costed: 10820.6332000494 }
// 3 times faster
{
rounds: 1000000,
f: [Function: from_load],
costed: 323.99007296562195
}
METHODS
APIS
nodejs
to_code (value:Any, indent=" ") : string;
to_script (value:Any, write_to_file_name:string, indent=" ") : void;
browser
to_code (value:Any, name:string, indent=" ") : string;
to_script (value:Any, name:string, indent=" ") : [window_prop_name:string, creat_func:Function] ;
LICENSE
- ISC