pinafore/src/routes/_utils/lodash-lite.js

31 lines
627 B
JavaScript
Raw Normal View History

// 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) {
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)) {
if (predicate(value, key)) {
res[key] = value
}
}
return res
}
export function padStart (string, length, chars) {
while (string.length < length) {
string = chars + string
}
return string
}