All files get-in.ts

100% Statements 12/12
100% Branches 8/8
100% Functions 1/1
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28        1x 45x 2x       43x 2x     41x   41x 10x     31x 17x     14x      
/*
 * Gets a deeply-nested property value from an object, given a 'path'
 * of property names or array indices.
 */
export function getIn(v, pathElems: (string | number)[]): any {
    if (!v) {
      return v;
    }
 
    // If this is an ImmutableJS structure, use existing getIn function
    if (typeof v.getIn === 'function') {
      return v.getIn(pathElems);
    }
 
    const [ firstElem, ...restElems] = pathElems;
 
    if (undefined === v[firstElem]) {
      return undefined;
    }
 
    if (restElems.length === 0) {
        return v[firstElem];
    }
 
    return getIn(v[firstElem], restElems);
}