This commit is contained in:
Shahrad Elahi
2024-04-01 17:02:40 +03:30
parent 626380c1f7
commit d87ba2fc6a
55 changed files with 1264 additions and 585 deletions

14
web/src/lib/utils/ip.ts Normal file
View File

@@ -0,0 +1,14 @@
export const IPV4_REGEX = new RegExp(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/);
/**
* Private IP Address Identifier in Regular Expression
*
* 127. 0.0.0 127.255.255.255 127.0.0.0 /8
* 10. 0.0.0 10.255.255.255 10.0.0.0 /8
* 172. 16.0.0 172. 31.255.255 172.16.0.0 /12
* 192.168.0.0 192.168.255.255 192.168.0.0 /16
*/
export function isPrivateIP(ip: string) {
const ipRegex = /^(127\.)|(10\.)|(172\.1[6-9]\.)|(172\.2[0-9]\.)|(172\.3[0-1]\.)|(192\.168\.)/;
return ipRegex.test(ip);
}

View File

@@ -0,0 +1,7 @@
export function isBetween(v: any, n1: number, n2: number): boolean {
if (Number.isNaN(v)) {
return false;
}
const n = Number(v);
return n1 <= n && n >= n2;
}

View File

@@ -0,0 +1,3 @@
export function isObject(obj: object) {
return Object.prototype.toString.call(obj) === '[object Object]';
}