@ztimson/utils 0.28.6 → 0.28.7
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/index.cjs +10 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +10 -0
- package/dist/index.mjs.map +1 -1
- package/dist/misc.d.ts +7 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1863,6 +1863,15 @@ ${opts.message || this.desc}`;
|
|
|
1863
1863
|
if (!email) return "";
|
|
1864
1864
|
return `https://www.gravatar.com/avatar/${md5(email)}?d=${def}`;
|
|
1865
1865
|
}
|
|
1866
|
+
function matchesCidr(ip, cidr) {
|
|
1867
|
+
if (!cidr) return true;
|
|
1868
|
+
if (!ip) return false;
|
|
1869
|
+
if (!cidr?.includes("/")) return ip === cidr;
|
|
1870
|
+
const [range, bits] = cidr.split("/");
|
|
1871
|
+
const mask = ~(2 ** (32 - parseInt(bits)) - 1);
|
|
1872
|
+
const ipToInt = (str) => str.split(".").reduce((int, octet) => (int << 8) + parseInt(octet), 0) >>> 0;
|
|
1873
|
+
return (ipToInt(ip) & mask) === (ipToInt(range) & mask);
|
|
1874
|
+
}
|
|
1866
1875
|
function ipV6ToV4(ip) {
|
|
1867
1876
|
if (!ip) return null;
|
|
1868
1877
|
const ipv4 = ip.split(":").splice(-1)[0];
|
|
@@ -2798,6 +2807,7 @@ ${err.message || err.toString()}`);
|
|
|
2798
2807
|
exports2.makeArray = makeArray;
|
|
2799
2808
|
exports2.makeUnique = makeUnique;
|
|
2800
2809
|
exports2.matchAll = matchAll;
|
|
2810
|
+
exports2.matchesCidr = matchesCidr;
|
|
2801
2811
|
exports2.md5 = md5;
|
|
2802
2812
|
exports2.mixin = mixin;
|
|
2803
2813
|
exports2.month = month;
|