@reldens/utils 0.18.1 → 0.20.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
@@ -301,6 +301,19 @@ class Shortcuts
301
301
  {
302
302
  return Number(Number(number).toFixed(decimals));
303
303
  }
304
+
305
+ cleanMessage(message, characterLimit)
306
+ {
307
+ if(!message){
308
+ return '';
309
+ }
310
+ let text = message.toString().replace(/\\/g, '');
311
+ if(0 < characterLimit){
312
+ return text.substring(0, characterLimit);
313
+ }
314
+ return text;
315
+ }
316
+
304
317
  }
305
318
 
306
319
  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.1",
4
+ "version": "0.20.0",
5
5
  "description": "Reldens - Utils",
6
6
  "author": "Damian A. Pastorini",
7
7
  "license": "MIT",