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

json-dry

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-dry - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

79

lib/json-dry.js

@@ -51,12 +51,15 @@ /**

function generateReplacer(value, replacer) {
function generateReplacer(rootValue, replacer) {
var
path = [],
seen = [value],
seen = [rootValue],
mapp = [specialChar],
isObject = (typeof value === 'object'),
isObject = (typeof rootValue === 'object'),
chain = [],
i
;
var prevchild = 0;
return function(key, value) {
return function DryReplacer(key, value) {

@@ -71,3 +74,3 @@ var valType;

valType = typeof value
valType = typeof value;

@@ -78,5 +81,24 @@ // did you know ? Safari passes keys as integers for arrays

if (valType === 'object' && value) {
if (chain.length) {
// See if the current is actually a property of the current
// active item in the chain
if (chain[chain.length-1][key] !== value) {
// If it's not, the current active item is probably done
chain.pop();
// Se we should also remove it from the path
path.pop();
}
}
// Push the current object to the chain
chain.push(value);
i = indexOf.call(seen, value);
if (i < 0) {
// Store the object in the seen array and return the index
i = seen.push(value) - 1;

@@ -90,2 +112,3 @@

path.push(('' + key).replace(specialCharRG, safeSpecialChar));
mapp[i] = specialChar + path.join(specialChar);

@@ -95,2 +118,3 @@ } else {

}
} else {

@@ -211,4 +235,49 @@ path.pop();

/**
* Determine if an object is empty or not.
* Only own properties are valid.
*
* @author Jelle De Loecker <jelle@codedor.be>
* @since 0.1.4
* @version 0.1.4
*/
function isEmptyObject(val) {
var key;
// Go over the keys in this object
for (key in val) {
// As soon as we encounter a key in this value that actually
// belongs to the object itself, we return false,
// because it's not empty
if (Object.hasOwnProperty.call(val, key)) {
return false;
}
}
return true;
}
/**
* Determine if an object is empty or not,
* with a special check for arrays
*
* @author Jelle De Loecker <jelle@codedor.be>
* @since 0.1.4
* @version 0.1.4
*/
function isEmpty(val) {
if (Array.isArray(val)) {
return !val.length;
}
return isEmptyObject(val);
}
this.stringify = stringifyRecursion;
this.parse = parseRecursion;
this.isEmptyObject = isEmptyObject;
this.isEmpty = isEmpty;

@@ -215,0 +284,0 @@ this.info = {path: false};

2

package.json
{
"name": "json-dry",
"description": "JSON generator & parser with circular, date and regex support",
"version": "0.1.3",
"version": "0.1.4",
"author": "Jelle De Loecker <jelle@codedor.be>",

@@ -6,0 +6,0 @@ "keywords": ["json", "circular", "serialization", "deserialization"],

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