Skip to content

Commit 5f92740

Browse files
committed
emptyなvalueのkeyを除外する関数を追加
1 parent 0a21d89 commit 5f92740

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/utils/remove.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import _ from 'lodash'
2+
3+
export const removeEmpty = (obj) => {
4+
return _.transform(obj, function (result, value, key) {
5+
if (!_.isEmpty(value) || _.isBoolean(value)) {
6+
if (typeof value === 'object') {
7+
result[key] = removeEmpty(value)
8+
} else {
9+
result[key] = value
10+
}
11+
} else if (_.isArray(value)) {
12+
result[key] = []
13+
}
14+
})
15+
}

0 commit comments

Comments
 (0)