avoid cyclic issues

Signed-off-by: Travis Glenn Hansen <travisghansen@yahoo.com>
This commit is contained in:
Travis Glenn Hansen
2022-03-05 09:11:54 -07:00
parent b723136f2a
commit a18f8ad8b7
2 changed files with 20 additions and 1 deletions
+18
View File
@@ -51,6 +51,24 @@ function getLargestNumber() {
return number;
}
function stringify(value) {
const getCircularReplacer = () => {
const seen = new WeakSet();
return (key, value) => {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
return;
}
seen.add(value);
}
return value;
};
};
return JSON.stringify(value, getCircularReplacer());
}
module.exports.sleep = sleep;
module.exports.lockKeysFromRequest = lockKeysFromRequest;
module.exports.getLargestNumber = getLargestNumber;
module.exports.stringify = stringify;