Skip to content

Commit d42f23f

Browse files
committed
Make flattenNames more readable
1 parent 13bc8cb commit d42f23f

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

src/flattenNames.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import _ from 'lodash'
22

3-
export const flattenNames = (things) => {
3+
export const flattenNames = (things = []) => {
44
const names = []
55

6-
things.map((thing) => {
7-
Array.isArray(thing) && flattenNames(thing).map(name => names.push(name))
8-
_.isPlainObject(thing) && _.forOwn(thing, (value, key) => {
9-
value === true && names.push(key)
10-
names.push(`${ key }-${ value }`)
11-
})
12-
_.isString(thing) && names.push(thing)
13-
return thing
6+
_.map(things, (thing) => {
7+
if (Array.isArray(thing)) {
8+
flattenNames(thing).map(name => names.push(name))
9+
} else if (_.isPlainObject(thing)) {
10+
_.forOwn(thing, (value, key) => {
11+
value === true && names.push(key)
12+
names.push(`${ key }-${ value }`)
13+
})
14+
} else if (_.isString(thing)) {
15+
names.push(thing)
16+
}
1417
})
1518

1619
return names

0 commit comments

Comments
 (0)