1.0.0 • Published 1 month ago

empty-deep v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

EmptyDeep

Removes empty values from arrays and deeply nested objects, with configurable "emptiness" criteria. Completely empty input values ([], '', etc.) are returned as undefined.

Installation

npm install -s empty-deep

Usage

import { emptyDeep } from 'empty-deep';

console.log(emptyDeep({}));                 // undefined
console.log(emptyDeep({ key: undefined })); // undefined
console.log(emptyDeep(null));               // undefined
console.log(emptyDeep([1, 2, []]));         // [1, 2]

const myObject = {
  title: null,
  subject: '',
  body: 'Todat at lunch...',
  meta: {
    tags: ['tag1', 'tag2', ''],
  },
  authors: [{}]
}

console.log(emptyDeep(myObject));

/**
 * output:
 * 
 * {
 *   body: 'Today at lunch...',
 *   meta: ['tag1', 'tag2']
 * }
 */
1.0.0

1 month ago