Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
5efb045f22 | |||
7119390681 | |||
fd95c0c697 |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.26.7",
|
||||
"version": "0.26.10",
|
||||
"description": "Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
11
src/misc.ts
11
src/misc.ts
@ -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') 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.
|
||||
*
|
||||
|
@ -39,6 +39,8 @@ export function logicTest(target: object, condition: string): boolean {
|
||||
case '=':
|
||||
case '==': return a == b;
|
||||
case '!=': return a != b;
|
||||
case '+': return typeof a?.includes != 'undefined' ? a.includes(b) : a == b;
|
||||
case '-': return typeof a?.includes != 'undefined' ? !a.includes(b) : a != 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]));
|
||||
|
Reference in New Issue
Block a user