UNPKG

ice.fo.utils

Version:

27 lines (23 loc) 773 B
import _get from 'lodash/get' export function get (o, key, defaultV) { const result = _get(o, key, defaultV) return result != null ? result : defaultV } export function getValue (o, defaultValue = '', path = '') { if (path) { const paths = path.split('.') return _get(o, paths.concat('value')) || _get(o, paths) || defaultValue } else if (!o) { return defaultValue } else { return (o.value !== undefined ? o.value : Object.keys(o).length ? o : null) || defaultValue } } export function getLabel (o, defaultValue = '', path = '') { if (path) { const paths = path.split('.') return _get(o, paths.concat('label')) || _get(o, paths) || defaultValue } else { return (o && o.label !== undefined ? o.label : o) || defaultValue } }