Added IPv6 to v4 converter
This commit is contained in:
parent
7747dc5558
commit
adafd61c83
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.25.17",
|
||||
"version": "0.25.18",
|
||||
"description": "Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
24
src/misc.ts
24
src/misc.ts
@ -1,6 +1,16 @@
|
||||
import {PathEvent} from './path-events.ts';
|
||||
import {md5} from './string';
|
||||
|
||||
/**
|
||||
* Escape any regex special characters to avoid misinterpretation during search
|
||||
*
|
||||
* @param {string} value String which should be escaped
|
||||
* @return {string} New escaped sequence
|
||||
*/
|
||||
export function escapeRegex(value: string) {
|
||||
return value.replace(/[.*+?^${}()|\[\]\\]/g, '\\$&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a stringified function with arguments asynchronously
|
||||
* @param {object} args Map of key/value arguments
|
||||
@ -26,13 +36,15 @@ export function gravatar(email: string, def='mp') {
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape any regex special characters to avoid misinterpretation during search
|
||||
*
|
||||
* @param {string} value String which should be escaped
|
||||
* @return {string} New escaped sequence
|
||||
* Convert IPv6 to v4 because who uses that, NAT4Life
|
||||
* @param {string} ip IPv6 address, e.g. 2001:0db8:85a3:0000:0000:8a2e:0370:7334
|
||||
* @returns {string | null} IPv4 address, e.g. 172.16.58.3
|
||||
*/
|
||||
export function escapeRegex(value: string) {
|
||||
return value.replace(/[.*+?^${}()|\[\]\\]/g, '\\$&');
|
||||
export function ipV6ToV4(ip: string) {
|
||||
if(!ip) return null;
|
||||
const ipv4 = ip.split(':').splice(-1)[0];
|
||||
if(ipv4 == '1') return '127.0.0.1';
|
||||
return ipv4;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user