Skip to content

Remove falsy, empty or nullable values from objects

License

Notifications You must be signed in to change notification settings

Pikachews/clean-deep

This branch is 3 commits ahead of nunofgs/clean-deep:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

16bdc7b · Jun 6, 2021

History

71 Commits
Aug 27, 2019
Jun 6, 2021
Aug 19, 2020
Aug 27, 2019
Aug 27, 2019
Jun 6, 2021
Jun 6, 2021
Jul 18, 2017
Aug 19, 2020
Jun 6, 2021
Aug 19, 2020
Jun 6, 2021

Repository files navigation

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

About

Remove falsy, empty or nullable values from objects

Resources

License

Stars

Watchers

Forks

Languages

  • JavaScript 100.0%