Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsan

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsan - npm Package Compare versions

Comparing version 3.1.11 to 3.1.12

.npmignore

2

lib/cycle.js

@@ -107,3 +107,3 @@ var pathGetter = require('./path-getter');

if (typeof value === 'object' && value !== null) {
if (typeof value === 'object' && options['refs']) {
var foundPath = map.get(value);

@@ -110,0 +110,0 @@ if (foundPath) {

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;

@@ -19,2 +30,3 @@ if (typeof options === 'boolean') {

}
if (typeof options.refs === 'undefined') options.refs = true;

@@ -32,10 +44,12 @@ var decycled = cycle.decycle(value, options, replacer);

var needsRetrocycle = /"\$jsan"/.test(text);
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;
var parsed;
if (arguments.length === 1) {
parsed = JSON.parse(text);
} else {
parsed = JSON.parse(text, reviver);
}
return resolved;
if (needsRetrocycle) {
parsed = cycle.retrocycle(parsed);
}
return parsed;
}
{
"name": "jsan",
"version": "3.1.11",
"version": "3.1.12",
"description": "handle circular references when stringifying and parsing",

@@ -18,8 +18,7 @@ "main": "index.js",

"circular-json": "^0.3.0",
"immutable": "^3.8.2",
"immutable": "^3.7.6",
"json-stringify-safe": "^5.0.1",
"mobx": "^2.4.1",
"mocha": "^2.2.1",
"rimraf": "^2.5.2",
"remotedev-serialize": "^0.1.1"
"rimraf": "^2.5.2"
},

@@ -26,0 +25,0 @@ "dependencies": {},

@@ -193,2 +193,11 @@ var assert = require('assert');

it('can use the refs option', function() {
var obj1 = { a: 1 };
var obj = { "prop1": obj1, "prop2": { "prop3": obj1 } };
assert.equal(jsan.stringify(obj, null, null, {refs: true}), '{"prop1":{"a":1},"prop2":{"prop3":{"$jsan":"$.prop1"}}}');
assert.equal(jsan.stringify(obj, null, null, true), '{"prop1":{"a":1},"prop2":{"prop3":{"$jsan":"$.prop1"}}}');
assert.equal(jsan.stringify(obj, null, null, false), '{"prop1":{"a":1},"prop2":{"prop3":{"$jsan":"$.prop1"}}}');
assert.equal(jsan.stringify(obj, null, null, {refs: false}), '{"prop1":{"a":1},"prop2":{"prop3":{"a":1}}}');
});
it('works on objects with "[", "\'", and "]" in the keys', function() {

@@ -232,2 +241,9 @@ var obj = {};

});
it('uses reviver function', function() {
var str = '{"a":1,"b":null}';
assert.deepEqual({"a":1,"b":2},
jsan.parse(str, function (key, value) { return key === "b" ? 2 : value; })
);
});

@@ -240,2 +256,8 @@ it('can decode dates', function() {

it('can decode dates while using reviver', function() {
var str = '{"$jsan":"d1400000000000"}';
var obj = jsan.parse(str, function (key, value) { return value; });
assert(obj instanceof Date);
});
it('can decode regexes', function() {

@@ -242,0 +264,0 @@ str = '{"$jsan":"r,test"}';

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc