Created
December 30, 2018 01:30
-
-
Save morficus/aa372e6bdfd90f99b1e5a9f214537046 to your computer and use it in GitHub Desktop.
Returns an object with non-empty attribute values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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