@reldens/utils 0.18.0 → 0.19.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/lib/logger.js CHANGED
@@ -2,12 +2,11 @@
2
2
  *
3
3
  * Reldens - Logger
4
4
  *
5
- * This is a general logger handle.
6
- *
7
5
  */
8
6
 
9
7
  class Logger
10
8
  {
9
+
11
10
  logLevels = {
12
11
  none: 0,
13
12
  emergency: 1, // system is unusable
@@ -25,15 +24,29 @@ class Logger
25
24
  // @TODO - BETA
26
25
  // - Implement different log systems (console.log, files logs, db log?).
27
26
  // - 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(',');
27
+ let context = this.context();
28
+ this.logLevel = context.RELDENS_LOG_LEVEL || 0;
29
+ this.enableTraceFor = (context.RELDENS_ENABLE_TRACE_FOR || '').split(',');
30
+ }
31
+
32
+ context()
33
+ {
34
+ // @NOTE: any change on this method could break Parcel and you will end up with the following error.
35
+ // Failed to resolve module specifier "process"
36
+ let context = process.env;
37
+ if('undefined' !== typeof window){
38
+ return window;
39
+ }
40
+ return context;
30
41
  }
31
42
 
32
43
  log(levelLabel, ...args)
33
44
  {
34
45
  console.log(levelLabel.toUpperCase()+' -', ...args);
35
- if(this.enableTraceFor.indexOf(levelLabel) !== -1){
36
- console.trace();
46
+ if(-1 !== this.enableTraceFor.indexOf('all') || -1 !== this.enableTraceFor.indexOf(levelLabel)){
47
+ let stackHolder = {};
48
+ Error.captureStackTrace(stackHolder, levelLabel);
49
+ console.log(stackHolder.stack);
37
50
  }
38
51
  }
39
52
 
package/lib/shortcuts.js CHANGED
@@ -41,6 +41,9 @@ class Shortcuts
41
41
 
42
42
  inArray(value, dataArray)
43
43
  {
44
+ if(!this.isArray(dataArray)){
45
+ return false;
46
+ }
44
47
  return -1 === dataArray.indexOf(value);
45
48
  }
46
49
 
@@ -130,6 +133,18 @@ class Shortcuts
130
133
  return this.hasOwn(obj, prop) ? obj[prop] : defaultReturn;
131
134
  }
132
135
 
136
+ getByPath(obj, propertyPath, defaultReturn)
137
+ {
138
+ if(!this.isObject(obj) || !this.isArray(propertyPath)){
139
+ return defaultReturn;
140
+ }
141
+ let property = propertyPath.shift();
142
+ if(0 === propertyPath.length){
143
+ return this.get(obj, property, defaultReturn);
144
+ }
145
+ return this.getByPath(obj[property], propertyPath, defaultReturn);
146
+ }
147
+
133
148
  getByPriority(obj, propsArray)
134
149
  {
135
150
  if(!this.isArray(propsArray)){
@@ -286,6 +301,7 @@ class Shortcuts
286
301
  {
287
302
  return Number(Number(number).toFixed(decimals));
288
303
  }
304
+
289
305
  }
290
306
 
291
307
  module.exports = new Shortcuts();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reldens/utils",
3
3
  "scope": "@reldens",
4
- "version": "0.18.0",
4
+ "version": "0.19.0",
5
5
  "description": "Reldens - Utils",
6
6
  "author": "Damian A. Pastorini",
7
7
  "license": "MIT",