@reldens/utils 0.48.0 → 0.50.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
@@ -29,14 +29,13 @@ class Logger
29
29
  this.callback = false;
30
30
  this.forcedDisabled = Boolean(sc.get(context, 'RELDENS_LOGS_FORCED_DISABLED', false));
31
31
  this.addTimeStamp = Boolean(sc.get(context, 'RELDENS_LOGS_INCLUDE_TIMESTAMP', true));
32
- this.maxLogArgLength = sc.get(context, 'RELDENS_LOGS_MAX_ARGUMENT_LENGTH', 1000);
33
- this.maxStackTraceLength = sc.get(context, 'RELDENS_LOGS_MAX_STACK_TRACE_LENGTH', 2000);
32
+ this.maxLogArgLength = sc.get(context, 'RELDENS_LOGS_MAX_ARGUMENT_LENGTH', 0);
33
+ this.maxStackTraceLength = sc.get(context, 'RELDENS_LOGS_MAX_STACK_TRACE_LENGTH', 0);
34
+ this.applySanitizer = Boolean(sc.get(context, 'RELDENS_LOGS_APPLY_SANITIZER', false));
34
35
  }
35
36
 
36
37
  context()
37
38
  {
38
- // @NOTE: any change on this method could break Parcel and you will end up with the following error.
39
- // Failed to resolve module specifier "process"
40
39
  let context = process.env;
41
40
  if('undefined' !== typeof window){
42
41
  return window;
@@ -95,8 +94,11 @@ class Logger
95
94
  log(levelLabel, ...args)
96
95
  {
97
96
  let date = !this.addTimeStamp ? '' : (new Date()).toISOString().slice(0, 19).replace('T', ' ')+' - ';
98
- let sanitizedArgs = args.map(arg => sc.isString(arg) ? sc.cleanMessage(arg, this.maxLogArgLength) : arg);
99
- this.logWithCallback(date+levelLabel.toUpperCase()+' -', ...sanitizedArgs);
97
+ let processedArgs = args;
98
+ if(this.applySanitizer){
99
+ processedArgs = args.map(arg => sc.isString(arg) ? sc.cleanMessage(arg, this.maxLogArgLength) : arg);
100
+ }
101
+ this.logWithCallback(date+levelLabel.toUpperCase()+' -', ...processedArgs);
100
102
  if(-1 !== this.enableTraceFor().indexOf('all') || -1 !== this.enableTraceFor().indexOf(levelLabel)){
101
103
  if('function' !== typeof Error?.captureStackTrace){
102
104
  this.logWithCallback('Error.captureStackTrace is not available.', typeof Error?.captureStackTrace);
@@ -104,8 +106,11 @@ class Logger
104
106
  }
105
107
  let stackHolder = {};
106
108
  Error.captureStackTrace(stackHolder, levelLabel);
107
- let sanitizedStack = sc.cleanMessage(stackHolder.stack, this.maxStackTraceLength);
108
- this.logWithCallback(sanitizedStack);
109
+ let processedStack = stackHolder.stack;
110
+ if(this.applySanitizer){
111
+ processedStack = sc.cleanMessage(stackHolder.stack, this.maxStackTraceLength);
112
+ }
113
+ this.logWithCallback(processedStack);
109
114
  }
110
115
  return this;
111
116
  }
package/lib/shortcuts.js CHANGED
@@ -31,7 +31,7 @@ class Shortcuts
31
31
 
32
32
  isObject(obj)
33
33
  {
34
- return (obj && typeof obj === 'object' && !this.isArray(obj));
34
+ return (obj && 'object' === typeof obj && !this.isArray(obj));
35
35
  }
36
36
 
37
37
  isArray(obj)
@@ -661,6 +661,45 @@ class Shortcuts
661
661
  return str.split(separator).map(item => item.trim()).filter(item => '' !== item);
662
662
  }
663
663
 
664
+ isSecurePath(filePath, dangerous = [], maxLength = 2048)
665
+ {
666
+ if(!this.isString(filePath)){
667
+ return false;
668
+ }
669
+ let normalized = filePath.replace(/\\/g, '/');
670
+ if(!this.isArray(dangerous) || 0 === dangerous.length){
671
+ dangerous = [
672
+ '../', '..\\', './', '.\\',
673
+ '/etc/', '/proc/', '/sys/',
674
+ 'C:\\Windows\\', 'C:\\System32\\',
675
+ '%2e%2e%2f', '%2e%2e%5c'
676
+ ];
677
+ }
678
+ for(let pattern of dangerous){
679
+ if(normalized.toLowerCase().includes(pattern.toLowerCase())){
680
+ return false;
681
+ }
682
+ }
683
+ return maxLength >= filePath.length;
684
+ }
685
+
686
+ validateInput(input, type)
687
+ {
688
+ if(!this.isString(input)){
689
+ return false;
690
+ }
691
+ let patterns = {
692
+ email: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
693
+ username: /^[a-zA-Z0-9_-]{3,30}$/,
694
+ strongPassword: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/,
695
+ alphanumeric: /^[a-zA-Z0-9]+$/,
696
+ numeric: /^\d+$/,
697
+ hexColor: /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,
698
+ ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
699
+ };
700
+ return patterns[type] ? patterns[type].test(input) : false;
701
+ }
702
+
664
703
  }
665
704
 
666
705
  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.48.0",
4
+ "version": "0.50.0",
5
5
  "description": "Reldens - Utils",
6
6
  "author": "Damian A. Pastorini",
7
7
  "license": "MIT",