npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

deep-empty

0.1.5 • Public • Published

deep-empty Build Status

This method does a depth first removal of "empty" values ( [], {}, '') from collections (arrays & objects).

For example, it will return an empty object for the following:

require('deep-empty')({ key : [ '', { foo: {}, bar: [] } ] })      => {}

It will return [false] for the following:

require('deep-empty')([[], false, {}])                             => [ false ]

The method can optionally be customized in two ways.

  1. You can pass in the values to keep when iterating over a collection.
  2. You can pass in the things that should not be considered a collection to iterate over.
deepEmpty(object[, toKeep[, toSkip]])

The defaults for the two methods above are:

function toKeep(value) {
    return  (_.isDate(value) || _.isFunction(value)) ||     // all dates and functions are kept
            (!_.isObject(value) && !_.isString(value)) ||   // all things that are not object or string are kep
            !_.isEmpty(value);                              // only non empty strings and objects are kept
}

function toSkip(value) {
    return !_.isObject(value) || _.isDate(value) || _.isFunction(value);
}

Keywords

none

install

npm i deep-empty

Downloadsweekly downloads

1

version

0.1.5

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability