Comparing version 3.1.7 to 3.1.8
@@ -55,2 +55,9 @@ var pathGetter = require('./path-getter'); | ||
} | ||
if (options['nan'] && typeof value === 'number' && isNaN(value)) { | ||
return {$jsan: 'n'} | ||
} | ||
if (options['infinity']) { | ||
if (Number.POSITIVE_INFINITY === value) return {$jsan: 'i'} | ||
if (Number.NEGATIVE_INFINITY === value) return {$jsan: 'y'} | ||
} | ||
if (options['undefined'] && value === undefined) { | ||
@@ -57,0 +64,0 @@ return {$jsan: 'u'} |
@@ -25,3 +25,5 @@ var cycle = require('./cycle'); | ||
'map': options, | ||
'set': options | ||
'set': options, | ||
'nan': options, | ||
'infinity': options | ||
} | ||
@@ -28,0 +30,0 @@ } |
@@ -54,2 +54,8 @@ var pathGetter = require('./path-getter'); | ||
return new Set(jsan.parse(rest)); | ||
case 'n': | ||
return NaN; | ||
case 'i': | ||
return Infinity; | ||
case 'y': | ||
return -Infinity; | ||
default: | ||
@@ -56,0 +62,0 @@ console.warn('unknown type', obj); |
{ | ||
"name": "jsan", | ||
"version": "3.1.7", | ||
"version": "3.1.8", | ||
"description": "handle circular references when stringifying and parsing", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -53,2 +53,26 @@ var assert = require('assert'); | ||
it('can handle NaN', function() { | ||
var obj = { | ||
u: NaN | ||
} | ||
var str = jsan.stringify(obj, null, null, true); | ||
assert.deepEqual(str, '{"u":{"$jsan":"n"}}'); | ||
}); | ||
it('can handle Infinity', function() { | ||
var obj = { | ||
u: Infinity | ||
} | ||
var str = jsan.stringify(obj, null, null, true); | ||
assert.deepEqual(str, '{"u":{"$jsan":"i"}}'); | ||
}); | ||
it('can handle -Infinity', function() { | ||
var obj = { | ||
u: -Infinity | ||
} | ||
var str = jsan.stringify(obj, null, null, true); | ||
assert.deepEqual(str, '{"u":{"$jsan":"y"}}'); | ||
}); | ||
it('can handle errors', function() { | ||
@@ -183,2 +207,20 @@ var obj = { | ||
it('can decode NaN', function() { | ||
str = '{"u":{"$jsan":"n"}}'; | ||
var obj = jsan.parse(str); | ||
assert('u' in obj && isNaN(obj.u) && typeof obj.u === 'number'); | ||
}); | ||
it('can decode Infinity', function() { | ||
str = '{"u":{"$jsan":"i"}}'; | ||
var obj = jsan.parse(str); | ||
assert('u' in obj && obj.u === Number.POSITIVE_INFINITY); | ||
}); | ||
it('can decode -Infinity', function() { | ||
str = '{"u":{"$jsan":"y"}}'; | ||
var obj = jsan.parse(str); | ||
assert('u' in obj && obj.u === Number.NEGATIVE_INFINITY); | ||
}); | ||
it('can decode errors', function() { | ||
@@ -185,0 +227,0 @@ str = '{"e":{"$jsan":"e:("}}'; |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
34211
736
0