MCPcopy Create free account
hub / github.com/Famous/engine / strip

Function strip

utilities/strip.js:42–62  ·  view source on GitHub ↗

* Removes all non-primitive values from a (nested) object. * * Used for makeing arbitrary objects serializable through the structured * cloning algorithm used by `postMessage`. * * Supported primitives: `null`, `undefined`, `Boolean`, `Number`, `String` * * @method strip * * @param {*} obj

(obj)

Source from the content-addressed store, hash-verified

40 * primitive types (serializable).
41 */
42function strip(obj) {
43 switch (obj) {
44 case null:
45 case undefined:
46 return obj;
47 }
48 switch (obj.constructor) {
49 case Boolean:
50 case Number:
51 case String:
52 return obj;
53 case Object:
54 for (var key in obj) {
55 var stripped = strip(obj[key], true);
56 obj[key] = stripped;
57 }
58 return obj;
59 default:
60 return null;
61 }
62}
63
64module.exports = strip;

Callers 1

strip.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected