vuikit
Version:
A Vuejs component library based on UIkit
26 lines (21 loc) • 539 B
JavaScript
/**
* Vuikit 0.7.0
* (c) 2018 Miljan Aleksic
* @license MIT
*/
import { isObject, isString } from 'vuikit/core/util'
/**
* Gets the Object value at specific `path`. If the resolved value is
* `undefined`, the `defVal` is returned in its place.
*/
export default function (obj, path, defVal) {
var result = isObject(obj) && isString(path)
? get(obj, path)
: undefined
return result === undefined
? defVal
: result
}
function get (obj, path) {
return path.split('.').reduce((acc, val) => acc && acc[val], obj)
}