0.2.1 • Published 7 years ago
node-stringify v0.2.1
node-stringify
Stringify javascript objects and retrieve with eval
.
Important notes
This library IS NOT designed to replace JSON.stringify
. Unless you truly understand what this library does, I suggest you use JSON.stringify
in the first place.
Install
npm install node-stringify --save
Example
var stringify = require('node-stringify');
console.assert(stringify(123) === '123');
console.assert(stringify('abc') === '\'abc\'');
console.assert(stringify(null) === 'null');
console.assert(stringify(undefined) === 'undefined');
console.assert(stringify(new Date(1000)) === 'new Date(1000)');
console.assert(stringify(function (a,b,c) {}) === '(function (a,b,c) {})');
console.assert(stringify([1, 2, 3]) === '[1,2,3]');
// The parenthesis is to make the result work with `eval`
console.assert(stringify({a: 1, b: 2}) === '({a:1,b:2})');
console.assert(stringify({a: 1, b: [2, 3]}) === '({a:1,b:[2,3]})');
// You can turn off the parenthesis too
console.assert(stringify({a: 1, b: 2}, {parenthesis:false}) === '{a:1,b:2}');
console.assert(stringify({a: 1, b: [2, 3]}, {parenthesis:false}) === '{a:1,b:[2,3]}');
Supported types
- null
- undefined
- number
- string
- date
- regexp
- function
- array
- object
Difference with JSON.stringify
- The result of
node-stringify
can be retrieved directly usingeval
(Please be aware thateval
may be insecure).
Known issues
- Not support objects with circular references or too deeply nested(implemented in a recursive way).
License
MIT License.
0.2.1
7 years ago
0.2.0
7 years ago
0.0.19
8 years ago
0.0.18
10 years ago
0.0.16
10 years ago
0.0.15
10 years ago
0.0.14
10 years ago
0.0.13
10 years ago
0.0.12
10 years ago
0.0.11
10 years ago
0.0.10
10 years ago
0.0.9
10 years ago
0.0.8
10 years ago
0.0.7
10 years ago
0.0.6
10 years ago
0.0.5
10 years ago
0.0.4
10 years ago
0.0.3
10 years ago
0.0.2
10 years ago
0.0.1
10 years ago