2018-12-23 10:10:16 -08:00
|
|
|
// Some functions from Lodash that are a bit heavyweight and which
|
|
|
|
// we can just do in idiomatic ES2015+
|
|
|
|
|
|
|
|
export function get (obj, keys, defaultValue) {
|
|
|
|
for (let key of keys) {
|
|
|
|
if (obj && key in obj) {
|
|
|
|
obj = obj[key]
|
|
|
|
} else {
|
|
|
|
return defaultValue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
|
|
|
|
export function pickBy (obj, predicate) {
|
|
|
|
let res = {}
|
|
|
|
for (let [key, value] of Object.entries(obj)) {
|
|
|
|
if (predicate(value, key)) {
|
|
|
|
res[key] = value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
2019-03-03 17:21:22 -08:00
|
|
|
|
|
|
|
export function padStart (string, length, chars) {
|
|
|
|
while (string.length < length) {
|
|
|
|
string = chars + string
|
|
|
|
}
|
|
|
|
return string
|
|
|
|
}
|