@reldens/utils 0.10.0-beta.2 → 0.11.0

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/README.md CHANGED
@@ -6,9 +6,9 @@
6
6
 
7
7
  - Interaction area calculation helper.
8
8
  - Shortcuts.
9
- - Logger
10
- - Error Manager
11
- - Events Manager
9
+ - Logger.
10
+ - Error Manager.
11
+ - Events Manager.
12
12
 
13
13
  Need something specific?
14
14
 
@@ -18,7 +18,7 @@ Need something specific?
18
18
 
19
19
  ## Documentation
20
20
 
21
- [https://www.reldens.com/documentation/skills](https://www.reldens.com/documentation/skills)
21
+ [https://www.reldens.com/documentation/utils/](https://www.reldens.com/documentation/utils/)
22
22
 
23
23
 
24
24
  ---
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * Reldens - InteractionArea
4
4
  *
5
- * This class is used to validate the area for an specific object or action, for example if player A targets player B
5
+ * This class is used to validate the area for a specific object or action, for example if player A target player B
6
6
  * by clicking on it and then run an action (by pressing space bar or using the action button), the action will
7
7
  * be only valid and executed if player A is inside the interactive area of player B.
8
8
  *
package/lib/logger.js CHANGED
@@ -8,30 +8,97 @@
8
8
 
9
9
  class Logger
10
10
  {
11
+ logLevels = {
12
+ none: 0,
13
+ emergency: 1, // system is unusable
14
+ alert: 2, // action must be taken immediately
15
+ critical: 3, // critical conditions
16
+ error: 4, // error conditions
17
+ warning: 5, // warning conditions
18
+ notice: 6, // normal but significant condition
19
+ info: 7, // informational messages
20
+ debug: 8 // debug-level messages
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
@@ -33,7 +33,7 @@ class Shortcuts
33
33
  return Array.isArray(obj);
34
34
  }
35
35
 
36
- convertArrayToObjectByKeys(dataArray, keyProperty)
36
+ convertObjectsArrayToObjectByKeys(dataArray, keyProperty)
37
37
  {
38
38
  let objectByKeys = {};
39
39
  for(let arrayItem of dataArray){
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reldens/utils",
3
3
  "scope": "@reldens",
4
- "version": "0.10.0-beta.2",
4
+ "version": "0.11.0",
5
5
  "description": "Reldens - Utils",
6
6
  "author": "Damian A. Pastorini",
7
7
  "license": "MIT",