omit-deep-2

Deep omitting with support for predicate functions, and arrays

Usage no npm install needed!

<script type="module">
  import omitDeep2 from 'https://cdn.skypack.dev/omit-deep-2';
</script>

README

omit-deep-2

Build Status Coverage Status npm version

npm

Omit object values recursively by key / keys / predicate

Installation

npm install --save omit-deep-2

Usage

// For purposes of this example, assume that this object 
// is reinitialized before each omitDeep call
var obj = {
    a: 1,
    b: 2,
    c: {
        d: 3,
        e: 4
    }
};

// With key
omitDeep(obj, 'a'); 
// returns { b: 2, c: { d: 3, e: 4 } }

// With multiple keys
omitDeep(obj, ['a', 'b'], ['d'], 'e'); 
// returns { c: {} }

// Recursively
omitDeep(obj, 'a', 'd'); 
// returns { b: 2, c: { e: 4 } }

// With predicate function
omitDeep(obj, (key, val) => typeof val === 'object' || key === 'b'); 
// returns { a: 1 }