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.8 to 3.1.9

29

lib/cycle.js

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

(function rez(value) {
return (function rez(value) {

@@ -172,12 +172,19 @@ // The rez function walks recursively through the object looking for $jsan

for (name in value) {
if (name === '$jsan') {
value[name] = value[name][0];
// base case passed raw object
if(typeof value[name] === 'string' && name === '$jsan'){
return utils.restore(value.$jsan, $);
break;
}
if (typeof value[name] === 'object') {
item = value[name];
if (item && typeof item === 'object') {
if (item.$jsan) {
value[name] = utils.restore(item.$jsan, $);
} else {
rez(item);
else {
if (name === '$jsan') {
value[name] = value[name][0];
}
if (typeof value[name] === 'object') {
item = value[name];
if (item && typeof item === 'object') {
if (item.$jsan) {
value[name] = utils.restore(item.$jsan, $);
} else {
rez(item);
}
}

@@ -189,4 +196,4 @@ }

}
return value;
}($));
return $;
};
{
"name": "jsan",
"version": "3.1.8",
"version": "3.1.9",
"description": "handle circular references when stringifying and parsing",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -46,2 +46,26 @@ var assert = require('assert');

it('can handle undefined', function() {
var obj = undefined;
var str = jsan.stringify(obj, null, null, true);
assert.deepEqual(str, '{"$jsan":"u"}');
});
it('can handle NaN', function() {
var obj = NaN;
var str = jsan.stringify(obj, null, null, true);
assert.deepEqual(str, '{"$jsan":"n"}');
});
it('can handle Infinity', function() {
var obj = Infinity;
var str = jsan.stringify(obj, null, null, true);
assert.deepEqual(str, '{"$jsan":"i"}');
});
it('can handle -Infinity', function() {
var obj = -Infinity;
var str = jsan.stringify(obj, null, null, true);
assert.deepEqual(str, '{"$jsan":"y"}');
});
it('can handle nested undefined', function() {
var obj = {

@@ -54,3 +78,3 @@ u: undefined

it('can handle NaN', function() {
it('can handle nested NaN', function() {
var obj = {

@@ -63,3 +87,3 @@ u: NaN

it('can handle Infinity', function() {
it('can handle nested Infinity', function() {
var obj = {

@@ -72,3 +96,3 @@ u: Infinity

it('can handle -Infinity', function() {
it('can handle nested -Infinity', function() {
var obj = {

@@ -187,2 +211,50 @@ u: -Infinity

it('can decode dates', function() {
var str = '{"$jsan":"d1400000000000"}';
var obj = jsan.parse(str);
assert(obj instanceof Date);
});
it('can decode regexes', function() {
str = '{"$jsan":"r,test"}';
var obj = jsan.parse(str);
assert(obj instanceof RegExp )
});
it('can decode functions', function() {
str = '{"$jsan":"ffunction () { /* ... */ }"}';
var obj = jsan.parse(str);
assert(obj instanceof Function);
});
it('can decode undefined', function() {
str = '{"$jsan":"u"}';
var obj = jsan.parse(str);
assert(obj === undefined);
});
it('can decode NaN', function() {
str = '{"$jsan":"n"}';
var obj = jsan.parse(str);
assert(isNaN(obj) && typeof obj === 'number');
});
it('can decode Infinity', function() {
str = '{"$jsan":"i"}';
var obj = jsan.parse(str);
assert(obj === Number.POSITIVE_INFINITY);
});
it('can decode -Infinity', function() {
str = '{"$jsan":"y"}';
var obj = jsan.parse(str);
assert(obj === Number.NEGATIVE_INFINITY);
});
it('can decode errors', function() {
str = '{"$jsan":"e:("}';
var obj = jsan.parse(str);
assert(obj instanceof Error && obj.message === ':(');
});
it('can decode nested dates', function() {
var str = '{"now":{"$jsan":"d1400000000000"}}';

@@ -193,3 +265,3 @@ var obj = jsan.parse(str);

it('can decode regexes', function() {
it('can decode nested regexes', function() {
str = '{"r":{"$jsan":"r,test"}}';

@@ -200,3 +272,3 @@ var obj = jsan.parse(str);

it('can decode functions', function() {
it('can decode nested functions', function() {
str = '{"f":{"$jsan":"ffunction () { /* ... */ }"}}';

@@ -207,3 +279,3 @@ var obj = jsan.parse(str);

it('can decode undefined', function() {
it('can decode nested undefined', function() {
str = '{"u":{"$jsan":"u"}}';

@@ -214,3 +286,3 @@ var obj = jsan.parse(str);

it('can decode NaN', function() {
it('can decode nested NaN', function() {
str = '{"u":{"$jsan":"n"}}';

@@ -221,3 +293,3 @@ var obj = jsan.parse(str);

it('can decode Infinity', function() {
it('can decode nested Infinity', function() {
str = '{"u":{"$jsan":"i"}}';

@@ -228,3 +300,3 @@ var obj = jsan.parse(str);

it('can decode -Infinity', function() {
it('can decode nested -Infinity', function() {
str = '{"u":{"$jsan":"y"}}';

@@ -235,3 +307,3 @@ var obj = jsan.parse(str);

it('can decode errors', function() {
it('can decode nested errors', function() {
str = '{"e":{"$jsan":"e:("}}';

@@ -238,0 +310,0 @@ var obj = jsan.parse(str);

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