@akashalib/without-empty-values
TypeScript icon, indicating that this package has built-in type declarations

0.6.1 • Public • Published

@akashalib/without-empty-values

Helper function to return undefined instead of null, empty string, empty array or object with empty values. It also emits undefined elements from an array and does all these things recursively.

Install

npm install @akashalib/without-empty-values
# OR
yarn add @akashalib/without-empty-values

Usage

import { withoutEmptyValues } from "@akashalib/without-empty-values";

console.log(withoutEmptyValues(undefined)); // undefined

console.log(withoutEmptyValues(null)); // undefined

console.log(withoutEmptyValues("")); // undefined

console.log(withoutEmptyValues({})); // undefined

console.log(withoutEmptyValues([])); // undefined

console.log(withoutEmptyValues([1, null, "a", ""])); // [1, "a"]

console.log(
  withoutEmptyValues({
    a: null,
    b: "",
    c: { ca: [null, 1, "", undefined] },
    d: []
  })
); // {c: { ca: [1]} }

console.log(
  withoutEmptyValues({
    a: null,
    b: "",
    c: { ca: [null, "", undefined] },
    d: []
  })
); // undefined

Package Sidebar

Install

npm i @akashalib/without-empty-values

Weekly Downloads

9

Version

0.6.1

License

ISC

Unpacked Size

4.84 kB

Total Files

6

Last publish

Collaborators

  • 2rajpx