1.4.0 • Published 8 months ago

tiny-clean-object v1.4.0

Weekly downloads
15
License
MIT
Repository
github
Last release
8 months ago

tiny-clean-object

NPM version NPM monthly download

A tiny and fast utility to clean deep object

Installation

npm install tiny-clean-object

Example:

import {cleanObject} from 'tiny-clean-object';

const object = {
  a: 'ok',
  b: 123,
  c: null,
  d: undefined,
  e: NaN,
  f: Infinity,
  g: {
    deep: 'ok',
    deep2: {
      obj: {},
      arr: [],
      empty: '',
    },
    deep3: null,
    deep4: NaN,
  },
  h: [],
  i: {},
  k: '',
};

cleanObject(object, {deep: true, emptyObjects: true});

Result

{
  "a": "ok",
  "b": 123,
  "g": {
    "deep": "ok",
    "deep2": {
      "arr": []
    }
  },
  "h": []
}

Options

OptionDefault valueDescription
deepfalseRecursive. Clean deep object
skipNullfalseSkip keys with null as the value
emptyStringstrueRemove empty strings, ie: ''
emptyInvalidNumberstrueRemove NaN and Infinity
emptyArraysfalseRemove empty arrays, ie: []
emptyObjectsfalseRemove empty objects, ie: {}

License

MIT

1.4.0

8 months ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.0

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.1

4 years ago