ip-utilties 1.2.0 → 1.3.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/package.json +3 -2
- package/src/ip.mjs +9 -8
- package/types/ip.d.mts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ip-utilties",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"ipv4",
|
|
17
17
|
"ipv6",
|
|
18
18
|
"network",
|
|
19
|
-
"subnet"
|
|
19
|
+
"subnet",
|
|
20
|
+
"cidr"
|
|
20
21
|
],
|
|
21
22
|
"contributors": [
|
|
22
23
|
{
|
package/src/ip.mjs
CHANGED
|
@@ -51,9 +51,7 @@ function _encode(family, address) {
|
|
|
51
51
|
const res = new family.factory(family.segments);
|
|
52
52
|
|
|
53
53
|
let i = 0;
|
|
54
|
-
for (const segment of family
|
|
55
|
-
.normalize(address)
|
|
56
|
-
.split(family.separator)) {
|
|
54
|
+
for (const segment of family.normalize(address).split(family.separator)) {
|
|
57
55
|
res[i++] = parseInt(segment, family.base);
|
|
58
56
|
}
|
|
59
57
|
|
|
@@ -148,7 +146,7 @@ export function isIPv6(address) {
|
|
|
148
146
|
* @return {string|undefined}
|
|
149
147
|
*/
|
|
150
148
|
export function familyIP(address) {
|
|
151
|
-
return _family(address)?.name
|
|
149
|
+
return _family(address)?.name;
|
|
152
150
|
}
|
|
153
151
|
|
|
154
152
|
function _family(address) {
|
|
@@ -162,8 +160,7 @@ function _is(family, address) {
|
|
|
162
160
|
|
|
163
161
|
case "object":
|
|
164
162
|
return (
|
|
165
|
-
address instanceof family.factory &&
|
|
166
|
-
address.length === family.segments
|
|
163
|
+
address instanceof family.factory && address.length === family.segments
|
|
167
164
|
);
|
|
168
165
|
}
|
|
169
166
|
|
|
@@ -203,8 +200,7 @@ export function prefixIP(address, length) {
|
|
|
203
200
|
|
|
204
201
|
function _prefix(family, address, length) {
|
|
205
202
|
return (
|
|
206
|
-
_asBigInt(family, address) &
|
|
207
|
-
(-1n << BigInt(family.bitLength - length))
|
|
203
|
+
_asBigInt(family, address) & (-1n << BigInt(family.bitLength - length))
|
|
208
204
|
);
|
|
209
205
|
}
|
|
210
206
|
|
|
@@ -218,6 +214,11 @@ export function rangeIP(address, prefix, lowerAdd = 0, upperReduce = 0) {
|
|
|
218
214
|
];
|
|
219
215
|
}
|
|
220
216
|
|
|
217
|
+
export function matchPrefixIP(prefix, length, address) {
|
|
218
|
+
const family = _family(address);
|
|
219
|
+
return _prefix(family, address, length) === _prefix(family, prefix, length);
|
|
220
|
+
}
|
|
221
|
+
|
|
221
222
|
export function normalizeCIDR(address) {
|
|
222
223
|
let [prefix, prefixLength] = address.split(/\//);
|
|
223
224
|
let longPrefix;
|
package/types/ip.d.mts
CHANGED
|
@@ -15,6 +15,7 @@ export function familyIP(address: string | Uint8Array | Uint16Array): string | u
|
|
|
15
15
|
export function asBigInt(address: any): any;
|
|
16
16
|
export function prefixIP(address: any, length: any): string;
|
|
17
17
|
export function rangeIP(address: any, prefix: any, lowerAdd?: number, upperReduce?: number): any[];
|
|
18
|
+
export function matchPrefixIP(prefix: any, length: any, address: any): boolean;
|
|
18
19
|
export function normalizeCIDR(address: any): {
|
|
19
20
|
longPrefix?: undefined;
|
|
20
21
|
prefix?: undefined;
|