New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reject-empty

Omit empty values of an array|object


Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created

rejectEmpty(sth <array|object>, omitZero <Boolean>)

npm version npm download build

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 0 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 0
    ),
    [true, 1, 'hello', { a: 1 }, [2]]
  )
})

test('omit empty values except 0 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 0
    ),
    { g: true, h: 'hello', i: { a: 1 }, j: [2] }
  )
})

Test & Coverage

npm test & npm run cov

FAQs

Package last updated on 12 Apr 2017

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