Socket
Book a DemoInstallSign in
Socket

deep-empty

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deep-empty

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

0.1.5
latest
Source
npmnpm
Version published
Weekly downloads
2
100%
Maintainers
1
Weekly downloads
 
Created
Source

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.

  • You can pass in the values to keep when iterating over a collection.
  • 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);
}

FAQs

Package last updated on 21 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.