ip-utilties 3.0.4 → 3.1.1
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/README.md +3 -4
- package/package.json +12 -7
- package/src/ip.mjs +25 -12
- package/types/ip.d.mts +8 -0
package/README.md
CHANGED
|
@@ -9,18 +9,17 @@
|
|
|
9
9
|
[](http://commitizen.github.io/cz-cli/)
|
|
10
10
|
[](https://snyk.io/test/github/arlac77/ip-utilties)
|
|
11
11
|
|
|
12
|
-
ip
|
|
12
|
+
ip-v4/v6 utility functions
|
|
13
13
|
|
|
14
14
|
## Three different representations
|
|
15
15
|
|
|
16
16
|
```javascript
|
|
17
17
|
const ip4AsString = "10.0.0.1";
|
|
18
18
|
const ip4AsArray = new Uint8Array([10,0,0,1]);
|
|
19
|
-
const ip4or6AsBigInt = 10n <<
|
|
19
|
+
const ip4or6AsBigInt = 10n << 24n | 1n;
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
encodeIPv4("10.0.0.1") // -> 10n << 14n | 1n;
|
|
22
|
+
encodeIPv4("10.0.0.1") // -> 10n << 24n | 1n;
|
|
24
23
|
```
|
|
25
24
|
|
|
26
25
|
# API
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ip-utilties",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
7
7
|
},
|
|
8
|
-
"packageManager": "npm@11.
|
|
8
|
+
"packageManager": "npm@11.16.0",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"default": "./src/ip.mjs"
|
|
@@ -40,15 +40,20 @@
|
|
|
40
40
|
"lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule --target esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"ava": "^
|
|
44
|
-
"browser-ava": "^2.3.
|
|
43
|
+
"ava": "^8.0.1",
|
|
44
|
+
"browser-ava": "^2.3.62",
|
|
45
45
|
"c8": "^11.0.0",
|
|
46
46
|
"documentation": "^14.0.3",
|
|
47
|
-
"semantic-release": "^25.0.
|
|
48
|
-
"typescript": "^6.0.
|
|
47
|
+
"semantic-release": "^25.0.5",
|
|
48
|
+
"typescript": "^6.0.3"
|
|
49
|
+
},
|
|
50
|
+
"overrides": {
|
|
51
|
+
"c8": {
|
|
52
|
+
"yargs": "^18.0.0"
|
|
53
|
+
}
|
|
49
54
|
},
|
|
50
55
|
"engines": {
|
|
51
|
-
"node": ">=
|
|
56
|
+
"node": ">=26.2.0"
|
|
52
57
|
},
|
|
53
58
|
"repository": {
|
|
54
59
|
"type": "git",
|
package/src/ip.mjs
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Address familiy IPv4
|
|
3
|
+
*/
|
|
4
|
+
export const FAMILY_IPV4 = "IPv4";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Address familiy IPv6
|
|
8
|
+
*/
|
|
9
|
+
export const FAMILY_IPV6 = "IPv6";
|
|
10
|
+
|
|
1
11
|
const ipv4 = {
|
|
2
|
-
name:
|
|
12
|
+
name: FAMILY_IPV4,
|
|
3
13
|
factory: Uint8Array,
|
|
4
|
-
normalize:
|
|
14
|
+
normalize: address => address,
|
|
5
15
|
separator: ".",
|
|
6
16
|
bitLength: 32,
|
|
7
17
|
segments: 4,
|
|
@@ -11,7 +21,7 @@ const ipv4 = {
|
|
|
11
21
|
};
|
|
12
22
|
|
|
13
23
|
const ipv6 = {
|
|
14
|
-
name:
|
|
24
|
+
name: FAMILY_IPV6,
|
|
15
25
|
factory: Uint16Array,
|
|
16
26
|
normalize(address) {
|
|
17
27
|
const parts = address.split(":");
|
|
@@ -32,7 +42,7 @@ const ipv6 = {
|
|
|
32
42
|
|
|
33
43
|
/**
|
|
34
44
|
* Encode ipv4 or ipv6 address into number array.
|
|
35
|
-
* @param {string|number[]} address
|
|
45
|
+
* @param {string|number[]} address
|
|
36
46
|
* @returns number[]
|
|
37
47
|
*/
|
|
38
48
|
export function encodeIP(address) {
|
|
@@ -42,7 +52,7 @@ export function encodeIP(address) {
|
|
|
42
52
|
|
|
43
53
|
/**
|
|
44
54
|
* Encode ipv6 address into number array.
|
|
45
|
-
* @param {string|number[]|bigint} address
|
|
55
|
+
* @param {string|number[]|bigint} address
|
|
46
56
|
* @returns number[]
|
|
47
57
|
*/
|
|
48
58
|
export function encodeIPv6(address) {
|
|
@@ -51,7 +61,7 @@ export function encodeIPv6(address) {
|
|
|
51
61
|
|
|
52
62
|
/**
|
|
53
63
|
* Encode ipv6 address into number array.
|
|
54
|
-
* @param {string|number[]|bigint} address
|
|
64
|
+
* @param {string|number[]|bigint} address
|
|
55
65
|
* @returns number[]
|
|
56
66
|
*/
|
|
57
67
|
export function encodeIPv4(address) {
|
|
@@ -229,7 +239,10 @@ export function rangeIP(address, prefix, lowerAdd = 0, upperReduce = 0) {
|
|
|
229
239
|
|
|
230
240
|
export function matchPrefixIP(prefix, length, address) {
|
|
231
241
|
const family = _family(address);
|
|
232
|
-
return
|
|
242
|
+
return (
|
|
243
|
+
family !== undefined &&
|
|
244
|
+
_prefix(family, address, length) === _prefix(family, prefix, length)
|
|
245
|
+
);
|
|
233
246
|
}
|
|
234
247
|
|
|
235
248
|
export function normalizeCIDR(address) {
|
|
@@ -332,11 +345,11 @@ export function hasWellKnownSubnet(address) {
|
|
|
332
345
|
/*
|
|
333
346
|
* https://www.iana.org/assignments/ipv6-multicast-addresses/ipv6-multicast-addresses.xhtml
|
|
334
347
|
*/
|
|
335
|
-
export const IPV6_NODE_LOCAL_ALL_NODES
|
|
336
|
-
export const IPV6_NODE_LOCAL_ALL_ROUTERS
|
|
337
|
-
export const IPV6_LINK_LOCAL_ALL_NODES
|
|
338
|
-
export const IPV6_LINK_LOCAL_ALL_ROUTERS
|
|
339
|
-
export const IPV6_SITE_LOCAL_ALL_ROUTERS
|
|
348
|
+
export const IPV6_NODE_LOCAL_ALL_NODES = _encode(ipv6, "ff01::1");
|
|
349
|
+
export const IPV6_NODE_LOCAL_ALL_ROUTERS = _encode(ipv6, "ff01::2");
|
|
350
|
+
export const IPV6_LINK_LOCAL_ALL_NODES = _encode(ipv6, "ff02::1");
|
|
351
|
+
export const IPV6_LINK_LOCAL_ALL_ROUTERS = _encode(ipv6, "ff02::2");
|
|
352
|
+
export const IPV6_SITE_LOCAL_ALL_ROUTERS = _encode(ipv6, "ff05::2");
|
|
340
353
|
export const IPV6_SITE_LOCAL_ALL_DHCP_SERVERS = _encode(ipv6, "ff05::1:3");
|
|
341
354
|
|
|
342
355
|
export const IPV4_LOCALHOST = _encode(ipv4, "127.0.0.1");
|
package/types/ip.d.mts
CHANGED
|
@@ -44,6 +44,14 @@ export function isLocalhost(address: any): boolean;
|
|
|
44
44
|
export function isLinkLocal(address: any): boolean;
|
|
45
45
|
export function isUniqueLocal(address: any): boolean;
|
|
46
46
|
export function hasWellKnownSubnet(address: any): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Address familiy IPv4
|
|
49
|
+
*/
|
|
50
|
+
export const FAMILY_IPV4: "IPv4";
|
|
51
|
+
/**
|
|
52
|
+
* Address familiy IPv6
|
|
53
|
+
*/
|
|
54
|
+
export const FAMILY_IPV6: "IPv6";
|
|
47
55
|
export const IPV6_NODE_LOCAL_ALL_NODES: any;
|
|
48
56
|
export const IPV6_NODE_LOCAL_ALL_ROUTERS: any;
|
|
49
57
|
export const IPV6_LINK_LOCAL_ALL_NODES: any;
|