lib/Utility/Objects.js   A
last analyzed

Complexity

Total Complexity 15
Complexity/F 3

Size

Lines of Code 38
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 15
c 1
b 0
f 0
nc 1
mnd 1
bc 10
fnc 5
dl 0
loc 38
rs 10
bpm 2
cpm 3
noi 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A Objects.copy 0 13 4
B Objects.merge 0 19 8
1
var Objects = {
2
  merge: function (a, b) {
3
    if (typeof b === 'undefined' || b === null) {
4
      return a
5
    }
6
    if (typeof b !== 'object' || typeof a !== 'object' || a === null) {
7
      return b
8
    }
9
    if (Array.isArray(a) || Array.isArray(b)) {
10
      return b
11
    }
12
    var target = {}
13
    Object.keys(a).forEach(function (key) {
14
      target[key] = a[key]
15
    })
16
    Object.keys(b).forEach(function (key) {
17
      target[key] = Objects.merge(target[key], b[key])
18
    })
19
    return target
20
  },
21
  copy: function (value) {
22
    if (typeof value !== 'object' || value === null) {
23
      return value
24
    }
25
    if (Array.isArray(value)) {
26
      return value.map(Objects.copy)
27
    }
28
    var target = {}
29
    Object.keys(value).forEach(function (key) {
30
      target[key] = Objects.copy(value[key])
31
    })
32
    return target
33
  }
34
}
35
36
module.exports = {
37
  Objects: Objects
38
}
39