Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

clean-deep

nunofgs1.1mMIT3.4.0TypeScript support: included

Remove falsy, empty or nullable values from objects

clean, clean-deep, deep

readme

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

changelog

Changelog

v3.4.0 (2020-08-19)

v3.3.0 (2020-02-11)

v3.2.0 (2019-12-04)

v3.1.0 (2019-10-15)

v3.0.5 (2019-09-10)

v3.0.4 (2019-08-27)

v3.0.3 (2019-08-27)

v3.0.2 (2019-08-27)

v3.0.1 (2017-07-18)

v3.0.0 (2017-04-26)

v2.0.2 (2017-03-09)

  • Update dist to es5 to keep uglifyjs compatibility #20 (akofman)

v2.0.1 (2016-11-02)

  • Fix recursive array cleaning #17 (zeke)
  • Upgrade babel-eslint to avoid 'estraverse-fb' error #18 (callmevlad)

v2.0.0 (2016-10-02)

v1.0.0 (2016-09-09)

  • Add transform-es2015-arrow-functions babel plugin #2 (ruipenso)