Comparing version 3.1.12 to 3.1.13
@@ -31,3 +31,4 @@ var pathGetter = require('./path-getter'); | ||
var hasCircular = Object.prototype.hasOwnProperty.call(options, 'circular'); | ||
var noCircularOption = !Object.prototype.hasOwnProperty.call(options, 'circular'); | ||
var withRefs = options.refs !== false; | ||
@@ -108,11 +109,17 @@ return (function derez(_value, path, key) { | ||
if (typeof value === 'object' && options['refs']) { | ||
if (typeof value === 'object') { | ||
var foundPath = map.get(value); | ||
if (foundPath) { | ||
if (hasCircular && path.indexOf(foundPath) === 0) { | ||
return typeof options.circular === 'function'? | ||
if (noCircularOption && withRefs) { | ||
return {$jsan: foundPath}; | ||
} | ||
if (path.indexOf(foundPath) === 0) { | ||
if (!noCircularOption) { | ||
return typeof options.circular === 'function'? | ||
options.circular(value, path, foundPath): | ||
options.circular; | ||
} | ||
return {$jsan: foundPath}; | ||
} | ||
return {$jsan: foundPath}; | ||
if (withRefs) return {$jsan: foundPath}; | ||
} | ||
@@ -119,0 +126,0 @@ map.set(value, path); |
@@ -30,3 +30,2 @@ var cycle = require('./cycle'); | ||
} | ||
if (typeof options.refs === 'undefined') options.refs = true; | ||
@@ -33,0 +32,0 @@ var decycled = cycle.decycle(value, options, replacer); |
{ | ||
"name": "jsan", | ||
"version": "3.1.12", | ||
"version": "3.1.13", | ||
"description": "handle circular references when stringifying and parsing", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -202,2 +202,12 @@ var assert = require('assert'); | ||
it('works with refs option with circular references', function() { | ||
var obj = {}; | ||
obj.self = obj; | ||
obj.a = 1; | ||
obj.b = {t: 1}; | ||
obj.c = obj.b; | ||
assert.equal(jsan.stringify(obj, null, null, {refs: false}), '{"self":{"$jsan":"$"},"a":1,"b":{"t":1},"c":{"t":1}}'); | ||
assert.equal(jsan.stringify(obj, null, null, {refs: false, circular: 'Circular'}), '{"self":"Circular","a":1,"b":{"t":1},"c":{"t":1}}'); | ||
}); | ||
it('works on objects with "[", "\'", and "]" in the keys', function() { | ||
@@ -204,0 +214,0 @@ var obj = {}; |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
41065
884
0