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 | 4 | var sarahVersion = {}; |
|
26 | |||
27 | /** |
||
28 | * @public |
||
29 | * @readOnly |
||
30 | * @type {int} |
||
31 | */ |
||
32 | 4 | sarahVersion.v3 = 3; |
|
33 | /** |
||
34 | * @public |
||
35 | * @readOnly |
||
36 | * @type {int} |
||
37 | */ |
||
38 | 4 | sarahVersion.v4 = 4; |
|
39 | |||
40 | /** |
||
41 | * @public |
||
42 | * |
||
43 | * @returns {boolean} |
||
44 | */ |
||
45 | 4 | sarahVersion.isV3 = function() { |
|
46 | 6 | return typeof Config === 'undefined'; |
|
47 | }; |
||
48 | |||
49 | /** |
||
50 | * @public |
||
51 | * |
||
52 | * @returns {boolean} |
||
53 | */ |
||
54 | 4 | sarahVersion.isV4 = function() { |
|
55 | 2 | return !this.isV3(); |
|
56 | }; |
||
57 | |||
58 | /** |
||
59 | * @public |
||
60 | * |
||
61 | * @returns {int} |
||
62 | */ |
||
63 | 4 | sarahVersion.get = function() { |
|
64 | 2 | return this.isV3() ? this.v3 : this.v4; |
|
65 | }; |
||
66 | |||
67 | module.exports = sarahVersion; |
||
68 |