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) {
|
2019-08-03 13:49:37 -07:00
|
|
|
for (const key of keys) {
|
2018-12-23 10:10:16 -08:00
|
|
|
if (obj && key in obj) {
|
|
|
|
obj = obj[key]
|
|
|
|
} else {
|
|
|
|
return defaultValue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
|
|
|
|
export function pickBy (obj, predicate) {
|
2019-08-03 13:49:37 -07:00
|
|
|
const res = {}
|
|
|
|
for (const [key, value] of Object.entries(obj)) {
|
2018-12-23 10:10:16 -08:00
|
|
|
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
|
|
|
|
}
|