lib/Utility/Objects.js   A
last analyzed

Complexity

Total Complexity 8
Complexity/F 1.6

Size

Lines of Code 44
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 8
nc 1
mnd 1
bc 6
fnc 5
dl 0
loc 44
rs 10
bpm 1.2
cpm 1.6
noi 0
c 1
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A Objects.merge 0 10 3
A Objects.copy 0 3 1
A Objects.isObject 0 3 1
A Objects.isFunction 0 3 1
1
var Objects = {
2
  /**
3
   * @param {object|*} v
4
   * @return {boolean}
5
   */
6
  isObject: function (v) {
7
    return v !== null && typeof v === 'object' && !Array.isArray(v)
8
  },
9
  /**
10
   * @param {Function|*} v
11
   * @return {boolean}
12
   */
13
  isFunction: function (v) {
14
    return typeof v === 'function'
15
  },
16
  /**
17
   * @param {object} source
18
   * @param {boolean} [deep]
19
   * @return {object}
20
   */
21
  copy: function (source, deep) {
22
    return Objects.merge({}, source, deep)
23
  },
24
  /**
25
   * @param {object|*} target
26
   * @param {object|*} source
27
   * @param {boolean} [deep]
28
   * @return {object}
29
   */
30
  merge: function (target, source, deep) {
31
    if (!Objects.isObject(source)) {
32
      return source
33
    }
34
    target = Objects.isObject(target) ? target : {}
35
    Object.keys(source).forEach(function (key) {
36
      target[key] = deep ? Objects.merge(target[key], source[key], true) : source[key]
37
    })
38
    return target
39
  }
40
}
41
42
module.exports = {
43
  Objects: Objects
44
}
45