Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break circular dependencies #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions taffy.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var TAFFY, exports, T;
isIndexable, returnFilter, runFilters,
numcharsplit, orderByCol, run, intersection,
filter, makeCid, safeForJson,
isRegexp, sortArgs
isRegexp, sortArgs, safeForJsonRecursive
;


Expand Down Expand Up @@ -90,12 +90,22 @@ var TAFFY, exports, T;
isRegexp = function(aObj) {
return Object.prototype.toString.call(aObj)==='[object RegExp]';
}

safeForJson = function(aObj) {
return safeForJsonRecursive(aObj, []);
}

safeForJsonRecursive = function(aObj, aPrevious) {
for (var i in aPrevious) {
if (aPrevious[i]===aObj) {
return null;
}
}
aPrevious.push(aObj);
var myResult = T.isArray(aObj) ? [] : T.isObject(aObj) ? {} : null;
if(aObj===null) return aObj;
for(var i in aObj) {
myResult[i] = isRegexp(aObj[i]) ? aObj[i].toString() : T.isArray(aObj[i]) || T.isObject(aObj[i]) ? safeForJson(aObj[i]) : aObj[i];
myResult[i] = isRegexp(aObj[i]) ? aObj[i].toString() : T.isArray(aObj[i]) || T.isObject(aObj[i]) ? safeForJsonRecursive(aObj[i], aPrevious) : aObj[i];
}
return myResult;
}
Expand Down