All files / src/utils get.js

85.71% Statements 6/7
90.91% Branches 10/11
100% Functions 1/1
85.71% Lines 6/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13    42x     42x 42x 42x 13x   29x    
/* eslint-disable no-param-reassign */
export default function get(object, keys, defaultVal = undefined) {
  Iif (typeof object !== 'object') {
    return defaultVal;
  }
  keys = Array.isArray(keys) ? keys : keys.split('.');
  object = object[keys[0]];
  if (object && keys.length > 1) {
    return get(object, keys.slice(1), defaultVal);
  }
  return object === undefined ? defaultVal : object;
}