1.0.3 • Published 10 months ago

nv-random-pson v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

nv-random-pson

  • generate a random JSON, whose string-lelement could be directly using '"' + str + '"' when do JSON.stringify
  • nvlang support a subset-of-json called pson

pson

    pson string  must can be directly quote when do stringify AND NOT include 4-bytes UTF8
    pson number's absolute value  must between [0.000001,1e+21)  
         // to avoid using  scientific notation 
         // scientific notation  IS hard to understand , its boring 
  • this pkg is for test pson, normally USELESS

install

  • npm install nv-random-pson

usage

         const x = require("nv-random-pson")    

example

	var [top,stats] = x.creat();


	/*
	> stats
	Cnt {
	  A: 52334,
	  D: 52408,
	  S: 104650,
	  N: 36314,
	  t: 6591,
	  f: 6594,
	  n: 3253,
	  c: 262144
	}
	> 

	> JSON.stringify(top).length
	2107341
	> 
	*/

	var [top,stats] = x.creat({max_total_cnt:2000000})

	/*
	> stats
	Cnt {
	  A: 399911,
	  D: 400321,
	  S: 799148,
	  N: 275418,
	  t: 49863,
	  f: 50631,
	  n: 24708,
	  c: 2000000
	}
	> JSON.stringify(top).length
	16105843
	> 
	*/

	/*
	> x.get_max_str_sz()
	128
	*/
	x.set_max_str_sz(8); // for creat very big json, the string must be small , else OOM crash

	var [top,stats] = x.creat({max_total_cnt:10000000})
	/*
	this will cost a long time (because random generate string element is very slow) 10s- 20s

	> stats
	Cnt {
	  A: 2000882,
	  D: 2000581,
	  S: 3998414,
	  N: 1375380,
	  t: 249586,
	  f: 250188,
	  n: 124969,
	  c: 10000000
	}
	> JSON.stringify(top).length   // generate a about 80M nested json 
	80497556 
	> 

	use it to test if your JSON.stringify fast enough

	*/

METHODS

APIS

LICENSE

  • ISC
1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago