As of June 2024, the npm registry hosts over 2 million packages, making it one of the largest open-source software repositories in the world.
Cumulative downloads
Total Downloads
Last day
-1.7%
29,843
Compared to previous day
Last week
1.8%
165,803
Compared to previous week
Last month
0.1%
680,864
Compared to previous month
Last year
0%
5,061,728
Compared to previous year
1
7
Stringify JS values
npm install --save seroval
yarn add seroval
pnpm add seroval
import { serialize } from 'seroval'; const object = { number: [Math.random(), -0, NaN, Infinity, -Infinity], string: ['hello world', '<script>Hello World</script>'], boolean: [true, false], null: null, undefined: undefined, bigint: 9007199254740991n, array: [,,,], // holes regexp: /[a-z0-9]+/i, date: new Date(), map: new Map([['hello', 'world']]), set: new Set(['hello', 'world']), }; // self cyclic references // recursive objects object.self = object; // recursive arrays object.array.push(object.array); // recursive maps object.map.set('self', object.map); // recursive sets object.set.add(object.set); // mutual cyclic references object.array.push(object.map); object.map.set('mutual', object.set); object.set.add(object.array); const result = 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:void 0,bigint:9007199254740991n,array:h=[,,,,k=(j=[],new Map([["hello","world"],["mutual",m=new Set(["hello","world"])]]))],regexp:/[a-z0-9]+/i,date:new Date("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: void 0, bigint: 9007199254740991n, array: (h = [ , , , , (k = ((j = []), new Map([ ["hello", "world"], ["mutual", (m = new Set(["hello", "world"]))], ]))), ]), regexp: /[a-z0-9]+/i, date: new Date("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
Score
Last Scanned on
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More