json-dry
Advanced tools
Comparing version 0.1.5 to 0.1.6
@@ -52,11 +52,19 @@ /** | ||
function generateReplacer(rootValue, replacer) { | ||
var | ||
path = [], | ||
seen = [rootValue], | ||
mapp = [specialChar], | ||
isObject = (typeof rootValue === 'object'), | ||
chain = [], | ||
i | ||
; | ||
var path = [], | ||
seen = [rootValue], // Registry of ALL objects | ||
mapp = [specialChar], // The main map to use | ||
seens = {}, // Registry of objects per constructor | ||
seensmapp = {}, // Map of seens to seen id | ||
isObject = (typeof rootValue === 'object'), | ||
chain = [], | ||
i; | ||
if (typeof rootValue == 'object') { | ||
seens[rootValue.constructor.name] = [rootValue]; | ||
seensmapp[rootValue.constructor.name] = [0]; | ||
} | ||
var prevchild = 0; | ||
@@ -66,4 +74,4 @@ | ||
var valType; | ||
var valType, j, nameType; | ||
// the replacer has rights to decide | ||
@@ -82,2 +90,10 @@ // if a new object should be returned | ||
// Get the constructor name | ||
nameType = value.constructor.name; | ||
if (!seens[nameType]) { | ||
seens[nameType] = []; | ||
seensmapp[nameType] = []; | ||
} | ||
if (chain.length) { | ||
@@ -98,5 +114,6 @@ // See if the current is actually a property of the current | ||
chain.push(value); | ||
// See if this object has been seen before | ||
i = seens[nameType].indexOf(value); | ||
i = indexOf.call(seen, value); | ||
if (i < 0) { | ||
@@ -106,2 +123,4 @@ | ||
i = seen.push(value) - 1; | ||
j = seens[nameType].push(value); | ||
seensmapp[nameType][j] = i; | ||
@@ -117,3 +136,3 @@ if (value.constructor.name == 'RegExp') { | ||
} else { | ||
value = mapp[i]; | ||
value = mapp[seensmapp[nameType][j]]; | ||
} | ||
@@ -142,2 +161,3 @@ | ||
} | ||
return value; | ||
@@ -144,0 +164,0 @@ }; |
{ | ||
"name": "json-dry", | ||
"description": "JSON generator & parser with circular, date and regex support", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"author": "Jelle De Loecker <jelle@codedor.be>", | ||
@@ -6,0 +6,0 @@ "keywords": ["json", "circular", "serialization", "deserialization"], |
9511
263