Narnia's Poofy Meatcleaver
npm’s 2019 JavaScript ecosystem survey analysis is now available!Get your copy here »

clean-deep

2.0.2 • Public • Published

clean-deep

Removes empty objects, arrays, empty strings, null and undefined values from objects. Does not alter the original object.

Status

npm version build status

Installation

Install the package via npm:

$ npm install clean-deep --save

Usage

Arguments

  1. object (Object): The source object.
  2. [options] (Object): An optional object with the following options:
Option Default value Description
emptyArrays true Remove empty arrays, ie: []
emptyObjects true Remove empty objects, ie: {}
emptyStrings true Remove empty strings, ie: ''
nullValues true Remove null values, ie: null
undefinedValues true Remove null values, ie: undefined

(Object): Returns the cleansed object.

Example

const cleanDeep = require('clean-deep');
const object = {
  bar: {},
  baz: null,
  biz: 'baz',
  foo: '',
  net: [],
  nit: undefined,
  qux: {
    baz: 'boz',
    txi: ''
  }
};
 
cleanDeep(object);
// => { biz: 'baz', qux: { baz: 'boz' } }

Tests

$ npm test

Release

npm version [<newversion> | major | minor | patch] -m "Release %s"

License

MIT

Install

npm i clean-deep

DownloadsWeekly Downloads

49,566

Version

2.0.2

License

MIT

Last publish

Collaborators

  • avatar
  • avatar
  • avatar