@reldens/utils 0.50.0 → 0.52.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
@@ -32,6 +32,8 @@ class Logger
32
32
  this.maxLogArgLength = sc.get(context, 'RELDENS_LOGS_MAX_ARGUMENT_LENGTH', 0);
33
33
  this.maxStackTraceLength = sc.get(context, 'RELDENS_LOGS_MAX_STACK_TRACE_LENGTH', 0);
34
34
  this.applySanitizer = Boolean(sc.get(context, 'RELDENS_LOGS_APPLY_SANITIZER', false));
35
+ this.activeLogLevels = [];
36
+ this.customLevels = [];
35
37
  }
36
38
 
37
39
  context()
@@ -91,8 +93,21 @@ class Logger
91
93
  return (this.context().RELDENS_ENABLE_TRACE_FOR || '').split(',');
92
94
  }
93
95
 
94
- log(levelLabel, ...args)
96
+ log(levelNumber, levelLabel, ...args)
95
97
  {
98
+ if(this.forcedDisabled){
99
+ return this;
100
+ }
101
+ if(0 < this.activeLogLevels.length){
102
+ if(-1 === this.activeLogLevels.indexOf(levelNumber)){
103
+ return this;
104
+ }
105
+ }
106
+ if(0 === this.activeLogLevels.length){
107
+ if(levelNumber > this.logLevel()){
108
+ return this;
109
+ }
110
+ }
96
111
  let date = !this.addTimeStamp ? '' : (new Date()).toISOString().slice(0, 19).replace('T', ' ')+' - ';
97
112
  let processedArgs = args;
98
113
  if(this.applySanitizer){
@@ -125,90 +140,42 @@ class Logger
125
140
 
126
141
  debug(...args)
127
142
  {
128
- if(this.forcedDisabled){
129
- return this;
130
- }
131
- if(8 > this.logLevel()){
132
- return this;
133
- }
134
- return this.log('debug', ...args);
143
+ return this.log(8, 'debug', ...args);
135
144
  }
136
145
 
137
146
  info(...args)
138
147
  {
139
- if(this.forcedDisabled){
140
- return this;
141
- }
142
- if(7 > this.logLevel()){
143
- return this;
144
- }
145
- return this.log('info', ...args);
148
+ return this.log(7, 'info', ...args);
146
149
  }
147
150
 
148
151
  notice(...args)
149
152
  {
150
- if(this.forcedDisabled){
151
- return this;
152
- }
153
- if(6 > this.logLevel()){
154
- return this;
155
- }
156
- return this.log('notice', ...args);
153
+ return this.log(6, 'notice', ...args);
157
154
  }
158
155
 
159
156
  warning(...args)
160
157
  {
161
- if(this.forcedDisabled){
162
- return this;
163
- }
164
- if(5 > this.logLevel()){
165
- return this;
166
- }
167
- return this.log('warning', ...args);
158
+ return this.log(5, 'warning', ...args);
168
159
  }
169
160
 
170
161
  error(...args)
171
162
  {
172
- if(this.forcedDisabled){
173
- return this;
174
- }
175
- if(4 > this.logLevel()){
176
- return this;
177
- }
178
- return this.log('error', ...args);
163
+ return this.log(4, 'error', ...args);
179
164
  }
180
165
 
181
166
  critical(...args)
182
167
  {
183
- if(this.forcedDisabled){
184
- return this;
185
- }
186
- if(3 > this.logLevel()){
187
- return this;
188
- }
189
- return this.log('critical', ...args);
168
+ return this.log(3, 'critical', ...args);
190
169
  }
191
170
 
192
171
  alert(...args)
193
172
  {
194
- if(this.forcedDisabled){
195
- return this;
196
- }
197
- if(2 > this.logLevel()){
198
- return this;
199
- }
200
- return this.log('alert', ...args);
173
+ return this.log(2, 'alert', ...args);
201
174
  }
202
175
 
203
176
  emergency(...args)
204
177
  {
205
- if(this.forcedDisabled){
206
- return this;
207
- }
208
- if(1 > this.logLevel()){
209
- return this;
210
- }
211
- return this.log('emergency', ...args);
178
+ return this.log(1, 'emergency', ...args);
212
179
  }
213
180
 
214
181
  }
package/lib/shortcuts.js CHANGED
@@ -62,6 +62,11 @@ class Shortcuts
62
62
  return this.isObject(obj) && property && 'function' === typeof obj[property];
63
63
  }
64
64
 
65
+ isSymbol(value)
66
+ {
67
+ return 'symbol' === typeof value;
68
+ }
69
+
65
70
  isString(value)
66
71
  {
67
72
  return 'string' === typeof value;
@@ -93,6 +98,11 @@ class Shortcuts
93
98
  return 'boolean' === typeof value;
94
99
  }
95
100
 
101
+ isPromise(value)
102
+ {
103
+ return value && 'function' === typeof value.then;
104
+ }
105
+
96
106
  hasDangerousKeys(obj, key = null)
97
107
  {
98
108
  let dangerousKeys = ['__proto__', 'constructor', 'prototype'];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reldens/utils",
3
3
  "scope": "@reldens",
4
- "version": "0.50.0",
4
+ "version": "0.52.0",
5
5
  "description": "Reldens - Utils",
6
6
  "author": "Damian A. Pastorini",
7
7
  "license": "MIT",
@@ -34,7 +34,8 @@
34
34
  "bugs": {
35
35
  "url": "https://github.com/damian-pastorini/reldens-utils/issues"
36
36
  },
37
- "dependencies": {
38
- "await-event-emitter": "2.0.2"
39
- }
37
+ "scripts": {
38
+ "test": "node tests/run.js"
39
+ },
40
+ "dependencies": {}
40
41
  }