https://github.com/mike1pol/omit-empty
Omit emptry arrays, objects and strings
https://github.com/mike1pol/omit-empty
js omit omit-js omitempty vanilla-javascript
Last synced: about 1 month ago
JSON representation
Omit emptry arrays, objects and strings
- Host: GitHub
- URL: https://github.com/mike1pol/omit-empty
- Owner: mike1pol
- License: mit
- Created: 2017-10-19T13:25:38.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-22T18:52:39.000Z (over 8 years ago)
- Last Synced: 2025-10-04T07:53:53.800Z (8 months ago)
- Topics: js, omit, omit-js, omitempty, vanilla-javascript
- Language: JavaScript
- Size: 6.84 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# omit-empty
[](https://www.npmjs.com/package/@mikepol/omit-empty) [](https://npmjs.org/package/@mikepol/omit-empty) [](https://travis-ci.org/mike1pol/omit-empty)
Recursively omit empty properties from an object. Omits empty objects, arrays, strings or zero.
## Install
```npm i -s @mikepol/omit-empty```
## Usage
```
import omitEmpty from '@mikepol/omit-empty';
omitEmpty({a: 'a', b: ''});
//=> {a: 'a'}
omitEmpty({a: 'a', b: {c: 'c', d: ''}});
//=> {a: 'a', b: {c: 'c'}
omitEmpty({a: ['a'], b: []});
//=> {a: ['a']}
omitEmpty({a: 0, b: 1});
//=> {a: 0, b: 1}
omitEmpty({a: null, b: ''});
//=> null
```
## Tests
```npm install && npm test```