ip-utilties 1.0.2 → 1.0.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/ip.mjs +4 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ip-utilties",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
package/src/ip.mjs CHANGED
@@ -158,11 +158,7 @@ export function isIPv6(address) {
158
158
  }
159
159
 
160
160
  function _definition(address) {
161
- for (const defintion of [ipv4, ipv6]) {
162
- if (_is(defintion, address)) {
163
- return defintion;
164
- }
165
- }
161
+ return [ipv4, ipv6].find(d => _is(d, address));
166
162
  }
167
163
 
168
164
  function _is(definition, address) {
@@ -181,7 +177,7 @@ function _is(definition, address) {
181
177
  }
182
178
 
183
179
  export function asBigInt(address) {
184
- return _asBigInt(isIPv4(address) ? ipv4 : ipv6, address);
180
+ return _asBigInt(_definition(address), address);
185
181
  }
186
182
 
187
183
  function _asBigInt(definition, address) {
@@ -207,7 +203,7 @@ function _encodeBigInt(definition, address) {
207
203
  }
208
204
 
209
205
  export function prefixIP(address, length) {
210
- const definition = isIPv4(address) ? ipv4 : ipv6;
206
+ const definition = _definition(address);
211
207
  return _decode(definition, _prefix(definition, address, length));
212
208
  }
213
209
 
@@ -219,11 +215,9 @@ function _prefix(definition, address, length) {
219
215
  }
220
216
 
221
217
  export function rangeIP(address, prefix, lowerAdd = 0, upperReduce = 0) {
222
- const definition = isIPv4(address) ? ipv4 : ipv6;
223
-
218
+ const definition = _definition(address);
224
219
  const from = _prefix(definition, address, prefix);
225
220
  const to = from | ((1n << BigInt(definition.bitLength - prefix)) - 1n);
226
-
227
221
  return [
228
222
  _encode(definition, from + BigInt(lowerAdd)),
229
223
  _encode(definition, to - BigInt(upperReduce))