Skip to content

An optimised way to remove any prop value (eg. undefined, empty objects, ...) from an object. A small and simple integration

License

Notifications You must be signed in to change notification settings

mesqueeb/remove-anything

Repository files navigation

Remove Anything ✂️

Total Downloads Latest Stable Version

npm i remove-anything

Removes props (eg. undefined) from an object

An optimised way to remove any prop value (eg. undefined, empty objects, ...) from an object. A small and simple integration.

Usage

import { removeProp } from 'remove-anything'

const payload = { a: 1, b: undefined }
const noUndefined = removeProp(payload, undefined)

noUndefined // { a: 1 }

const payload = { a: 1, b: undefined }
const no1 = removeProp(payload, 1)

no1 // { b: undefined }

Remove multiple props

You can keep on passing parameters to remove additional props

const payload = { a: 1, b: undefined }
removeProp(payload, 1, undefined)

// returns
// {}

Remove Empty Objects and Arrays

const payload = { a: 1, b: undefined, c: {}, d: [] }
removeProps(payload, {}, [])

// returns
// { a: 1, b: undefined }

Meet the family (more tiny utils with TS support)

About

An optimised way to remove any prop value (eg. undefined, empty objects, ...) from an object. A small and simple integration

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published