blob: 1073f8045fccdb9f17112e984ab8f782e6b46da2 [file] [log] [blame]
module.exports = stripFunctions;
/*
* Returns a copy of the input with its functions stripped out.
* Array entries would be set to null. Object entries are unset.
* The functions are stripped deeply, also purging from nested objects/arrays.
*/
function stripFunctions(data) {
if (typeof data === 'function') {
return null;
} else if (typeof data === 'object') {
// JSON.parse + stringify deeply purges function properties in objects.
return JSON.parse(JSON.stringify(data));
}
return data; // primitive type
}