Completed
Push — master ( 598926...1a164b )
by Fike
44s queued 17s
created

lib/logger/Level.js   A

Complexity

Total Complexity 8
Complexity/F 2.67

Size

Lines of Code 29
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 8
c 1
b 0
f 0
nc 32
mnd 1
bc 3
fnc 3
dl 0
loc 29
rs 10
bpm 1
cpm 2.6666
noi 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A Level.find 0 6 3
A Level.keys.forEach 0 11 2
1
/**
2
 * @typedef {object} Level~Element
3
 * @property {string} id
4
 * @property {int} weight
5
 * @property {boolean} implicit
6
 */
7
8
/**
9
 * @enum
10
 *
11
 * @property {Level~Element} All
12
 * @property {Level~Element} Trace
13
 * @property {Level~Element} Debug
14
 * @property {Level~Element} Info
15
 * @property {Level~Element} Notice
16
 * @property {Level~Element} Warn
17
 * @property {Level~Element} Error
18
 * @property {Level~Element} Off
19
 */
20
var Level = {}
21
22
Level.keys = ['All', 'Trace', 'Debug', 'Info', 'Notice', 'Warn', 'Error']
23
Level.values = []
24
Level.explicit = []
25
Level.implicit = []
26
var implicit = ['All', 'Off']
27
Level.keys.forEach(function (id) {
28
  var level = {
29
    id: id,
30
    weight: Level.keys.indexOf(id) + 1,
31
    implicit: implicit.indexOf(id) > -1
32
  }
33
  Level[id] = level
34
  Level.values.push(level)
35
  var target = level.implicit ? Level.implicit : Level.explicit
36
  target.push(level)
37
})
38
39
Level.find = function (input) {
40
  input = input && input.toLowerCase ? input.toLowerCase() : input
41
  return Level.keys.reduce(function (carrier, id) {
42
    return input === id.toLowerCase() || input === Level[id] ? Level[id] : carrier
43
  }, null)
44
}
45
46
module.exports = {
47
  Level: Level
48
}
49