MCPcopy Create free account
hub / github.com/DanWahlin/CustomerManagerStandard / __toJSONSafe

Function __toJSONSafe

CustomerManager/Scripts/breeze.debug.js:209–243  ·  view source on GitHub ↗
(obj, replacer)

Source from the content-addressed store, hash-verified

207
208 // safely perform toJSON logic on objects with cycles.
209 function __toJSONSafe(obj, replacer) {
210 if (obj !== Object(obj)) return obj; // primitive value
211 if (obj._$visited) return undefined;
212 if (obj.toJSON) {
213 var newObj = obj.toJSON();
214 if (newObj !== Object(newObj)) return newObj; // primitive value
215 if (newObj !== obj) return __toJSONSafe(newObj);
216 // toJSON returned the object unchanged.
217 obj = newObj;
218 }
219 obj._$visited = true;
220 var result;
221 if (obj instanceof Array) {
222 result = obj.map(function (o) {
223 return __toJSONSafe(o, replacer);
224 });
225 } else if (typeof (obj) === "function") {
226 result = undefined;
227 } else {
228 result = {};
229 for (var prop in obj) {
230 if (prop === "_$visited") continue;
231 var val = obj[prop];
232 if (replacer) {
233 val = replacer(prop, val);
234 if (val === undefined) continue;
235 }
236 val = __toJSONSafe(val);
237 if (val === undefined) continue;
238 result[prop] = val;
239 }
240 }
241 delete obj._$visited;
242 return result;
243 }
244
245 // resolves the values of a list of properties by checking each property in multiple sources until a value is found.
246 function __resolveProperties(sources, propertyNames) {

Callers 2

structuralObjectToJsonFunction · 0.85
unwrapInstanceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected