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

fast-safe-stringify

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-safe-stringify - npm Package Compare versions

Comparing version 1.1.11 to 1.1.12

7

index.js
module.exports = stringify
stringify.default = stringify
function stringify (obj) {
if (obj && typeof obj.toJSON === 'function') {
obj = obj.toJSON()
if (typeof obj === 'object' && typeof obj.toJSON !== 'function') {
decirc(obj, '', [], null)
}
decirc(obj, '', [], null)
return JSON.stringify(obj)

@@ -30,2 +29,4 @@ }

return
} else if (typeof val.toJSON === 'function') {
return
} else if (parent) {

@@ -32,0 +33,0 @@ if (~stack.indexOf(val)) {

{
"name": "fast-safe-stringify",
"version": "1.1.11",
"version": "1.1.12",
"description": "Safely and quickly serialize JavaScript objects",

@@ -16,4 +16,4 @@ "main": "index.js",

"json-stringify-safe": "^5.0.1",
"standard": "^8.0.0",
"tap": "^9.0.0"
"standard": "^9.0.0",
"tap": "^10.0.0"
},

@@ -20,0 +20,0 @@ "repository": {

@@ -156,1 +156,32 @@ var test = require('tap').test

})
test('child circular reference with toJSON', function (assert) {
// Create a test object that has an overriden `toJSON` property
TestObject.prototype.toJSON = function () { return { special: 'case' } }
function TestObject (content) {}
// Creating a simple circular object structure
const parentObject = {}
parentObject.childObject = new TestObject()
parentObject.childObject.parentObject = parentObject
// Creating a simple circular object structure
const otherParentObject = new TestObject()
otherParentObject.otherChildObject = {}
otherParentObject.otherChildObject.otherParentObject = otherParentObject
// Making sure our original tests work
assert.deepEqual(parentObject.childObject.parentObject, parentObject)
assert.deepEqual(otherParentObject.otherChildObject.otherParentObject, otherParentObject)
// Should both be idempotent
assert.equal(fss(parentObject), '{"childObject":{"special":"case"}}')
assert.equal(fss(otherParentObject), '{"special":"case"}')
// Therefore the following assertion should be `true`
assert.deepEqual(parentObject.childObject.parentObject, parentObject)
assert.deepEqual(otherParentObject.otherChildObject.otherParentObject, otherParentObject)
assert.end()
})

Sorry, the diff of this file is not supported yet

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