I wrote the function below to return all keys in an object that match a specific pattern. It seems really round-about because there's no filter function in lodash for objects, when you use it all keys are lost. Is this the only way to filter an objects keys using lodash?
export function keysThatMatch (pattern) {
return (data) => {
let x = _.chain(data)
.mapValues((value, key) => {
return [{
key: key,
value: value
}]
})
.values()
.filter(data => {
return data[0].key.match(pattern)
})
.zipWith(data => {
let tmp = {}
tmp[data[0].key] = data[0].value
return tmp
})
.value()
return _.extend.apply(null, x)
}
}