Compare commits

...

5 Commits

Author SHA1 Message Date
c1577c2106 Better search include/excludes
Some checks failed
Build / Build NPM Project (push) Successful in 43s
Build / Publish Documentation (push) Failing after 4s
Build / Tag Version (push) Successful in 8s
2025-07-21 18:46:27 -04:00
2b12916246 Handle more reservedIP cases
Some checks failed
Build / Build NPM Project (push) Successful in 42s
Build / Publish Documentation (push) Failing after 4s
Build / Tag Version (push) Successful in 8s
2025-07-21 18:45:11 -04:00
5efb045f22 Search include/exclude null fix
Some checks failed
Build / Build NPM Project (push) Successful in 45s
Build / Publish Documentation (push) Failing after 5s
Build / Tag Version (push) Successful in 9s
2025-07-21 18:33:15 -04:00
7119390681 Added reserved IP utility
Some checks failed
Build / Build NPM Project (push) Successful in 1m4s
Build / Publish Documentation (push) Failing after 1m2s
Build / Tag Version (push) Successful in 1m11s
2025-07-21 18:25:14 -04:00
fd95c0c697 Added includes / excludes to search
Some checks failed
Build / Build NPM Project (push) Successful in 1m4s
Build / Publish Documentation (push) Failing after 15s
Build / Tag Version (push) Successful in 23s
2025-07-21 18:15:21 -04:00
3 changed files with 15 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@ztimson/utils",
"version": "0.26.7",
"version": "0.26.12",
"description": "Utility library",
"author": "Zak Timson",
"license": "MIT",

View File

@ -47,6 +47,17 @@ export function ipV6ToV4(ip: string) {
return ipv4;
}
/**
* Check if IP is reserved, e.g. localhost, private IPs, etc.
* @param {string} ip
* @returns {boolean}
*/
export function reservedIp(ip: string): boolean {
if(ip == 'localhost' || ip == '127.0.0.1') return true;
return /\b(10\.(?:[0-9]{1,3}\.){2}[0-9]{1,3})\b|\b(172\.(?:1[6-9]|2[0-9]|3[0-1])\.(?:[0-9]{1,3}\.)[0-9]{1,3})\b|\b(192\.168\.(?:[0-9]{1,3}\.)[0-9]{1,3})\b/.test(ip);
}
/**
* Represents a function that listens for events and handles them accordingly.
*

View File

@ -39,6 +39,8 @@ export function logicTest(target: object, condition: string): boolean {
case '=':
case '==': return a == b;
case '!=': return a != b;
case '+': return a.toString().includes(b);
case '-': return !a.toString().includes(b);
case '>': return a > b;
case '>=': return a >= b;
case '<': return a < b;
@ -53,7 +55,7 @@ export function logicTest(target: object, condition: string): boolean {
const and = p.split('&&').map(p => p.trim()).filter(p => !!p);
return and.filter(p => {
// Boolean operator
const prop = /(\S+)\s*(==?|!=|>=|>|<=|<)\s*(\S+)/g.exec(p);
const prop = /(\S+)\s*(==?|!=|\+|-|>=|>|<=|<)\s*(\S+)/g.exec(p);
if(prop) {
const key = Object.keys(target).find(k => k.toLowerCase() == prop[1].toLowerCase());
return evalBoolean(dotNotation<any>(target, key || prop[1]), prop[2], JSONAttemptParse(prop[3]));