src/modules/getByKey.js   A
last analyzed

Complexity

Total Complexity 3
Complexity/F 3

Size

Lines of Code 20
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 13
mnd 2
bc 2
fnc 1
dl 0
loc 20
ccs 8
cts 8
cp 1
rs 10
bpm 2
cpm 3
noi 0
c 0
b 0
f 0
1
export default function getByKey(original, key, defaultValue) {
2 3
    const keys = key.split('.');
3
4 3
    let reference = original;
5
6 3
    while (keys.length > 0) {
7 4
        const referenceKey = keys.shift();
8
9 4
        if (
10
            reference === null ||
11
            reference === undefined ||
12
            !Object.prototype.hasOwnProperty.call(reference, referenceKey)
13
        ) {
14 2
            return defaultValue;
15
        }
16 2
        reference = reference[referenceKey];
17
    }
18
19 1
    return reference;
20
}
21