Comparing version 3.1.9 to 3.1.10
@@ -87,3 +87,8 @@ var pathGetter = require('./path-getter'); | ||
if (value && typeof value.toJSON === 'function') { | ||
value = value.toJSON(key); | ||
try { | ||
value = value.toJSON(key); | ||
} catch (error) { | ||
var keyString = (key || '$'); | ||
return "toJSON failed for '" + (map.get(value) || keyString) + "'"; | ||
} | ||
} | ||
@@ -90,0 +95,0 @@ |
var cycle = require('./cycle'); | ||
exports.stringify = function stringify(value, replacer, space, _options) { | ||
if (arguments.length < 4) { | ||
try { | ||
if (arguments.length === 1) { | ||
return JSON.stringify(value); | ||
} else { | ||
return JSON.stringify.apply(JSON, arguments); | ||
} | ||
} catch (e) {} | ||
} | ||
var options = _options || false; | ||
@@ -32,8 +21,3 @@ if (typeof options === 'boolean') { | ||
var decycled = cycle.decycle(value, options, replacer); | ||
if (arguments.length === 1) { | ||
return JSON.stringify(decycled); | ||
} else { | ||
return JSON.stringify(decycled, replacer, space); | ||
} | ||
return JSON.stringify(decycled); | ||
} | ||
@@ -43,12 +27,10 @@ | ||
var needsRetrocycle = /"\$jsan"/.test(text); | ||
var parsed; | ||
if (arguments.length === 1) { | ||
parsed = JSON.parse(text); | ||
} else { | ||
parsed = JSON.parse(text, reviver); | ||
var replaced = JSON.parse(text); | ||
var resolved = cycle.retrocycle(replaced); | ||
if(reviver) { | ||
var temp = JSON.stringify(resolved); | ||
var parsed = JSON.parse(temp, reviver); | ||
return parsed; | ||
} | ||
if (needsRetrocycle) { | ||
parsed = cycle.retrocycle(parsed); | ||
} | ||
return parsed; | ||
return resolved; | ||
} |
{ | ||
"name": "jsan", | ||
"version": "3.1.9", | ||
"version": "3.1.10", | ||
"description": "handle circular references when stringifying and parsing", | ||
@@ -18,7 +18,8 @@ "main": "index.js", | ||
"circular-json": "^0.3.0", | ||
"immutable": "^3.7.6", | ||
"immutable": "^3.8.2", | ||
"json-stringify-safe": "^5.0.1", | ||
"mobx": "^2.4.1", | ||
"mocha": "^2.2.1", | ||
"rimraf": "^2.5.2" | ||
"rimraf": "^2.5.2", | ||
"remotedev-serialize": "^0.1.1" | ||
}, | ||
@@ -25,0 +26,0 @@ "dependencies": {}, |
@@ -39,3 +39,3 @@ var assert = require('assert'); | ||
var obj = { | ||
f: function() {} | ||
f: function () {} | ||
} | ||
@@ -133,3 +133,3 @@ var str = jsan.stringify(obj, null, null, true); | ||
['a', 1], | ||
[{toString: function(){ return 'a' }}, 2], | ||
[{toString: function (){ return 'a' }}, 2], | ||
[{}, 3] | ||
@@ -146,3 +146,3 @@ ]) | ||
var obj = { | ||
set: new Set(['a', {toString: function(){ return 'a' }}, {}]) | ||
set: new Set(['a', {toString: function (){ return 'a' }}, {}]) | ||
} | ||
@@ -149,0 +149,0 @@ var str = jsan.stringify(obj, null, null, true); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50755
20
1216
8