Skip to content

kenberkeley/reject-empty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 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

Releases

No releases published

Packages

No packages published