0.5.3 • Published 2 years ago

js-serialize v0.5.3

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

js-serialize

Like JSON.stringify, but supports more types.

Installation

yarn add js-serialize
npm i js-serialize -S

Examples

> jsSerialize = require('js-serialize')
{ [Function: jsSerialize] raw: [Function: raw] }

> jsSerialize('foo')
'"foo"'

> jsSerialize(1)
'1'

> jsSerialize([2,3])
'[2,3]'

> jsSerialize(new Set([4,5]))
'new Set([4,5])'

> jsSerialize(new Map([["a",1],["b",2]]))
'new Map([["a",1],["b",2]])'

> jsSerialize(Symbol.for('bar'))
'Symbol.for("bar")'

> jsSerialize([true,false,null,undefined])
'[true,false,null,undefined]'

> jsSerialize(new Array(4))
'new Array(4)'

> jsSerialize([undefined,undefined])
'[undefined,undefined]'

> jsSerialize([,,5,,])
'[,,5,,]'

> jsSerialize(isNaN)
'isNaN'

> jsSerialize(Math.sin)
'Math.sin'

> jsSerialize({a:1,b:{2:3}})
'{a:1,b:{"2":3}}'

> jsSerialize({a:1,b:jsSerialize.raw('() => { console.log("arbitrary"); }')})
'{a:1,b:() => { console.log("arbitrary"); }}'

> jsSerialize(function quux(){})
'function quux(){}'

> jsSerialize(x => x*2)
'x => x*2'

> jsSerialize(() => '</script>')
'() => \'<\\/script>\''

> s=new Set
Set(0) {}
> s.add(s)
<ref *1> Set(1) { [Circular *1] }
> jsSerialize(s)
'($0=>($0=new Set,$0.add($0)))()'

> jsSerialize(["hello world", "hello long string", "hello world", "hello long string"])
'($0=>["hello world",$0="hello long string","hello world",$0])()'
0.5.3

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.12

5 years ago

0.1.11

6 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago