Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Stringify JS values

License

NotificationsYou must be signed in to change notification settings

lxsmnsyc/seroval

Repository files navigation

Stringify JS values

NPMJavaScript Style Guide

Install

npm install --save seroval
yarn add seroval
pnpm add seroval

Usage

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))();

Docs

Sponsors

Sponsors

License

MIT ©lxsmnsyc

About

Stringify JS values

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp