Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | 1x 1x 1x 1x 25x 38x 17x 38x 2x 36x 1x 35x 2x 33x 1x 32x 3x 29x 3x 26x | /** * Module dependencies. */ const isEmpty = require('lodash.isempty'); const isPlainObject = require('lodash.isplainobject'); const transform = require('lodash.transform'); /** * Export `cleanDeep` function. */ module.exports = function cleanDeep(object, { emptyArrays = true, emptyObjects = true, emptyStrings = true, nullValues = true, undefinedValues = true } = {}) { return transform(object, (result, value, key) => { // Recurse into arrays and objects. if (Array.isArray(value) || isPlainObject(value)) { value = cleanDeep(value, { emptyArrays, emptyObjects, emptyStrings, nullValues, undefinedValues }); } // Exclude empty objects. if (emptyObjects && isPlainObject(value) && isEmpty(value)) { return; } // Exclude empty arrays. if (emptyArrays && Array.isArray(value) && !value.length) { return; } // Exclude empty strings. if (emptyStrings && value === '') { return; } // Exclude null values. if (nullValues && value === null) { return; } // Exclude undefined values. if (undefinedValues && value === undefined) { return; } // Append when recursing arrays. if (Array.isArray(result)) { return result.push(value); } result[key] = value; }); } |