Passed
Push — master ( 3e148a...4cbe5d )
by Yo
01:25
created

sarahVersion.get   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
rs 10
nop 0
1
/* globals module, Config */
2
/**
3
 * @summary Sarah version helper
4
 * @description Provide helpful methods to deal with Sarah version
5
 *
6
 * @example
7
 * const version = require('sarah.lib.utils/version');
8
 *
9
 * @example <caption>Helper</caption>
10
 *  version.isV3();
11
 *  version.isV4();
12
 *  version.get();
13
 *
14
 * @example <caption>get usage</caption>
15
 *  var versionNumber = version.get();
16
 *  if (version.v3 == versionNumber) {
17
 *      ...
18
 *  }
19
 *  if (version.v4 == versionNumber) {
20
 *      ...
21
 *  }
22
 *
23
 */
24
25 1
var sarahVersion = {};
26
27
/**
28
 * @public
29
 * @readOnly
30
 * @type {int}
31
 */
32 1
sarahVersion.v3 = 3;
33
/**
34
 * @public
35
 * @readOnly
36
 * @type {int}
37
 */
38 1
sarahVersion.v4 = 4;
39
40
/**
41
 * @public
42
 *
43
 * @returns {boolean}
44
 */
45 1
sarahVersion.isV3 = function() {
46 6
    return typeof Config === 'undefined';
47
};
48
49
/**
50
 * @public
51
 *
52
 * @returns {boolean}
53
 */
54 1
sarahVersion.isV4 = function() {
55 2
    return !this.isV3();
56
};
57
58
/**
59
 * @public
60
 *
61
 * @returns {int}
62
 */
63 1
sarahVersion.get = function() {
64 2
    return this.isV3() ? this.v3 : this.v4;
65
};
66
67
module.exports = sarahVersion;
68