@reldens/utils 0.48.0 → 0.49.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/shortcuts.js +40 -1
- package/package.json +1 -1
package/lib/shortcuts.js
CHANGED
|
@@ -31,7 +31,7 @@ class Shortcuts
|
|
|
31
31
|
|
|
32
32
|
isObject(obj)
|
|
33
33
|
{
|
|
34
|
-
return (obj && typeof 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();
|