0.0.1 • Published 8 years ago

@joegesualdo/strip-keys-with-empty-values v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 years ago

@joegesualdo/strip-keys-with-empty-values Build Status

Strip an object's keys with empty values. Supports nested objects.

Install

$ npm install --save @joegesualdo/strip-keys-with-empty-values

Usage

import stripKeysWithEmptyValues from "@joegesualdo/strip-keys-with-empty-values"

let obj = {
  name: 'joe',
  age: '',
  job: {
    title: 'cool',
    hours: ''
  }
}

stripKeysWithEmptyValues(obj, true)
//=> {
//     name: 'joe',
//     job: {
//       title: 'cool'
//     }
//   }

API

stripKeysWithEmptyValues(obj, nested)

Strips the keys with empty values. Support nested objects.

NameTypeDescription
objObjectThe object you want to strip
nestedBooleanShould the keys of nested objects be stripped?

Returns: Object, that represents the obj provided but with the empty keys stripped.

import stripKeysWithEmptyValues from "@joegesualdo/strip-keys-with-empty-values"

let obj = {
  name: 'joe',
  age: '',
  job: {
    title: 'cool',
    hours: ''
  }
}

stripKeysWithEmptyValues(obj, true)
//=> {
//     name: 'joe',
//     job: {
//       title: 'cool'
//     }
//   }

Test

$ npm test

Build

$ npm run build

License

MIT © Joe Gesualdo