Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9
lxsmnsyc/seroval
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Stringify JS values
npm install --save seroval
yarn add seroval
pnpm add seroval
import{serialize}from'seroval';constobject={number:[Math.random(),-0,NaN,Infinity,-Infinity],string:['hello world','<script>Hello World</script>'],boolean:[true,false],null:null,undefined:undefined,bigint:9007199254740991n,array:[,,,],// holesregexp:/[a-z0-9]+/i,date:newDate(),map:newMap([['hello','world']]),set:newSet(['hello','world']),};// self cyclic references// recursive objectsobject.self=object;// recursive arraysobject.array.push(object.array);// recursive mapsobject.map.set('self',object.map);// recursive setsobject.set.add(object.set);// mutual cyclic referencesobject.array.push(object.map);object.map.set('mutual',object.set);object.set.add(object.array);constresult=serialize(object);console.log(result);
Output (as a string):
((h,j,k,m,o)=>(o={number:[0.5337763749243287,-0,0/0,1/0,-1/0],string:["hello world","\x3Cscript>Hello World\x3C/script>"],boolean:[!0,!1],null:null,undefined:void0,bigint:9007199254740991n,array:h=[,,,,k=(j=[],newMap([["hello","world"],["mutual",m=newSet(["hello","world"])]]))],regexp:/[a-z0-9]+/i,date:newDate("2023-12-07T17:28:57.909Z"),map:k,set:m},h[3]=h,k.set("self",k),m.add(m).add(h),o.self=o,o))()// Formatted for readability((h,j,k,m,o)=>((o={number:[0.5337763749243287,-0,0/0,1/0,-1/0],string:["hello world","\x3Cscript>Hello World\x3C/script>"],boolean:[!0,!1],null:null,undefined:void0,bigint:9007199254740991n,array:(h=[,,,,(k=((j=[]),newMap([["hello","world"],["mutual",(m=newSet(["hello","world"]))],]))),]),regexp:/[a-z0-9]+/i,date:newDate("2023-12-07T17:28:57.909Z"),map:k,set:m,}),(h[3]=h),k.set("self",k),m.add(m).add(h),(o.self=o),o))();
MIT ©lxsmnsyc
About
Stringify JS values
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
No packages published