@xyo-network/shared 2.106.0 → 2.107.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/dist/browser/IdLogger.d.cts +0 -1
- package/dist/browser/IdLogger.d.cts.map +1 -1
- package/dist/browser/IdLogger.d.mts +0 -1
- package/dist/browser/IdLogger.d.mts.map +1 -1
- package/dist/browser/IdLogger.d.ts +0 -1
- package/dist/browser/IdLogger.d.ts.map +1 -1
- package/dist/browser/index.cjs +11 -126
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +11 -105
- package/dist/browser/index.js.map +1 -1
- package/dist/neutral/IdLogger.d.cts +0 -1
- package/dist/neutral/IdLogger.d.cts.map +1 -1
- package/dist/neutral/IdLogger.d.mts +0 -1
- package/dist/neutral/IdLogger.d.mts.map +1 -1
- package/dist/neutral/IdLogger.d.ts +0 -1
- package/dist/neutral/IdLogger.d.ts.map +1 -1
- package/dist/neutral/index.cjs +11 -126
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.js +11 -105
- package/dist/neutral/index.js.map +1 -1
- package/dist/node/IdLogger.d.cts +0 -1
- package/dist/node/IdLogger.d.cts.map +1 -1
- package/dist/node/IdLogger.d.mts +0 -1
- package/dist/node/IdLogger.d.mts.map +1 -1
- package/dist/node/IdLogger.d.ts +0 -1
- package/dist/node/IdLogger.d.ts.map +1 -1
- package/dist/node/index.cjs +11 -139
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +11 -109
- package/dist/node/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAGxD,qBAAa,QAAS,YAAW,MAAM;IACrC,OAAO,CAAC,GAAG,CAAC,CAAc;IAC1B,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,MAAM;IAK7C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAEhB;IAED,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAGtB,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO;IAGrB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAItB,OAAO,CAAC,QAAQ;CAOjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAGxD,qBAAa,QAAS,YAAW,MAAM;IACrC,OAAO,CAAC,GAAG,CAAC,CAAc;IAC1B,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,MAAM;IAK7C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAEhB;IAED,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAGtB,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO;IAGrB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAItB,OAAO,CAAC,QAAQ;CAOjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAGxD,qBAAa,QAAS,YAAW,MAAM;IACrC,OAAO,CAAC,GAAG,CAAC,CAAc;IAC1B,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,MAAM;IAK7C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAEhB;IAED,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAGtB,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO;IAGrB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAItB,OAAO,CAAC,QAAQ;CAOjB"}
|
package/dist/browser/index.cjs
CHANGED
|
@@ -1,129 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
|
|
21
|
-
// src/index.ts
|
|
22
|
-
var src_exports = {};
|
|
23
|
-
__export(src_exports, {
|
|
24
|
-
IdLogger: () => IdLogger,
|
|
25
|
-
dump: () => dump,
|
|
26
|
-
ipVersion: () => ipVersion,
|
|
27
|
-
isIP: () => isIP,
|
|
28
|
-
isIPv4: () => isIPv4,
|
|
29
|
-
isIPv6: () => isIPv6
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(src_exports);
|
|
32
|
-
|
|
33
|
-
// src/dump.ts
|
|
34
|
-
var dump = /* @__PURE__ */ __name((object) => {
|
|
35
|
-
const cache = [];
|
|
36
|
-
return JSON.stringify(object, (key, value) => {
|
|
37
|
-
if (typeof value === "object" && value !== null) {
|
|
38
|
-
if (cache.includes(value)) {
|
|
39
|
-
return "[circular]";
|
|
40
|
-
}
|
|
41
|
-
cache.push(value);
|
|
42
|
-
}
|
|
43
|
-
return value;
|
|
44
|
-
}, 2);
|
|
45
|
-
}, "dump");
|
|
46
|
-
|
|
47
|
-
// src/IdLogger.ts
|
|
48
|
-
var import_logger = require("@xylabs/logger");
|
|
49
|
-
var IdLogger = class {
|
|
50
|
-
static {
|
|
51
|
-
__name(this, "IdLogger");
|
|
52
|
-
}
|
|
53
|
-
_id;
|
|
54
|
-
_logger;
|
|
55
|
-
constructor(logger, id) {
|
|
56
|
-
this._logger = logger;
|
|
57
|
-
this._id = id;
|
|
58
|
-
}
|
|
59
|
-
set id(id) {
|
|
60
|
-
this._id = () => id;
|
|
61
|
-
}
|
|
62
|
-
debug(message) {
|
|
63
|
-
this._logger?.debug(this.generate(message, (0, import_logger.getFunctionName)(3)));
|
|
64
|
-
}
|
|
65
|
-
error(message) {
|
|
66
|
-
this._logger?.error(this.generate(message, (0, import_logger.getFunctionName)(3)));
|
|
67
|
-
}
|
|
68
|
-
info(message) {
|
|
69
|
-
this._logger?.info(this.generate(message, (0, import_logger.getFunctionName)(3)));
|
|
70
|
-
}
|
|
71
|
-
log(message) {
|
|
72
|
-
this._logger?.log(this.generate(message, (0, import_logger.getFunctionName)(3)));
|
|
73
|
-
}
|
|
74
|
-
warn(message) {
|
|
75
|
-
this._logger?.warn(this.generate(message, (0, import_logger.getFunctionName)(3)));
|
|
76
|
-
}
|
|
77
|
-
generate(message, tag) {
|
|
78
|
-
return `${tag} ${this._id ? `[${this._id}] ` : ""}${typeof message === "string" ? message : typeof message === "object" ? JSON.stringify(message, void 0, 2) : `${message}`}`;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// src/is-ip/ip-regex.ts
|
|
83
|
-
var word = String.raw`[a-fA-F\d:]`;
|
|
84
|
-
var boundary = /* @__PURE__ */ __name((options) => options && options.includeBoundaries ? `(?:(?<=\\s|^)(?=${word})|(?<=${word})(?=\\s|$))` : "", "boundary");
|
|
85
|
-
var v4 = String.raw`(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}`;
|
|
86
|
-
var v6segment = String.raw`[a-fA-F\d]{1,4}`;
|
|
87
|
-
var v6 = `
|
|
1
|
+
"use strict";var s=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var $=(e,t)=>s(e,"name",{value:t,configurable:!0});var m=(e,t)=>{for(var i in t)s(e,i,{get:t[i],enumerable:!0})},R=(e,t,i,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let x of w(t))!_.call(e,x)&&x!==i&&s(e,x,{get:()=>t[x],enumerable:!(c=l(t,x))||c.enumerable});return e};var v=e=>R(s({},"__esModule",{value:!0}),e);var N={};m(N,{IdLogger:()=>f,dump:()=>y,ipVersion:()=>F,isIP:()=>h,isIPv4:()=>S,isIPv6:()=>p});module.exports=v(N);var y=$(e=>{let t=[];return JSON.stringify(e,(i,c)=>{if(typeof c=="object"&&c!==null){if(t.includes(c))return"[circular]";t.push(c)}return c},2)},"dump");var o=require("@xylabs/logger");var f=class{static{$(this,"IdLogger")}_id;_logger;constructor(t,i){this._logger=t,this._id=i}set id(t){this._id=()=>t}debug(t){this._logger?.debug(this.generate(t,(0,o.getFunctionName)(3)))}error(t){this._logger?.error(this.generate(t,(0,o.getFunctionName)(3)))}info(t){this._logger?.info(this.generate(t,(0,o.getFunctionName)(3)))}log(t){this._logger?.log(this.generate(t,(0,o.getFunctionName)(3)))}warn(t){this._logger?.warn(this.generate(t,(0,o.getFunctionName)(3)))}generate(t,i){return`${i} ${this._id?`[${this._id}] `:""}${typeof t=="string"?t:typeof t=="object"?JSON.stringify(t,void 0,2):`${t}`}`}};var a=String.raw`[a-fA-F\d:]`,g=$(e=>e&&e.includeBoundaries?`(?:(?<=\\s|^)(?=${a})|(?<=${a})(?=\\s|$))`:"","boundary"),n=String.raw`(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}`,r=String.raw`[a-fA-F\d]{1,4}`,u=`
|
|
88
2
|
(?:
|
|
89
|
-
(?:${
|
|
90
|
-
(?:${
|
|
91
|
-
(?:${
|
|
92
|
-
(?:${
|
|
93
|
-
(?:${
|
|
94
|
-
(?:${
|
|
95
|
-
(?:${
|
|
96
|
-
(?::(?:(?::${
|
|
3
|
+
(?:${r}:){7}(?:${r}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
|
|
4
|
+
(?:${r}:){6}(?:${n}|:${r}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
|
|
5
|
+
(?:${r}:){5}(?::${n}|(?::${r}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
|
|
6
|
+
(?:${r}:){4}(?:(?::${r}){0,1}:${n}|(?::${r}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
|
|
7
|
+
(?:${r}:){3}(?:(?::${r}){0,2}:${n}|(?::${r}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
|
|
8
|
+
(?:${r}:){2}(?:(?::${r}){0,3}:${n}|(?::${r}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
|
|
9
|
+
(?:${r}:){1}(?:(?::${r}){0,4}:${n}|(?::${r}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
|
|
10
|
+
(?::(?:(?::${r}){0,5}:${n}|(?::${r}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
|
|
97
11
|
)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
|
|
98
|
-
`.replaceAll(/\s*\/\/.*$/gm,
|
|
99
|
-
|
|
100
|
-
var v4exact = new RegExp(`^${v4}$`);
|
|
101
|
-
var v6exact = new RegExp(`^${v6}$`);
|
|
102
|
-
var ipRegex = /* @__PURE__ */ __name((options) => options && options.exact ? v46Exact : new RegExp(`(?:${boundary(options)}${v4}${boundary(options)})|(?:${boundary(options)}${v6}${boundary(options)})`, "g"), "ipRegex");
|
|
103
|
-
ipRegex.v4 = (options) => options && options.exact ? v4exact : new RegExp(`${boundary(options)}${v4}${boundary(options)}`, "g");
|
|
104
|
-
ipRegex.v6 = (options) => options && options.exact ? v6exact : new RegExp(`${boundary(options)}${v6}${boundary(options)}`, "g");
|
|
105
|
-
|
|
106
|
-
// src/is-ip/is-ip.ts
|
|
107
|
-
function isIP(value) {
|
|
108
|
-
return ipRegex({
|
|
109
|
-
exact: true
|
|
110
|
-
}).test(value);
|
|
111
|
-
}
|
|
112
|
-
__name(isIP, "isIP");
|
|
113
|
-
function isIPv6(value) {
|
|
114
|
-
return ipRegex.v6({
|
|
115
|
-
exact: true
|
|
116
|
-
}).test(value);
|
|
117
|
-
}
|
|
118
|
-
__name(isIPv6, "isIPv6");
|
|
119
|
-
function isIPv4(value) {
|
|
120
|
-
return ipRegex.v4({
|
|
121
|
-
exact: true
|
|
122
|
-
}).test(value);
|
|
123
|
-
}
|
|
124
|
-
__name(isIPv4, "isIPv4");
|
|
125
|
-
function ipVersion(value) {
|
|
126
|
-
return isIP(value) ? isIPv6(value) ? 6 : 4 : void 0;
|
|
127
|
-
}
|
|
128
|
-
__name(ipVersion, "ipVersion");
|
|
12
|
+
`.replaceAll(/\s*\/\/.*$/gm,"").replaceAll(`
|
|
13
|
+
`,"").trim(),E=new RegExp(`(?:^${n}$)|(?:^${u}$)`),b=new RegExp(`^${n}$`),A=new RegExp(`^${u}$`),d=$(e=>e&&e.exact?E:new RegExp(`(?:${g(e)}${n}${g(e)})|(?:${g(e)}${u}${g(e)})`,"g"),"ipRegex");d.v4=e=>e&&e.exact?b:new RegExp(`${g(e)}${n}${g(e)}`,"g");d.v6=e=>e&&e.exact?A:new RegExp(`${g(e)}${u}${g(e)}`,"g");function h(e){return d({exact:!0}).test(e)}$(h,"isIP");function p(e){return d.v6({exact:!0}).test(e)}$(p,"isIPv6");function S(e){return d.v4({exact:!0}).test(e)}$(S,"isIPv4");function F(e){return h(e)?p(e)?6:4:void 0}$(F,"ipVersion");
|
|
129
14
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/dump.ts","../../src/IdLogger.ts","../../src/is-ip/ip-regex.ts","../../src/is-ip/is-ip.ts"],"sourcesContent":["export * from './dump'\nexport * from './IdLogger'\nexport * from './is-ip'\nexport * from './Job'\n","export const dump = (object: unknown) => {\n const cache: unknown[] = []\n return JSON.stringify(\n object,\n (key, value) => {\n if (typeof value === 'object' && value !== null) {\n // Duplicate reference found, discard key\n if (cache.includes(value)) {\n return '[circular]'\n }\n\n // Store value in our collection\n cache.push(value)\n }\n return value\n },\n 2,\n )\n}\n","import { getFunctionName, Logger } from '@xylabs/logger'\n\n/** @deprecated use from @xylabs/logger instead */\nexport class IdLogger implements Logger {\n private _id?: () => string\n private _logger: Logger\n\n constructor(logger: Logger, id?: () => string) {\n this._logger = logger\n this._id = id\n }\n\n set id(id: string) {\n this._id = () => id\n }\n\n debug(message?: unknown) {\n this._logger?.debug(this.generate(message, getFunctionName(3)))\n }\n error(message?: unknown) {\n this._logger?.error(this.generate(message, getFunctionName(3)))\n }\n info(message?: unknown) {\n this._logger?.info(this.generate(message, getFunctionName(3)))\n }\n log(message?: unknown) {\n this._logger?.log(this.generate(message, getFunctionName(3)))\n }\n warn(message?: unknown) {\n this._logger?.warn(this.generate(message, getFunctionName(3)))\n }\n\n private generate(message?: unknown, tag?: string) {\n return `${tag} ${this._id ? `[${this._id}] ` : ''}${\n typeof message === 'string' ? message\n : typeof message === 'object' ? JSON.stringify(message, undefined, 2)\n : `${message}`\n }`\n }\n}\n","const word = String.raw`[a-fA-F\\d:]`\n\nexport interface Options {\n readonly exact?: boolean\n readonly includeBoundaries?: boolean\n}\n\nconst boundary = (options: Options) => (options && options.includeBoundaries ? `(?:(?<=\\\\s|^)(?=${word})|(?<=${word})(?=\\\\s|$))` : '')\n\nconst v4 = String.raw`(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}`\n\nconst v6segment = String.raw`[a-fA-F\\d]{1,4}`\n\nconst v6 = `\n(?:\n(?:${v6segment}:){7}(?:${v6segment}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8\n(?:${v6segment}:){6}(?:${v4}|:${v6segment}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4\n(?:${v6segment}:){5}(?::${v4}|(?::${v6segment}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4\n(?:${v6segment}:){4}(?:(?::${v6segment}){0,1}:${v4}|(?::${v6segment}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4\n(?:${v6segment}:){3}(?:(?::${v6segment}){0,2}:${v4}|(?::${v6segment}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4\n(?:${v6segment}:){2}(?:(?::${v6segment}){0,3}:${v4}|(?::${v6segment}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4\n(?:${v6segment}:){1}(?:(?::${v6segment}){0,4}:${v4}|(?::${v6segment}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4\n(?::(?:(?::${v6segment}){0,5}:${v4}|(?::${v6segment}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4\n)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1\n`\n .replaceAll(/\\s*\\/\\/.*$/gm, '')\n .replaceAll('\\n', '')\n .trim()\n\n// Pre-compile only the exact regexes because adding a global flag make regexes stateful\nconst v46Exact = new RegExp(`(?:^${v4}$)|(?:^${v6}$)`)\nconst v4exact = new RegExp(`^${v4}$`)\nconst v6exact = new RegExp(`^${v6}$`)\n\nexport const ipRegex = (options: Options) =>\n options && options.exact ?\n v46Exact\n : new RegExp(`(?:${boundary(options)}${v4}${boundary(options)})|(?:${boundary(options)}${v6}${boundary(options)})`, 'g')\n\nipRegex.v4 = (options: Options) => (options && options.exact ? v4exact : new RegExp(`${boundary(options)}${v4}${boundary(options)}`, 'g'))\nipRegex.v6 = (options: Options) => (options && options.exact ? v6exact : new RegExp(`${boundary(options)}${v6}${boundary(options)}`, 'g'))\n","import { ipRegex } from './ip-regex'\n\nexport function isIP(value: string) {\n return ipRegex({ exact: true }).test(value)\n}\n\nexport function isIPv6(value: string) {\n return ipRegex.v6({ exact: true }).test(value)\n}\n\nexport function isIPv4(value: string) {\n return ipRegex.v4({ exact: true }).test(value)\n}\n\nexport function ipVersion(value: string) {\n return (\n isIP(value) ?\n isIPv6(value) ? 6\n : 4\n : undefined\n )\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/dump.ts","../../src/IdLogger.ts","../../src/is-ip/ip-regex.ts","../../src/is-ip/is-ip.ts"],"sourcesContent":["export * from './dump'\nexport * from './IdLogger'\nexport * from './is-ip'\nexport * from './Job'\n","export const dump = (object: unknown) => {\n const cache: unknown[] = []\n return JSON.stringify(\n object,\n (key, value) => {\n if (typeof value === 'object' && value !== null) {\n // Duplicate reference found, discard key\n if (cache.includes(value)) {\n return '[circular]'\n }\n\n // Store value in our collection\n cache.push(value)\n }\n return value\n },\n 2,\n )\n}\n","import { getFunctionName, Logger } from '@xylabs/logger'\n\n/** @deprecated use from @xylabs/logger instead */\nexport class IdLogger implements Logger {\n private _id?: () => string\n private _logger: Logger\n\n constructor(logger: Logger, id?: () => string) {\n this._logger = logger\n this._id = id\n }\n\n set id(id: string) {\n this._id = () => id\n }\n\n debug(message?: unknown) {\n this._logger?.debug(this.generate(message, getFunctionName(3)))\n }\n error(message?: unknown) {\n this._logger?.error(this.generate(message, getFunctionName(3)))\n }\n info(message?: unknown) {\n this._logger?.info(this.generate(message, getFunctionName(3)))\n }\n log(message?: unknown) {\n this._logger?.log(this.generate(message, getFunctionName(3)))\n }\n warn(message?: unknown) {\n this._logger?.warn(this.generate(message, getFunctionName(3)))\n }\n\n private generate(message?: unknown, tag?: string) {\n return `${tag} ${this._id ? `[${this._id}] ` : ''}${\n typeof message === 'string' ? message\n : typeof message === 'object' ? JSON.stringify(message, undefined, 2)\n : `${message}`\n }`\n }\n}\n","const word = String.raw`[a-fA-F\\d:]`\n\nexport interface Options {\n readonly exact?: boolean\n readonly includeBoundaries?: boolean\n}\n\nconst boundary = (options: Options) => (options && options.includeBoundaries ? `(?:(?<=\\\\s|^)(?=${word})|(?<=${word})(?=\\\\s|$))` : '')\n\nconst v4 = String.raw`(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}`\n\nconst v6segment = String.raw`[a-fA-F\\d]{1,4}`\n\nconst v6 = `\n(?:\n(?:${v6segment}:){7}(?:${v6segment}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8\n(?:${v6segment}:){6}(?:${v4}|:${v6segment}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4\n(?:${v6segment}:){5}(?::${v4}|(?::${v6segment}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4\n(?:${v6segment}:){4}(?:(?::${v6segment}){0,1}:${v4}|(?::${v6segment}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4\n(?:${v6segment}:){3}(?:(?::${v6segment}){0,2}:${v4}|(?::${v6segment}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4\n(?:${v6segment}:){2}(?:(?::${v6segment}){0,3}:${v4}|(?::${v6segment}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4\n(?:${v6segment}:){1}(?:(?::${v6segment}){0,4}:${v4}|(?::${v6segment}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4\n(?::(?:(?::${v6segment}){0,5}:${v4}|(?::${v6segment}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4\n)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1\n`\n .replaceAll(/\\s*\\/\\/.*$/gm, '')\n .replaceAll('\\n', '')\n .trim()\n\n// Pre-compile only the exact regexes because adding a global flag make regexes stateful\nconst v46Exact = new RegExp(`(?:^${v4}$)|(?:^${v6}$)`)\nconst v4exact = new RegExp(`^${v4}$`)\nconst v6exact = new RegExp(`^${v6}$`)\n\nexport const ipRegex = (options: Options) =>\n options && options.exact ?\n v46Exact\n : new RegExp(`(?:${boundary(options)}${v4}${boundary(options)})|(?:${boundary(options)}${v6}${boundary(options)})`, 'g')\n\nipRegex.v4 = (options: Options) => (options && options.exact ? v4exact : new RegExp(`${boundary(options)}${v4}${boundary(options)}`, 'g'))\nipRegex.v6 = (options: Options) => (options && options.exact ? v6exact : new RegExp(`${boundary(options)}${v6}${boundary(options)}`, 'g'))\n","import { ipRegex } from './ip-regex'\n\nexport function isIP(value: string) {\n return ipRegex({ exact: true }).test(value)\n}\n\nexport function isIPv6(value: string) {\n return ipRegex.v6({ exact: true }).test(value)\n}\n\nexport function isIPv4(value: string) {\n return ipRegex.v4({ exact: true }).test(value)\n}\n\nexport function ipVersion(value: string) {\n return (\n isIP(value) ?\n isIPv6(value) ? 6\n : 4\n : undefined\n )\n}\n"],"mappings":"4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,EAAA,SAAAC,EAAA,cAAAC,EAAA,SAAAC,EAAA,WAAAC,EAAA,WAAAC,IAAA,eAAAC,EAAAR,GCAO,IAAMS,EAAOC,EAACC,GAAAA,CACnB,IAAMC,E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O,GAAGV,EAASE,CAAAA,CAAAA,GAAWI,CAAAA,GAAKN,EAASE,CAAAA,CAAAA,GAAY,GAAA,ECtC9H,SAASa,EAAKC,EAAa,CAChC,OAAOC,EAAQ,CAAEC,MAAO,EAAK,CAAA,EAAGC,KAAKH,CAAAA,CACvC,CAFgBD,EAAAA,EAAAA,QAIT,SAASK,EAAOJ,EAAa,CAClC,OAAOC,EAAQI,GAAG,CAAEH,MAAO,EAAK,CAAA,EAAGC,KAAKH,CAAAA,CAC1C,CAFgBI,EAAAA,EAAAA,UAIT,SAASE,EAAON,EAAa,CAClC,OAAOC,EAAQM,GAAG,CAAEL,MAAO,EAAK,CAAA,EAAGC,KAAKH,CAAAA,CAC1C,CAFgBM,EAAAA,EAAAA,UAIT,SAASE,EAAUR,EAAa,CACrC,OACED,EAAKC,CAAAA,EACHI,EAAOJ,CAAAA,EAAS,EACd,EACFS,MAEN,CAPgBD,EAAAA,EAAAA","names":["src_exports","__export","IdLogger","dump","ipVersion","isIP","isIPv4","isIPv6","__toCommonJS","dump","__name","object","cache","JSON","stringify","key","value","includes","push","import_logger","IdLogger","_id","_logger","constructor","logger","id","debug","message","generate","getFunctionName","error","info","log","warn","tag","JSON","stringify","undefined","word","String","raw","boundary","__name","options","includeBoundaries","v4","v6segment","v6","replaceAll","trim","v46Exact","RegExp","v4exact","v6exact","ipRegex","exact","isIP","value","ipRegex","exact","test","isIPv6","v6","isIPv4","v4","ipVersion","undefined"]}
|
package/dist/browser/index.js
CHANGED
|
@@ -1,108 +1,14 @@
|
|
|
1
|
-
var
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
|
-
// src/dump.ts
|
|
5
|
-
var dump = /* @__PURE__ */ __name((object) => {
|
|
6
|
-
const cache = [];
|
|
7
|
-
return JSON.stringify(object, (key, value) => {
|
|
8
|
-
if (typeof value === "object" && value !== null) {
|
|
9
|
-
if (cache.includes(value)) {
|
|
10
|
-
return "[circular]";
|
|
11
|
-
}
|
|
12
|
-
cache.push(value);
|
|
13
|
-
}
|
|
14
|
-
return value;
|
|
15
|
-
}, 2);
|
|
16
|
-
}, "dump");
|
|
17
|
-
|
|
18
|
-
// src/IdLogger.ts
|
|
19
|
-
import { getFunctionName } from "@xylabs/logger";
|
|
20
|
-
var IdLogger = class {
|
|
21
|
-
static {
|
|
22
|
-
__name(this, "IdLogger");
|
|
23
|
-
}
|
|
24
|
-
_id;
|
|
25
|
-
_logger;
|
|
26
|
-
constructor(logger, id) {
|
|
27
|
-
this._logger = logger;
|
|
28
|
-
this._id = id;
|
|
29
|
-
}
|
|
30
|
-
set id(id) {
|
|
31
|
-
this._id = () => id;
|
|
32
|
-
}
|
|
33
|
-
debug(message) {
|
|
34
|
-
this._logger?.debug(this.generate(message, getFunctionName(3)));
|
|
35
|
-
}
|
|
36
|
-
error(message) {
|
|
37
|
-
this._logger?.error(this.generate(message, getFunctionName(3)));
|
|
38
|
-
}
|
|
39
|
-
info(message) {
|
|
40
|
-
this._logger?.info(this.generate(message, getFunctionName(3)));
|
|
41
|
-
}
|
|
42
|
-
log(message) {
|
|
43
|
-
this._logger?.log(this.generate(message, getFunctionName(3)));
|
|
44
|
-
}
|
|
45
|
-
warn(message) {
|
|
46
|
-
this._logger?.warn(this.generate(message, getFunctionName(3)));
|
|
47
|
-
}
|
|
48
|
-
generate(message, tag) {
|
|
49
|
-
return `${tag} ${this._id ? `[${this._id}] ` : ""}${typeof message === "string" ? message : typeof message === "object" ? JSON.stringify(message, void 0, 2) : `${message}`}`;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// src/is-ip/ip-regex.ts
|
|
54
|
-
var word = String.raw`[a-fA-F\d:]`;
|
|
55
|
-
var boundary = /* @__PURE__ */ __name((options) => options && options.includeBoundaries ? `(?:(?<=\\s|^)(?=${word})|(?<=${word})(?=\\s|$))` : "", "boundary");
|
|
56
|
-
var v4 = String.raw`(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}`;
|
|
57
|
-
var v6segment = String.raw`[a-fA-F\d]{1,4}`;
|
|
58
|
-
var v6 = `
|
|
1
|
+
var f=Object.defineProperty;var $=(e,t)=>f(e,"name",{value:t,configurable:!0});var m=$(e=>{let t=[];return JSON.stringify(e,(d,g)=>{if(typeof g=="object"&&g!==null){if(t.includes(g))return"[circular]";t.push(g)}return g},2)},"dump");import{getFunctionName as o}from"@xylabs/logger";var s=class{static{$(this,"IdLogger")}_id;_logger;constructor(t,d){this._logger=t,this._id=d}set id(t){this._id=()=>t}debug(t){this._logger?.debug(this.generate(t,o(3)))}error(t){this._logger?.error(this.generate(t,o(3)))}info(t){this._logger?.info(this.generate(t,o(3)))}log(t){this._logger?.log(this.generate(t,o(3)))}warn(t){this._logger?.warn(this.generate(t,o(3)))}generate(t,d){return`${d} ${this._id?`[${this._id}] `:""}${typeof t=="string"?t:typeof t=="object"?JSON.stringify(t,void 0,2):`${t}`}`}};var u=String.raw`[a-fA-F\d:]`,i=$(e=>e&&e.includeBoundaries?`(?:(?<=\\s|^)(?=${u})|(?<=${u})(?=\\s|$))`:"","boundary"),n=String.raw`(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}`,r=String.raw`[a-fA-F\d]{1,4}`,x=`
|
|
59
2
|
(?:
|
|
60
|
-
(?:${
|
|
61
|
-
(?:${
|
|
62
|
-
(?:${
|
|
63
|
-
(?:${
|
|
64
|
-
(?:${
|
|
65
|
-
(?:${
|
|
66
|
-
(?:${
|
|
67
|
-
(?::(?:(?::${
|
|
3
|
+
(?:${r}:){7}(?:${r}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
|
|
4
|
+
(?:${r}:){6}(?:${n}|:${r}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
|
|
5
|
+
(?:${r}:){5}(?::${n}|(?::${r}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
|
|
6
|
+
(?:${r}:){4}(?:(?::${r}){0,1}:${n}|(?::${r}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
|
|
7
|
+
(?:${r}:){3}(?:(?::${r}){0,2}:${n}|(?::${r}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
|
|
8
|
+
(?:${r}:){2}(?:(?::${r}){0,3}:${n}|(?::${r}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
|
|
9
|
+
(?:${r}:){1}(?:(?::${r}){0,4}:${n}|(?::${r}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
|
|
10
|
+
(?::(?:(?::${r}){0,5}:${n}|(?::${r}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
|
|
68
11
|
)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
|
|
69
|
-
`.replaceAll(/\s*\/\/.*$/gm,
|
|
70
|
-
|
|
71
|
-
var v4exact = new RegExp(`^${v4}$`);
|
|
72
|
-
var v6exact = new RegExp(`^${v6}$`);
|
|
73
|
-
var ipRegex = /* @__PURE__ */ __name((options) => options && options.exact ? v46Exact : new RegExp(`(?:${boundary(options)}${v4}${boundary(options)})|(?:${boundary(options)}${v6}${boundary(options)})`, "g"), "ipRegex");
|
|
74
|
-
ipRegex.v4 = (options) => options && options.exact ? v4exact : new RegExp(`${boundary(options)}${v4}${boundary(options)}`, "g");
|
|
75
|
-
ipRegex.v6 = (options) => options && options.exact ? v6exact : new RegExp(`${boundary(options)}${v6}${boundary(options)}`, "g");
|
|
76
|
-
|
|
77
|
-
// src/is-ip/is-ip.ts
|
|
78
|
-
function isIP(value) {
|
|
79
|
-
return ipRegex({
|
|
80
|
-
exact: true
|
|
81
|
-
}).test(value);
|
|
82
|
-
}
|
|
83
|
-
__name(isIP, "isIP");
|
|
84
|
-
function isIPv6(value) {
|
|
85
|
-
return ipRegex.v6({
|
|
86
|
-
exact: true
|
|
87
|
-
}).test(value);
|
|
88
|
-
}
|
|
89
|
-
__name(isIPv6, "isIPv6");
|
|
90
|
-
function isIPv4(value) {
|
|
91
|
-
return ipRegex.v4({
|
|
92
|
-
exact: true
|
|
93
|
-
}).test(value);
|
|
94
|
-
}
|
|
95
|
-
__name(isIPv4, "isIPv4");
|
|
96
|
-
function ipVersion(value) {
|
|
97
|
-
return isIP(value) ? isIPv6(value) ? 6 : 4 : void 0;
|
|
98
|
-
}
|
|
99
|
-
__name(ipVersion, "ipVersion");
|
|
100
|
-
export {
|
|
101
|
-
IdLogger,
|
|
102
|
-
dump,
|
|
103
|
-
ipVersion,
|
|
104
|
-
isIP,
|
|
105
|
-
isIPv4,
|
|
106
|
-
isIPv6
|
|
107
|
-
};
|
|
12
|
+
`.replaceAll(/\s*\/\/.*$/gm,"").replaceAll(`
|
|
13
|
+
`,"").trim(),a=new RegExp(`(?:^${n}$)|(?:^${x}$)`),h=new RegExp(`^${n}$`),p=new RegExp(`^${x}$`),c=$(e=>e&&e.exact?a:new RegExp(`(?:${i(e)}${n}${i(e)})|(?:${i(e)}${x}${i(e)})`,"g"),"ipRegex");c.v4=e=>e&&e.exact?h:new RegExp(`${i(e)}${n}${i(e)}`,"g");c.v6=e=>e&&e.exact?p:new RegExp(`${i(e)}${x}${i(e)}`,"g");function l(e){return c({exact:!0}).test(e)}$(l,"isIP");function w(e){return c.v6({exact:!0}).test(e)}$(w,"isIPv6");function N(e){return c.v4({exact:!0}).test(e)}$(N,"isIPv4");function P(e){return l(e)?w(e)?6:4:void 0}$(P,"ipVersion");export{s as IdLogger,m as dump,P as ipVersion,l as isIP,N as isIPv4,w as isIPv6};
|
|
108
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/dump.ts","../../src/IdLogger.ts","../../src/is-ip/ip-regex.ts","../../src/is-ip/is-ip.ts"],"sourcesContent":["export const dump = (object: unknown) => {\n const cache: unknown[] = []\n return JSON.stringify(\n object,\n (key, value) => {\n if (typeof value === 'object' && value !== null) {\n // Duplicate reference found, discard key\n if (cache.includes(value)) {\n return '[circular]'\n }\n\n // Store value in our collection\n cache.push(value)\n }\n return value\n },\n 2,\n )\n}\n","import { getFunctionName, Logger } from '@xylabs/logger'\n\n/** @deprecated use from @xylabs/logger instead */\nexport class IdLogger implements Logger {\n private _id?: () => string\n private _logger: Logger\n\n constructor(logger: Logger, id?: () => string) {\n this._logger = logger\n this._id = id\n }\n\n set id(id: string) {\n this._id = () => id\n }\n\n debug(message?: unknown) {\n this._logger?.debug(this.generate(message, getFunctionName(3)))\n }\n error(message?: unknown) {\n this._logger?.error(this.generate(message, getFunctionName(3)))\n }\n info(message?: unknown) {\n this._logger?.info(this.generate(message, getFunctionName(3)))\n }\n log(message?: unknown) {\n this._logger?.log(this.generate(message, getFunctionName(3)))\n }\n warn(message?: unknown) {\n this._logger?.warn(this.generate(message, getFunctionName(3)))\n }\n\n private generate(message?: unknown, tag?: string) {\n return `${tag} ${this._id ? `[${this._id}] ` : ''}${\n typeof message === 'string' ? message\n : typeof message === 'object' ? JSON.stringify(message, undefined, 2)\n : `${message}`\n }`\n }\n}\n","const word = String.raw`[a-fA-F\\d:]`\n\nexport interface Options {\n readonly exact?: boolean\n readonly includeBoundaries?: boolean\n}\n\nconst boundary = (options: Options) => (options && options.includeBoundaries ? `(?:(?<=\\\\s|^)(?=${word})|(?<=${word})(?=\\\\s|$))` : '')\n\nconst v4 = String.raw`(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}`\n\nconst v6segment = String.raw`[a-fA-F\\d]{1,4}`\n\nconst v6 = `\n(?:\n(?:${v6segment}:){7}(?:${v6segment}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8\n(?:${v6segment}:){6}(?:${v4}|:${v6segment}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4\n(?:${v6segment}:){5}(?::${v4}|(?::${v6segment}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4\n(?:${v6segment}:){4}(?:(?::${v6segment}){0,1}:${v4}|(?::${v6segment}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4\n(?:${v6segment}:){3}(?:(?::${v6segment}){0,2}:${v4}|(?::${v6segment}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4\n(?:${v6segment}:){2}(?:(?::${v6segment}){0,3}:${v4}|(?::${v6segment}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4\n(?:${v6segment}:){1}(?:(?::${v6segment}){0,4}:${v4}|(?::${v6segment}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4\n(?::(?:(?::${v6segment}){0,5}:${v4}|(?::${v6segment}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4\n)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1\n`\n .replaceAll(/\\s*\\/\\/.*$/gm, '')\n .replaceAll('\\n', '')\n .trim()\n\n// Pre-compile only the exact regexes because adding a global flag make regexes stateful\nconst v46Exact = new RegExp(`(?:^${v4}$)|(?:^${v6}$)`)\nconst v4exact = new RegExp(`^${v4}$`)\nconst v6exact = new RegExp(`^${v6}$`)\n\nexport const ipRegex = (options: Options) =>\n options && options.exact ?\n v46Exact\n : new RegExp(`(?:${boundary(options)}${v4}${boundary(options)})|(?:${boundary(options)}${v6}${boundary(options)})`, 'g')\n\nipRegex.v4 = (options: Options) => (options && options.exact ? v4exact : new RegExp(`${boundary(options)}${v4}${boundary(options)}`, 'g'))\nipRegex.v6 = (options: Options) => (options && options.exact ? v6exact : new RegExp(`${boundary(options)}${v6}${boundary(options)}`, 'g'))\n","import { ipRegex } from './ip-regex'\n\nexport function isIP(value: string) {\n return ipRegex({ exact: true }).test(value)\n}\n\nexport function isIPv6(value: string) {\n return ipRegex.v6({ exact: true }).test(value)\n}\n\nexport function isIPv4(value: string) {\n return ipRegex.v4({ exact: true }).test(value)\n}\n\nexport function ipVersion(value: string) {\n return (\n isIP(value) ?\n isIPv6(value) ? 6\n : 4\n : undefined\n )\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/dump.ts","../../src/IdLogger.ts","../../src/is-ip/ip-regex.ts","../../src/is-ip/is-ip.ts"],"sourcesContent":["export const dump = (object: unknown) => {\n const cache: unknown[] = []\n return JSON.stringify(\n object,\n (key, value) => {\n if (typeof value === 'object' && value !== null) {\n // Duplicate reference found, discard key\n if (cache.includes(value)) {\n return '[circular]'\n }\n\n // Store value in our collection\n cache.push(value)\n }\n return value\n },\n 2,\n )\n}\n","import { getFunctionName, Logger } from '@xylabs/logger'\n\n/** @deprecated use from @xylabs/logger instead */\nexport class IdLogger implements Logger {\n private _id?: () => string\n private _logger: Logger\n\n constructor(logger: Logger, id?: () => string) {\n this._logger = logger\n this._id = id\n }\n\n set id(id: string) {\n this._id = () => id\n }\n\n debug(message?: unknown) {\n this._logger?.debug(this.generate(message, getFunctionName(3)))\n }\n error(message?: unknown) {\n this._logger?.error(this.generate(message, getFunctionName(3)))\n }\n info(message?: unknown) {\n this._logger?.info(this.generate(message, getFunctionName(3)))\n }\n log(message?: unknown) {\n this._logger?.log(this.generate(message, getFunctionName(3)))\n }\n warn(message?: unknown) {\n this._logger?.warn(this.generate(message, getFunctionName(3)))\n }\n\n private generate(message?: unknown, tag?: string) {\n return `${tag} ${this._id ? `[${this._id}] ` : ''}${\n typeof message === 'string' ? message\n : typeof message === 'object' ? JSON.stringify(message, undefined, 2)\n : `${message}`\n }`\n }\n}\n","const word = String.raw`[a-fA-F\\d:]`\n\nexport interface Options {\n readonly exact?: boolean\n readonly includeBoundaries?: boolean\n}\n\nconst boundary = (options: Options) => (options && options.includeBoundaries ? `(?:(?<=\\\\s|^)(?=${word})|(?<=${word})(?=\\\\s|$))` : '')\n\nconst v4 = String.raw`(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}`\n\nconst v6segment = String.raw`[a-fA-F\\d]{1,4}`\n\nconst v6 = `\n(?:\n(?:${v6segment}:){7}(?:${v6segment}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8\n(?:${v6segment}:){6}(?:${v4}|:${v6segment}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4\n(?:${v6segment}:){5}(?::${v4}|(?::${v6segment}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4\n(?:${v6segment}:){4}(?:(?::${v6segment}){0,1}:${v4}|(?::${v6segment}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4\n(?:${v6segment}:){3}(?:(?::${v6segment}){0,2}:${v4}|(?::${v6segment}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4\n(?:${v6segment}:){2}(?:(?::${v6segment}){0,3}:${v4}|(?::${v6segment}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4\n(?:${v6segment}:){1}(?:(?::${v6segment}){0,4}:${v4}|(?::${v6segment}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4\n(?::(?:(?::${v6segment}){0,5}:${v4}|(?::${v6segment}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4\n)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1\n`\n .replaceAll(/\\s*\\/\\/.*$/gm, '')\n .replaceAll('\\n', '')\n .trim()\n\n// Pre-compile only the exact regexes because adding a global flag make regexes stateful\nconst v46Exact = new RegExp(`(?:^${v4}$)|(?:^${v6}$)`)\nconst v4exact = new RegExp(`^${v4}$`)\nconst v6exact = new RegExp(`^${v6}$`)\n\nexport const ipRegex = (options: Options) =>\n options && options.exact ?\n v46Exact\n : new RegExp(`(?:${boundary(options)}${v4}${boundary(options)})|(?:${boundary(options)}${v6}${boundary(options)})`, 'g')\n\nipRegex.v4 = (options: Options) => (options && options.exact ? v4exact : new RegExp(`${boundary(options)}${v4}${boundary(options)}`, 'g'))\nipRegex.v6 = (options: Options) => (options && options.exact ? v6exact : new RegExp(`${boundary(options)}${v6}${boundary(options)}`, 'g'))\n","import { ipRegex } from './ip-regex'\n\nexport function isIP(value: string) {\n return ipRegex({ exact: true }).test(value)\n}\n\nexport function isIPv6(value: string) {\n return ipRegex.v6({ exact: true }).test(value)\n}\n\nexport function isIPv4(value: string) {\n return ipRegex.v4({ exact: true }).test(value)\n}\n\nexport function ipVersion(value: string) {\n return (\n isIP(value) ?\n isIPv6(value) ? 6\n : 4\n : undefined\n )\n}\n"],"mappings":"+EAAO,IAAMA,EAAOC,EAACC,GAAAA,CACnB,IAAMC,EAAmB,CAAA,EACzB,OAAOC,KAAKC,UACVH,EACA,CAACI,EAAKC,IAAAA,CACJ,GAAI,OAAOA,GAAU,UAAYA,IA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,EAAKC,EAAa,CAChC,OAAOC,EAAQ,CAAEC,MAAO,EAAK,CAAA,EAAGC,KAAKH,CAAAA,CACvC,CAFgBD,EAAAA,EAAAA,QAIT,SAASK,EAAOJ,EAAa,CAClC,OAAOC,EAAQI,GAAG,CAAEH,MAAO,EAAK,CAAA,EAAGC,KAAKH,CAAAA,CAC1C,CAFgBI,EAAAA,EAAAA,UAIT,SAASE,EAAON,EAAa,CAClC,OAAOC,EAAQM,GAAG,CAAEL,MAAO,EAAK,CAAA,EAAGC,KAAKH,CAAAA,CAC1C,CAFgBM,EAAAA,EAAAA,UAIT,SAASE,EAAUR,EAAa,CACrC,OACED,EAAKC,CAAAA,EACHI,EAAOJ,CAAAA,EAAS,EACd,EACFS,MAEN,CAPgBD,EAAAA,EAAAA","names":["dump","__name","object","cache","JSON","stringify","key","value","includes","push","getFunctionName","IdLogger","_id","_logger","constructor","logger","id","debug","message","generate","getFunctionName","error","info","log","warn","tag","JSON","stringify","undefined","word","String","raw","boundary","__name","options","includeBoundaries","v4","v6segment","v6","replaceAll","trim","v46Exact","RegExp","v4exact","v6exact","ipRegex","exact","isIP","value","ipRegex","exact","test","isIPv6","v6","isIPv4","v4","ipVersion","undefined"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAGxD,qBAAa,QAAS,YAAW,MAAM;IACrC,OAAO,CAAC,GAAG,CAAC,CAAc;IAC1B,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,MAAM;IAK7C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAEhB;IAED,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAGtB,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO;IAGrB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAItB,OAAO,CAAC,QAAQ;CAOjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAGxD,qBAAa,QAAS,YAAW,MAAM;IACrC,OAAO,CAAC,GAAG,CAAC,CAAc;IAC1B,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,MAAM;IAK7C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAEhB;IAED,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAGtB,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO;IAGrB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAItB,OAAO,CAAC,QAAQ;CAOjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"IdLogger.d.ts","sourceRoot":"","sources":["../../src/IdLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAGxD,qBAAa,QAAS,YAAW,MAAM;IACrC,OAAO,CAAC,GAAG,CAAC,CAAc;IAC1B,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,MAAM;IAK7C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAEhB;IAED,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO;IAGvB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAGtB,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO;IAGrB,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO;IAItB,OAAO,CAAC,QAAQ;CAOjB"}
|
package/dist/neutral/index.cjs
CHANGED
|
@@ -1,129 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
|
|
21
|
-
// src/index.ts
|
|
22
|
-
var src_exports = {};
|
|
23
|
-
__export(src_exports, {
|
|
24
|
-
IdLogger: () => IdLogger,
|
|
25
|
-
dump: () => dump,
|
|
26
|
-
ipVersion: () => ipVersion,
|
|
27
|
-
isIP: () => isIP,
|
|
28
|
-
isIPv4: () => isIPv4,
|
|
29
|
-
isIPv6: () => isIPv6
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(src_exports);
|
|
32
|
-
|
|
33
|
-
// src/dump.ts
|
|
34
|
-
var dump = /* @__PURE__ */ __name((object) => {
|
|
35
|
-
const cache = [];
|
|
36
|
-
return JSON.stringify(object, (key, value) => {
|
|
37
|
-
if (typeof value === "object" && value !== null) {
|
|
38
|
-
if (cache.includes(value)) {
|
|
39
|
-
return "[circular]";
|
|
40
|
-
}
|
|
41
|
-
cache.push(value);
|
|
42
|
-
}
|
|
43
|
-
return value;
|
|
44
|
-
}, 2);
|
|
45
|
-
}, "dump");
|
|
46
|
-
|
|
47
|
-
// src/IdLogger.ts
|
|
48
|
-
var import_logger = require("@xylabs/logger");
|
|
49
|
-
var IdLogger = class {
|
|
50
|
-
static {
|
|
51
|
-
__name(this, "IdLogger");
|
|
52
|
-
}
|
|
53
|
-
_id;
|
|
54
|
-
_logger;
|
|
55
|
-
constructor(logger, id) {
|
|
56
|
-
this._logger = logger;
|
|
57
|
-
this._id = id;
|
|
58
|
-
}
|
|
59
|
-
set id(id) {
|
|
60
|
-
this._id = () => id;
|
|
61
|
-
}
|
|
62
|
-
debug(message) {
|
|
63
|
-
this._logger?.debug(this.generate(message, (0, import_logger.getFunctionName)(3)));
|
|
64
|
-
}
|
|
65
|
-
error(message) {
|
|
66
|
-
this._logger?.error(this.generate(message, (0, import_logger.getFunctionName)(3)));
|
|
67
|
-
}
|
|
68
|
-
info(message) {
|
|
69
|
-
this._logger?.info(this.generate(message, (0, import_logger.getFunctionName)(3)));
|
|
70
|
-
}
|
|
71
|
-
log(message) {
|
|
72
|
-
this._logger?.log(this.generate(message, (0, import_logger.getFunctionName)(3)));
|
|
73
|
-
}
|
|
74
|
-
warn(message) {
|
|
75
|
-
this._logger?.warn(this.generate(message, (0, import_logger.getFunctionName)(3)));
|
|
76
|
-
}
|
|
77
|
-
generate(message, tag) {
|
|
78
|
-
return `${tag} ${this._id ? `[${this._id}] ` : ""}${typeof message === "string" ? message : typeof message === "object" ? JSON.stringify(message, void 0, 2) : `${message}`}`;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// src/is-ip/ip-regex.ts
|
|
83
|
-
var word = String.raw`[a-fA-F\d:]`;
|
|
84
|
-
var boundary = /* @__PURE__ */ __name((options) => options && options.includeBoundaries ? `(?:(?<=\\s|^)(?=${word})|(?<=${word})(?=\\s|$))` : "", "boundary");
|
|
85
|
-
var v4 = String.raw`(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}`;
|
|
86
|
-
var v6segment = String.raw`[a-fA-F\d]{1,4}`;
|
|
87
|
-
var v6 = `
|
|
1
|
+
"use strict";var s=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var $=(e,t)=>s(e,"name",{value:t,configurable:!0});var m=(e,t)=>{for(var i in t)s(e,i,{get:t[i],enumerable:!0})},R=(e,t,i,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let x of w(t))!_.call(e,x)&&x!==i&&s(e,x,{get:()=>t[x],enumerable:!(c=l(t,x))||c.enumerable});return e};var v=e=>R(s({},"__esModule",{value:!0}),e);var N={};m(N,{IdLogger:()=>f,dump:()=>y,ipVersion:()=>F,isIP:()=>h,isIPv4:()=>S,isIPv6:()=>p});module.exports=v(N);var y=$(e=>{let t=[];return JSON.stringify(e,(i,c)=>{if(typeof c=="object"&&c!==null){if(t.includes(c))return"[circular]";t.push(c)}return c},2)},"dump");var o=require("@xylabs/logger");var f=class{static{$(this,"IdLogger")}_id;_logger;constructor(t,i){this._logger=t,this._id=i}set id(t){this._id=()=>t}debug(t){this._logger?.debug(this.generate(t,(0,o.getFunctionName)(3)))}error(t){this._logger?.error(this.generate(t,(0,o.getFunctionName)(3)))}info(t){this._logger?.info(this.generate(t,(0,o.getFunctionName)(3)))}log(t){this._logger?.log(this.generate(t,(0,o.getFunctionName)(3)))}warn(t){this._logger?.warn(this.generate(t,(0,o.getFunctionName)(3)))}generate(t,i){return`${i} ${this._id?`[${this._id}] `:""}${typeof t=="string"?t:typeof t=="object"?JSON.stringify(t,void 0,2):`${t}`}`}};var a=String.raw`[a-fA-F\d:]`,g=$(e=>e&&e.includeBoundaries?`(?:(?<=\\s|^)(?=${a})|(?<=${a})(?=\\s|$))`:"","boundary"),n=String.raw`(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}`,r=String.raw`[a-fA-F\d]{1,4}`,u=`
|
|
88
2
|
(?:
|
|
89
|
-
(?:${
|
|
90
|
-
(?:${
|
|
91
|
-
(?:${
|
|
92
|
-
(?:${
|
|
93
|
-
(?:${
|
|
94
|
-
(?:${
|
|
95
|
-
(?:${
|
|
96
|
-
(?::(?:(?::${
|
|
3
|
+
(?:${r}:){7}(?:${r}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
|
|
4
|
+
(?:${r}:){6}(?:${n}|:${r}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
|
|
5
|
+
(?:${r}:){5}(?::${n}|(?::${r}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
|
|
6
|
+
(?:${r}:){4}(?:(?::${r}){0,1}:${n}|(?::${r}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
|
|
7
|
+
(?:${r}:){3}(?:(?::${r}){0,2}:${n}|(?::${r}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
|
|
8
|
+
(?:${r}:){2}(?:(?::${r}){0,3}:${n}|(?::${r}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
|
|
9
|
+
(?:${r}:){1}(?:(?::${r}){0,4}:${n}|(?::${r}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
|
|
10
|
+
(?::(?:(?::${r}){0,5}:${n}|(?::${r}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
|
|
97
11
|
)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
|
|
98
|
-
`.replaceAll(/\s*\/\/.*$/gm,
|
|
99
|
-
|
|
100
|
-
var v4exact = new RegExp(`^${v4}$`);
|
|
101
|
-
var v6exact = new RegExp(`^${v6}$`);
|
|
102
|
-
var ipRegex = /* @__PURE__ */ __name((options) => options && options.exact ? v46Exact : new RegExp(`(?:${boundary(options)}${v4}${boundary(options)})|(?:${boundary(options)}${v6}${boundary(options)})`, "g"), "ipRegex");
|
|
103
|
-
ipRegex.v4 = (options) => options && options.exact ? v4exact : new RegExp(`${boundary(options)}${v4}${boundary(options)}`, "g");
|
|
104
|
-
ipRegex.v6 = (options) => options && options.exact ? v6exact : new RegExp(`${boundary(options)}${v6}${boundary(options)}`, "g");
|
|
105
|
-
|
|
106
|
-
// src/is-ip/is-ip.ts
|
|
107
|
-
function isIP(value) {
|
|
108
|
-
return ipRegex({
|
|
109
|
-
exact: true
|
|
110
|
-
}).test(value);
|
|
111
|
-
}
|
|
112
|
-
__name(isIP, "isIP");
|
|
113
|
-
function isIPv6(value) {
|
|
114
|
-
return ipRegex.v6({
|
|
115
|
-
exact: true
|
|
116
|
-
}).test(value);
|
|
117
|
-
}
|
|
118
|
-
__name(isIPv6, "isIPv6");
|
|
119
|
-
function isIPv4(value) {
|
|
120
|
-
return ipRegex.v4({
|
|
121
|
-
exact: true
|
|
122
|
-
}).test(value);
|
|
123
|
-
}
|
|
124
|
-
__name(isIPv4, "isIPv4");
|
|
125
|
-
function ipVersion(value) {
|
|
126
|
-
return isIP(value) ? isIPv6(value) ? 6 : 4 : void 0;
|
|
127
|
-
}
|
|
128
|
-
__name(ipVersion, "ipVersion");
|
|
12
|
+
`.replaceAll(/\s*\/\/.*$/gm,"").replaceAll(`
|
|
13
|
+
`,"").trim(),E=new RegExp(`(?:^${n}$)|(?:^${u}$)`),b=new RegExp(`^${n}$`),A=new RegExp(`^${u}$`),d=$(e=>e&&e.exact?E:new RegExp(`(?:${g(e)}${n}${g(e)})|(?:${g(e)}${u}${g(e)})`,"g"),"ipRegex");d.v4=e=>e&&e.exact?b:new RegExp(`${g(e)}${n}${g(e)}`,"g");d.v6=e=>e&&e.exact?A:new RegExp(`${g(e)}${u}${g(e)}`,"g");function h(e){return d({exact:!0}).test(e)}$(h,"isIP");function p(e){return d.v6({exact:!0}).test(e)}$(p,"isIPv6");function S(e){return d.v4({exact:!0}).test(e)}$(S,"isIPv4");function F(e){return h(e)?p(e)?6:4:void 0}$(F,"ipVersion");
|
|
129
14
|
//# sourceMappingURL=index.cjs.map
|