cidr-block 1.0.0 → 1.0.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.
@@ -1 +1,150 @@
1
- const hello = 'world';export{hello};//# sourceMappingURL=index.esm.js.map
1
+ /**
2
+ * The numerical maximum size an IPv4 address can be
3
+ */
4
+ const IPv4_MAX = 2n ** 32n;
5
+ /**
6
+ * The numerical maximum size an IPv6 address can be
7
+ */
8
+ const IPv6_MAX = 2n ** 64n;class InvalidIpAddressError extends Error {
9
+ constructor(badIp) {
10
+ super(`${badIp} is not a valid IP address.`);
11
+ }
12
+ }
13
+ class InvalidCidrError extends Error {
14
+ constructor(badCidr) {
15
+ super(`${badCidr} is not a valid cidr block or range.`);
16
+ }
17
+ }const MAX_OCTET_SIZE = 255n;
18
+ /**
19
+ * Representation of an IPv4 address. Provides various utility methods like equality
20
+ * checking.
21
+ *
22
+ * @remarks
23
+ * Direct instantiation should be avoided; use {@link ipv4.address|ipv4.address()} instead.
24
+ */
25
+ class Ipv4Address {
26
+ address;
27
+ constructor(address) {
28
+ this.address = fromString(address);
29
+ }
30
+ /**
31
+ * @public
32
+ * @returns the IPv4 address as a string
33
+ */
34
+ toString() {
35
+ return toString(this.address);
36
+ }
37
+ /**
38
+ * Compares if two IP address are the same.
39
+ *
40
+ * @public
41
+ * @param otherIpAddress the other IPv4 address to compare
42
+ * @returns if the other IP address is the same
43
+ */
44
+ equals(otherIpAddress) {
45
+ return this.address === otherIpAddress.address;
46
+ }
47
+ }
48
+ /**
49
+ * Convenience function for creating an IPv4 address instance.
50
+ *
51
+ * @remarks
52
+ *
53
+ * In general, you should use this function instead of instantiating an Ipv4Address
54
+ * object directly. While there is nothing wrong with direct instantiation, convenience
55
+ * methods like these are meant to help reduce the footprint of your code and increase
56
+ * readability.
57
+ *
58
+ * @example
59
+ *
60
+ * ```typescript
61
+ * import * as cidr from 'cidr-block'
62
+ *
63
+ * const localhost = cidr.ipv4.address('172.0.0.0')
64
+ * ```
65
+ *
66
+ * @see {@link Ipv4Address}
67
+ *
68
+ * @param ip string representation of the IPv4 address
69
+ * @returns an instance of Ipv4Address
70
+ */
71
+ function address(ip) {
72
+ return new Ipv4Address(ip);
73
+ }
74
+ /**
75
+ * Converts the string representation of an IPv4 address to a BigInt.
76
+ *
77
+ * @remarks
78
+ *
79
+ * Conversion must be between string and bigint instead of integer as
80
+ * on 32-bit systems, Node.js may allocate the number as a 32-bit integer.
81
+ * To avoid this behavior, a BigInt is always used instead.
82
+ *
83
+ * @example
84
+ *
85
+ * ```typescript
86
+ * import * as cidr from 'cidr-block'
87
+ *
88
+ * cidr.ipv4.fromString('255.255.255.255') === 4_294_967_295n // ==> true
89
+ * cidr.ipv4.fromString('0.0.0.255') === 255n // ==> true
90
+ * ```
91
+ *
92
+ * @see This method is the inverse of {@link ipv4.toString|ipv4.toString()}
93
+ * @throws {@link InvalidIpAddressError}
94
+ *
95
+ * @public
96
+ * @param address IPv4 address represented as a string
97
+ * @returns numerical BigInt representation of the address
98
+ */
99
+ function fromString(address) {
100
+ try {
101
+ let [firstOctet, secondOctet, thirdOctet, fourthOctet] = address
102
+ .split('.')
103
+ .map(BigInt)
104
+ .filter(octet => octet >= 0 && octet <= MAX_OCTET_SIZE);
105
+ firstOctet = (firstOctet & MAX_OCTET_SIZE) << 24n;
106
+ secondOctet = (secondOctet & MAX_OCTET_SIZE) << 16n;
107
+ thirdOctet = (thirdOctet & MAX_OCTET_SIZE) << 8n;
108
+ fourthOctet = fourthOctet & MAX_OCTET_SIZE;
109
+ return firstOctet + secondOctet + thirdOctet + fourthOctet;
110
+ }
111
+ catch {
112
+ throw new InvalidIpAddressError(address);
113
+ }
114
+ }
115
+ /**
116
+ * Converts the numerical BigInt representation of an IPv4 address to its string representation.
117
+ *
118
+ * @remarks
119
+ *
120
+ * Conversion must be between string and bigint instead of integer as
121
+ * on 32-bit systems, Node.js may allocate the number as a 32-bit integer.
122
+ * To avoid this behavior, a BigInt is always used instead.
123
+ *
124
+ * @example
125
+ *
126
+ * ```typescript
127
+ * import * as cidr from 'cidr-block'
128
+ *
129
+ * cidr.ipv4.toString(0n) === '0.0.0.0' // ==> true
130
+ * cidr.ipv4.toString(65_280n) === '0.0.255.0' // ==> true
131
+ * cidr.ipv4.toString(4_294_967_295n) === '255.255.255.255' // ==> true
132
+ * ```
133
+ *
134
+ * @see This method is the inverse of {@link ipv4.fromString|ipv4.fromString()}
135
+ * @throws {@link InvalidIpAddressError}
136
+ *
137
+ * @public
138
+ * @param ip IPv4 address as a BigInt
139
+ * @returns string representation of the address
140
+ */
141
+ function toString(ip) {
142
+ if (ip < 0 || ip > IPv4_MAX) {
143
+ throw new InvalidIpAddressError(ip.toString());
144
+ }
145
+ const firstOctet = (ip >> 24n) & MAX_OCTET_SIZE;
146
+ const secondOctet = (ip >> 16n) & MAX_OCTET_SIZE;
147
+ const thirdOctet = (ip >> 8n) & MAX_OCTET_SIZE;
148
+ const fourthOctet = ip & MAX_OCTET_SIZE;
149
+ return `${firstOctet}.${secondOctet}.${thirdOctet}.${fourthOctet}`;
150
+ }var index=/*#__PURE__*/Object.freeze({__proto__:null,Ipv4Address:Ipv4Address,address:address,fromString:fromString,toString:toString});export{IPv4_MAX,IPv6_MAX,InvalidCidrError,InvalidIpAddressError,index as ipv4};//# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":"MAAa,KAAK,GAAG"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/cidr/constants.ts","../src/cidr/errors.ts","../src/cidr/ipv4/ipv4-address.ts"],"sourcesContent":[null,null,null],"names":[],"mappings":"AAAA;;;MAGa,QAAQ,GAAG,EAAE,IAAI,IAAG;AAEjC;;;MAGa,QAAQ,GAAG,EAAE,IAAI,UCRjB,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,KAAa;QACvB,KAAK,CAAC,GAAG,KAAK,6BAA6B,CAAC,CAA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KACzC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;SA0BgB,QAAQ,CAAC,EAAU;IACjC,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,QAAQ,EAAE;QAC3B,MAAM,IAAI,qBAAqB,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAA;KAC/C;IACD,MAAM,UAAU,GAAG,CAAC,EAAE,IAAI,GAAG,IAAI,cAAc,CAAA;IAC/C,MAAM,WAAW,GAAG,CAAC,EAAE,IAAI,GAAG,IAAI,cAAc,CAAA;IAChD,MAAM,UAAU,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,cAAc,CAAA;IAC9C,MAAM,WAAW,GAAG,EAAE,GAAG,cAAc,CAAA;IACvC,OAAO,GAAG,UAAU,IAAI,WAAW,IAAI,UAAU,IAAI,WAAW,EAAE,CAAA;AACpE"}
package/build/index.js CHANGED
@@ -1 +1,150 @@
1
- 'use strict';Object.defineProperty(exports,'__esModule',{value:true});const hello = 'world';exports.hello=hello;//# sourceMappingURL=index.js.map
1
+ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});/**
2
+ * The numerical maximum size an IPv4 address can be
3
+ */
4
+ const IPv4_MAX = 2n ** 32n;
5
+ /**
6
+ * The numerical maximum size an IPv6 address can be
7
+ */
8
+ const IPv6_MAX = 2n ** 64n;class InvalidIpAddressError extends Error {
9
+ constructor(badIp) {
10
+ super(`${badIp} is not a valid IP address.`);
11
+ }
12
+ }
13
+ class InvalidCidrError extends Error {
14
+ constructor(badCidr) {
15
+ super(`${badCidr} is not a valid cidr block or range.`);
16
+ }
17
+ }const MAX_OCTET_SIZE = 255n;
18
+ /**
19
+ * Representation of an IPv4 address. Provides various utility methods like equality
20
+ * checking.
21
+ *
22
+ * @remarks
23
+ * Direct instantiation should be avoided; use {@link ipv4.address|ipv4.address()} instead.
24
+ */
25
+ class Ipv4Address {
26
+ address;
27
+ constructor(address) {
28
+ this.address = fromString(address);
29
+ }
30
+ /**
31
+ * @public
32
+ * @returns the IPv4 address as a string
33
+ */
34
+ toString() {
35
+ return toString(this.address);
36
+ }
37
+ /**
38
+ * Compares if two IP address are the same.
39
+ *
40
+ * @public
41
+ * @param otherIpAddress the other IPv4 address to compare
42
+ * @returns if the other IP address is the same
43
+ */
44
+ equals(otherIpAddress) {
45
+ return this.address === otherIpAddress.address;
46
+ }
47
+ }
48
+ /**
49
+ * Convenience function for creating an IPv4 address instance.
50
+ *
51
+ * @remarks
52
+ *
53
+ * In general, you should use this function instead of instantiating an Ipv4Address
54
+ * object directly. While there is nothing wrong with direct instantiation, convenience
55
+ * methods like these are meant to help reduce the footprint of your code and increase
56
+ * readability.
57
+ *
58
+ * @example
59
+ *
60
+ * ```typescript
61
+ * import * as cidr from 'cidr-block'
62
+ *
63
+ * const localhost = cidr.ipv4.address('172.0.0.0')
64
+ * ```
65
+ *
66
+ * @see {@link Ipv4Address}
67
+ *
68
+ * @param ip string representation of the IPv4 address
69
+ * @returns an instance of Ipv4Address
70
+ */
71
+ function address(ip) {
72
+ return new Ipv4Address(ip);
73
+ }
74
+ /**
75
+ * Converts the string representation of an IPv4 address to a BigInt.
76
+ *
77
+ * @remarks
78
+ *
79
+ * Conversion must be between string and bigint instead of integer as
80
+ * on 32-bit systems, Node.js may allocate the number as a 32-bit integer.
81
+ * To avoid this behavior, a BigInt is always used instead.
82
+ *
83
+ * @example
84
+ *
85
+ * ```typescript
86
+ * import * as cidr from 'cidr-block'
87
+ *
88
+ * cidr.ipv4.fromString('255.255.255.255') === 4_294_967_295n // ==> true
89
+ * cidr.ipv4.fromString('0.0.0.255') === 255n // ==> true
90
+ * ```
91
+ *
92
+ * @see This method is the inverse of {@link ipv4.toString|ipv4.toString()}
93
+ * @throws {@link InvalidIpAddressError}
94
+ *
95
+ * @public
96
+ * @param address IPv4 address represented as a string
97
+ * @returns numerical BigInt representation of the address
98
+ */
99
+ function fromString(address) {
100
+ try {
101
+ let [firstOctet, secondOctet, thirdOctet, fourthOctet] = address
102
+ .split('.')
103
+ .map(BigInt)
104
+ .filter(octet => octet >= 0 && octet <= MAX_OCTET_SIZE);
105
+ firstOctet = (firstOctet & MAX_OCTET_SIZE) << 24n;
106
+ secondOctet = (secondOctet & MAX_OCTET_SIZE) << 16n;
107
+ thirdOctet = (thirdOctet & MAX_OCTET_SIZE) << 8n;
108
+ fourthOctet = fourthOctet & MAX_OCTET_SIZE;
109
+ return firstOctet + secondOctet + thirdOctet + fourthOctet;
110
+ }
111
+ catch {
112
+ throw new InvalidIpAddressError(address);
113
+ }
114
+ }
115
+ /**
116
+ * Converts the numerical BigInt representation of an IPv4 address to its string representation.
117
+ *
118
+ * @remarks
119
+ *
120
+ * Conversion must be between string and bigint instead of integer as
121
+ * on 32-bit systems, Node.js may allocate the number as a 32-bit integer.
122
+ * To avoid this behavior, a BigInt is always used instead.
123
+ *
124
+ * @example
125
+ *
126
+ * ```typescript
127
+ * import * as cidr from 'cidr-block'
128
+ *
129
+ * cidr.ipv4.toString(0n) === '0.0.0.0' // ==> true
130
+ * cidr.ipv4.toString(65_280n) === '0.0.255.0' // ==> true
131
+ * cidr.ipv4.toString(4_294_967_295n) === '255.255.255.255' // ==> true
132
+ * ```
133
+ *
134
+ * @see This method is the inverse of {@link ipv4.fromString|ipv4.fromString()}
135
+ * @throws {@link InvalidIpAddressError}
136
+ *
137
+ * @public
138
+ * @param ip IPv4 address as a BigInt
139
+ * @returns string representation of the address
140
+ */
141
+ function toString(ip) {
142
+ if (ip < 0 || ip > IPv4_MAX) {
143
+ throw new InvalidIpAddressError(ip.toString());
144
+ }
145
+ const firstOctet = (ip >> 24n) & MAX_OCTET_SIZE;
146
+ const secondOctet = (ip >> 16n) & MAX_OCTET_SIZE;
147
+ const thirdOctet = (ip >> 8n) & MAX_OCTET_SIZE;
148
+ const fourthOctet = ip & MAX_OCTET_SIZE;
149
+ return `${firstOctet}.${secondOctet}.${thirdOctet}.${fourthOctet}`;
150
+ }var index=/*#__PURE__*/Object.freeze({__proto__:null,Ipv4Address:Ipv4Address,address:address,fromString:fromString,toString:toString});exports.IPv4_MAX=IPv4_MAX;exports.IPv6_MAX=IPv6_MAX;exports.InvalidCidrError=InvalidCidrError;exports.InvalidIpAddressError=InvalidIpAddressError;exports.ipv4=index;//# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":"4EAAa,KAAK,GAAG"}
1
+ {"version":3,"file":"index.js","sources":["../src/cidr/constants.ts","../src/cidr/errors.ts","../src/cidr/ipv4/ipv4-address.ts"],"sourcesContent":[null,null,null],"names":[],"mappings":"sEAAA;;;MAGa,QAAQ,GAAG,EAAE,IAAI,IAAG;AAEjC;;;MAGa,QAAQ,GAAG,EAAE,IAAI,UCRjB,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,KAAa;QACvB,KAAK,CAAC,GAAG,KAAK,6BAA6B,CAAC,CAAA;KAC7C;CACF;MAEY,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAe;QACzB,KAAK,CAAC,GAAG,OAAO,sCAAsC,CAAC,CAAA;KACxD;CCNH,MAAM,cAAc,GAAG,IAAI,CAAA;AAE3B;;;;;;;MAOa,WAAW;IACd,OAAO,CAAQ;IAEvB,YAAmB,OAAe;QAChC,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;KACnC;;;;;IAMM,QAAQ;QACb,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;KAC9B;;;;;;;;IASM,MAAM,CAAC,cAA2B;QACvC,OAAO,IAAI,CAAC,OAAO,KAAK,cAAc,CAAC,OAAO,CAAA;KAC/C;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;SAuBgB,OAAO,CAAC,EAAU;IAChC,OAAO,IAAI,WAAW,CAAC,EAAE,CAAC,CAAA;AAC5B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;SAyBgB,UAAU,CAAC,OAAe;IACxC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numerical maximum size an IPv6 address can be
7
+ */
8
+ export declare const IPv6_MAX: bigint;
@@ -0,0 +1,6 @@
1
+ export declare class InvalidIpAddressError extends Error {
2
+ constructor(badIp: string);
3
+ }
4
+ export declare class InvalidCidrError extends Error {
5
+ constructor(badCidr: string);
6
+ }
@@ -0,0 +1 @@
1
+ export * from './ipv4-address';
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Representation of an IPv4 address. Provides various utility methods like equality
3
+ * checking.
4
+ *
5
+ * @remarks
6
+ * Direct instantiation should be avoided; use {@link ipv4.address|ipv4.address()} instead.
7
+ */
8
+ export declare class Ipv4Address {
9
+ private address;
10
+ constructor(address: string);
11
+ /**
12
+ * @public
13
+ * @returns the IPv4 address as a string
14
+ */
15
+ toString(): string;
16
+ /**
17
+ * Compares if two IP address are the same.
18
+ *
19
+ * @public
20
+ * @param otherIpAddress the other IPv4 address to compare
21
+ * @returns if the other IP address is the same
22
+ */
23
+ equals(otherIpAddress: Ipv4Address): boolean;
24
+ }
25
+ /**
26
+ * Convenience function for creating an IPv4 address instance.
27
+ *
28
+ * @remarks
29
+ *
30
+ * In general, you should use this function instead of instantiating an Ipv4Address
31
+ * object directly. While there is nothing wrong with direct instantiation, convenience
32
+ * methods like these are meant to help reduce the footprint of your code and increase
33
+ * readability.
34
+ *
35
+ * @example
36
+ *
37
+ * ```typescript
38
+ * import * as cidr from 'cidr-block'
39
+ *
40
+ * const localhost = cidr.ipv4.address('172.0.0.0')
41
+ * ```
42
+ *
43
+ * @see {@link Ipv4Address}
44
+ *
45
+ * @param ip string representation of the IPv4 address
46
+ * @returns an instance of Ipv4Address
47
+ */
48
+ export declare function address(ip: string): Ipv4Address;
49
+ /**
50
+ * Converts the string representation of an IPv4 address to a BigInt.
51
+ *
52
+ * @remarks
53
+ *
54
+ * Conversion must be between string and bigint instead of integer as
55
+ * on 32-bit systems, Node.js may allocate the number as a 32-bit integer.
56
+ * To avoid this behavior, a BigInt is always used instead.
57
+ *
58
+ * @example
59
+ *
60
+ * ```typescript
61
+ * import * as cidr from 'cidr-block'
62
+ *
63
+ * cidr.ipv4.fromString('255.255.255.255') === 4_294_967_295n // ==> true
64
+ * cidr.ipv4.fromString('0.0.0.255') === 255n // ==> true
65
+ * ```
66
+ *
67
+ * @see This method is the inverse of {@link ipv4.toString|ipv4.toString()}
68
+ * @throws {@link InvalidIpAddressError}
69
+ *
70
+ * @public
71
+ * @param address IPv4 address represented as a string
72
+ * @returns numerical BigInt representation of the address
73
+ */
74
+ export declare function fromString(address: string): bigint;
75
+ /**
76
+ * Converts the numerical BigInt representation of an IPv4 address to its string representation.
77
+ *
78
+ * @remarks
79
+ *
80
+ * Conversion must be between string and bigint instead of integer as
81
+ * on 32-bit systems, Node.js may allocate the number as a 32-bit integer.
82
+ * To avoid this behavior, a BigInt is always used instead.
83
+ *
84
+ * @example
85
+ *
86
+ * ```typescript
87
+ * import * as cidr from 'cidr-block'
88
+ *
89
+ * cidr.ipv4.toString(0n) === '0.0.0.0' // ==> true
90
+ * cidr.ipv4.toString(65_280n) === '0.0.255.0' // ==> true
91
+ * cidr.ipv4.toString(4_294_967_295n) === '255.255.255.255' // ==> true
92
+ * ```
93
+ *
94
+ * @see This method is the inverse of {@link ipv4.fromString|ipv4.fromString()}
95
+ * @throws {@link InvalidIpAddressError}
96
+ *
97
+ * @public
98
+ * @param ip IPv4 address as a BigInt
99
+ * @returns string representation of the address
100
+ */
101
+ export declare function toString(ip: bigint): string;
@@ -1 +1,3 @@
1
- export declare const hello = "world";
1
+ export * as ipv4 from './cidr/ipv4/index';
2
+ export * from './cidr/constants';
3
+ export * from './cidr/errors';
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cidr-block",
3
3
  "description": "cidr range utils for allocating blocks of ip ranges using cidr notation",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "license": "MIT",
6
6
  "author": "Brandon Burrus <brandon@burrus.io>",
7
7
  "homepage": "https://cidr-block.com",
@@ -65,9 +65,6 @@
65
65
  "jest": {
66
66
  "preset": "ts-jest",
67
67
  "testEnvironment": "node",
68
- "roots": [
69
- "<rootDir>/tests"
70
- ],
71
68
  "transform": {
72
69
  "^.+\\.ts$": "ts-jest"
73
70
  }
@@ -81,7 +78,11 @@
81
78
  "extends": [
82
79
  "eslint:recommended",
83
80
  "plugin:@typescript-eslint/recommended"
84
- ]
81
+ ],
82
+ "rules": {
83
+ "@typescript-eslint/no-non-null-assertion": "off",
84
+ "prefer-const": "off"
85
+ }
85
86
  },
86
87
  "prettier": {
87
88
  "arrowParens": "avoid",