@vue-interface/utils
Version:
A utility package for Vue Interface.
15 lines (12 loc) • 462 B
JavaScript
import isArray from './isArray';
import isNull from './isNull';
import isString from './isString';
import isUndefined from './isUndefined';
export default function get(object, path, defaultValue) {
const value = (isString(path) ? path.split('.') : (
!isArray(path) ? [path] : path)
).reduce((a, b) => a[b], object);
return !isUndefined(value) && !isNull(value) ? value : (
!isUndefined(defaultValue) ? defaultValue : value
);
}