@a4sex/params-pruner
TypeScript icon, indicating that this package has built-in type declarations

1.0.10 • Public • Published

Params pruner

A lightweight NPM package that provides a single function, prune, which removes all empty values from an object, including empty strings, null, NaN, and undefined, across all nested levels.Additionally, it preserves boolean fields with a value of false in the pruned object.

This means that boolean fields with a value of false will not be considered empty and will be retained in the pruned object. Only values that fall under the empty criteria (empty strings, null, NaN, and undefined) will be removed.

Usage

To use the prune function, import it into your project. The prune function takes a single parameter, which should be an object. It removes all empty values from the object recursively and returns the pruned object.

import prune from '@a4sex/params-pruner';

let object = {
  value: 1,
  empty: '',
  null: null,
  nan: NaN,
  defined: undefined,
  boolean: false,
  inline: {
    value: 1,
    empty: '',
    null: null,
    nan: NaN,
    defined: undefined,
    boolean: false,
  }
};

const result = prune(object);

console.log(result);
// Output: { 
//   value: 1, 
//   boolean: false,
//   inline: { 
//     value: 1 
//     boolean: false,
//   } 
// }

Readme

Keywords

Package Sidebar

Install

npm i @a4sex/params-pruner

Weekly Downloads

2

Version

1.0.10

License

GPL-3.0-or-later

Unpacked Size

2.63 kB

Total Files

4

Last publish

Collaborators

  • tebaly