Skip to content

Instantly share code, notes, and snippets.

@morficus
Created December 30, 2018 01:30
Show Gist options
  • Select an option

  • Save morficus/aa372e6bdfd90f99b1e5a9f214537046 to your computer and use it in GitHub Desktop.

Select an option

Save morficus/aa372e6bdfd90f99b1e5a9f214537046 to your computer and use it in GitHub Desktop.
Returns an object with non-empty attribute values
import isEmpty from 'lodash/isEmpty'
import isNumber from 'lodash/isNumber'
/**
* Returns an object with non-empty attribute values
* @param {Object} targetObject Any object
*/
export default function(targetObject) {
const cleanObject = {}
Object.keys(targetObject).forEach(key => {
const current = targetObject[key]
if (!isEmpty(current) || isNumber(current)) {
cleanObject[key] = current
}
})
return cleanObject
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment