@reldens/utils 0.6.0 → 0.10.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/logger.js CHANGED
@@ -8,30 +8,97 @@
8
8
 
9
9
  class Logger
10
10
  {
11
+ logLevels = {
12
+ none: 0,
13
+ debug: 8, // debug-level messages
14
+ info: 7, // informational messages
15
+ notice: 6, // normal but significant condition
16
+ warning: 5, // warning conditions
17
+ error: 4, // error conditions
18
+ critical: 3, // critical conditions
19
+ alert: 2, // action must be taken immediately
20
+ emergency: 1, // system is unusable
21
+ };
11
22
 
12
23
  constructor()
13
24
  {
14
- this.enableTrace = [];
25
+ // @TODO - BETA
26
+ // - Implement different log systems (console.log, files logs, db log?).
27
+ // - Implement notifications system (email?), and make it configurable for the different log levels.
28
+ this.logLevel = process.env.RELDENS_LOG_LEVEL || 0;
29
+ this.enableTraceFor = (process.env.RELDENS_ENABLE_TRACE_FOR || '').split(',');
15
30
  }
16
31
 
17
- info(...args)
32
+ log(levelLabel, ...args)
18
33
  {
19
- // @TODO - BETA.17:
20
- // - implement environment variables to validate the log level (info, warning, error, critical).
21
- // - implement different log systems (console.log, files logs, db log?).
22
- // - implement notifications system (email?), and make it configurable for the different log levels.
23
- console.info('INFO -', ...args);
24
- if(this.enableTrace.indexOf('info') !== -1){
34
+ console.log(levelLabel.toUpperCase()+' -', ...args);
35
+ if(this.enableTraceFor.indexOf(levelLabel) !== -1){
25
36
  console.trace();
26
37
  }
27
38
  }
28
39
 
40
+ debug(...args)
41
+ {
42
+ if(8 > this.logLevel){
43
+ return;
44
+ }
45
+ this.log('debug', ...args);
46
+ }
47
+
48
+ info(...args)
49
+ {
50
+ if(7 > this.logLevel){
51
+ return;
52
+ }
53
+ this.log('info', ...args);
54
+ }
55
+
56
+ notice(...args)
57
+ {
58
+ if(6 > this.logLevel){
59
+ return;
60
+ }
61
+ this.log('notice', ...args);
62
+ }
63
+
64
+ warning(...args)
65
+ {
66
+ if(5 > this.logLevel){
67
+ return;
68
+ }
69
+ this.log('warning', ...args);
70
+ }
71
+
29
72
  error(...args)
30
73
  {
31
- console.error('ERROR -', ...args);
32
- if(this.enableTrace.indexOf('error') !== -1){
33
- console.trace();
74
+ if(4 > this.logLevel){
75
+ return;
76
+ }
77
+ this.log('error', ...args);
78
+ }
79
+
80
+ critical(...args)
81
+ {
82
+ if(3 > this.logLevel){
83
+ return;
84
+ }
85
+ this.log('critical', ...args);
86
+ }
87
+
88
+ alert(...args)
89
+ {
90
+ if(2 > this.logLevel){
91
+ return;
92
+ }
93
+ this.log('alert', ...args);
94
+ }
95
+
96
+ emergency(...args)
97
+ {
98
+ if(1 > this.logLevel){
99
+ return;
34
100
  }
101
+ this.log('emergency', ...args);
35
102
  }
36
103
 
37
104
  }
package/lib/shortcuts.js CHANGED
@@ -23,9 +23,9 @@ class Shortcuts
23
23
  }
24
24
  }
25
25
 
26
- isTrue(obj, prop)
26
+ isTrue(obj, prop, strictValidation)
27
27
  {
28
- return (obj && {}.hasOwnProperty.call(obj, prop) && obj[prop]);
28
+ return (obj && {}.hasOwnProperty.call(obj, prop) && (strictValidation ? true === obj[prop] : obj[prop]));
29
29
  }
30
30
 
31
31
  isArray(obj)
@@ -37,7 +37,7 @@ class Shortcuts
37
37
  {
38
38
  let objectByKeys = {};
39
39
  for(let arrayItem of dataArray){
40
- objectByKeys[dataArray[keyProperty]] = arrayItem;
40
+ objectByKeys[arrayItem[keyProperty]] = arrayItem;
41
41
  }
42
42
  return objectByKeys;
43
43
  }
@@ -57,7 +57,7 @@ class Shortcuts
57
57
  return to;
58
58
  }
59
59
 
60
- getJson(jsonString, defaultReturn = false)
60
+ toJson(jsonString, defaultReturn = false)
61
61
  {
62
62
  return this.parseJson(jsonString) || defaultReturn;
63
63
  }
@@ -71,7 +71,7 @@ class Shortcuts
71
71
  }
72
72
  }
73
73
 
74
- getDef(object, prop, defaultReturn)
74
+ get(object, prop, defaultReturn)
75
75
  {
76
76
  return this.hasOwn(object, prop) ? object[prop] : defaultReturn;
77
77
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reldens/utils",
3
3
  "scope": "@reldens",
4
- "version": "0.6.0",
4
+ "version": "0.10.0-beta.4",
5
5
  "description": "Reldens - Utils",
6
6
  "author": "Damian A. Pastorini",
7
7
  "license": "MIT",