New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

obj-clean

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

obj-clean

Remove empty objects, empty strings, null and undefined values from objects

latest
Source
npmnpm
Version
3.0.1
Version published
Maintainers
1
Created
Source

obj-clean Build Status

Remove empty objects, empty arrays, empty strings, null and undefined values from objects.

Install

$ npm install --save obj-clean

Usage

const clean = require('obj-clean');

clean({foo: ''});
//=> {}

clean({foo: 'bar', baz: undefined});
//=> {foo: 'bar'}

clean({foo: {bar: 'baz', baz: null, bax: false}});
//=> {foo: {bar: 'baz', bax: false}}

clean({foo: {bar: 'baz', baz: {}});
//=> {foo: {bar: 'baz'}}

clean({foo: 'bar', baz: []});
//=> {foo: 'bar', baz: []}

clean({foo: [{unicorn: ''}]});
//=> {foo: []}

clean({foo: [{unicorn: '', rainbow: '🌈'}]});
//=> {foo: [{rainbow: '🌈'}]}

clean({foo: [{unicorn: ''}]}, {cleanArrays: false});
//=> {foo: [{unicorn: ''}]}

clean({foo: [{unicorn: ''}]}, {preserveArrays: false});
//=> {}

API

clean(obj, [options])

Returns a clean object.

obj

Type: Object

The object to clean up.

options

preserveArrays

Type: boolean
Default: true

Set to false if you want to remove empty arrays.

cleanArrays

Type: boolean
Default: true

Set to false if you don't want to iterate over arrays and clean all the objects inside the array.

License

MIT © Sam Verschueren

Keywords

object

FAQs

Package last updated on 22 May 2019

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