Comparing version 0.1.3 to 0.1.4
@@ -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}; |
{ | ||
"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"], |
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
8700
239