clean-deep
Remove falsy, empty or nullable values from objects
Last updated 4 years ago by nunofgs .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install clean-deep 
SYNC missed versions from official npm registry.

clean-deep

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

As of version 3.0.0, clean-deep traverses arrays as well as objects.

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
cleanKeys [] Remove specific keys, ie: ['foo', 'bar', ' ']
cleanValues [] Remove specific values, ie: ['foo', 'bar', ' ']
emptyArrays true Remove empty arrays, ie: []
emptyObjects true Remove empty objects, ie: {}
emptyStrings true Remove empty strings, ie: ''
NaNValues false Remove NaN values, ie: NaN
nullValues true Remove null values, ie: null
undefinedValues true Remove undefined 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

Current Tags

  • 3.4.0                                ...           latest (4 years ago)

15 Versions

  • 3.4.0                                ...           4 years ago
  • 3.3.0                                ...           5 years ago
  • 3.2.0                                ...           5 years ago
  • 3.1.0                                ...           5 years ago
  • 3.0.5                                ...           5 years ago
  • 3.0.4                                ...           5 years ago
  • 3.0.3                                ...           5 years ago
  • 3.0.2                                ...           7 years ago
  • 3.0.1                                ...           7 years ago
  • 3.0.0                                ...           8 years ago
  • 2.0.2                                ...           8 years ago
  • 2.0.1                                ...           8 years ago
  • 2.0.0                                ...           8 years ago
  • 1.0.0                                ...           8 years ago
  • 0.0.1                                ...           9 years ago
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (6)
Dependents (0)
None

© 2010 - cnpmjs.org x YWFE | Home | YWFE