https://github.com/kenberkeley/reject-empty
Omit empty values of an array | object
https://github.com/kenberkeley/reject-empty
clear delete empty filter omit pick reject remove value
Last synced: 3 months ago
JSON representation
Omit empty values of an array | object
- Host: GitHub
- URL: https://github.com/kenberkeley/reject-empty
- Owner: kenberkeley
- Created: 2017-04-12T03:39:33.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-12T03:56:13.000Z (about 8 years ago)
- Last Synced: 2025-02-15T03:12:20.900Z (4 months ago)
- Topics: clear, delete, empty, filter, omit, pick, reject, remove, value
- Language: JavaScript
- Size: 3.91 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rejectEmpty(sth ``, omitZero ``)
[![npm version][npm-v-img]][npm-url]
[![npm download][npm-dl-img]][npm-url]
[![build][build-img]][build-url]> Omit empty values of an array | object
### Installation
`npm i reject-empty -S`
### Usage
> Let's take a look at the test examples```
test('omit empty values except zero of an array', t => {
t.deepEqual(
rejectEmpty(
[0, '0', undefined, null, NaN, false, '', true, 1, 'hello', { a: 1 }, [2]]
),
[0, '0', true, 1, 'hello', { a: 1 }, [2]]
)
})test('omit empty values of an array', t => {
t.deepEqual(
rejectEmpty(
[0, '0', undefined, null, NaN, false, '', true, 1, 'hello', { a: 1 }, [2]],
true // omit zero
),
[true, 1, 'hello', { a: 1 }, [2]]
)
})test('omit empty values except zero of an object', t => {
t.deepEqual(
rejectEmpty(
{ a: 0, b: undefined, c: null, d: NaN, e: false, f: '', g: true, h: 'hello', i: { a: 1 }, j: [2] }
),
{ a: 0, g: true, h: 'hello', i: { a: 1 }, j: [2] }
)
})test('omit empty values of an object', t => {
t.deepEqual(
rejectEmpty(
{ a: '0', b: undefined, c: null, d: NaN, e: false, f: '', g: true, h: 'hello', i: { a: 1 }, j: [2] },
true // omit zero
),
{ g: true, h: 'hello', i: { a: 1 }, j: [2] }
)
})
```### Test & Coverage
`npm test` & `npm run cov`
[npm-url]: https://www.npmjs.com/package/reject-empty
[npm-v-img]: http://img.shields.io/npm/v/reject-empty.svg
[npm-dl-img]: http://img.shields.io/npm/dm/reject-empty.svg
[build-img]: https://travis-ci.org/kenberkeley/reject-empty.svg?branch=master
[build-url]: https://travis-ci.org/kenberkeley/reject-empty