All files / Object getObjVal.js

75% Statements 3/4
58.33% Branches 7/12
100% Functions 2/2
75% Lines 3/4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16    1x     1x             2x      
import { isStr, isArr } from '../Is'
export function getVal(obj, path, defaultValue) {
  Iif (!obj || !(isStr(path) || isArr(path))) {
    return obj
  }
  return (
    (!isArr(path)
      ? path
          .replace(/\[/g, '.')
          .replace(/\]/g, '')
          .split('.')
      : path
    ).reduce((prev, next) => (prev || {})[next], obj) || defaultValue
  )
}