Skip to content

Commit 9e756ae

Browse files
committed
1 parent f951820 commit 9e756ae

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

node_modules/ip-address/dist/ipv4.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,39 @@ class Address4 {
252252
static fromBigInt(bigInt) {
253253
return Address4.fromHex(bigInt.toString(16));
254254
}
255+
/**
256+
* Convert a byte array to an Address4 object
257+
* @memberof Address4
258+
* @static
259+
* @param {Array<number>} bytes - an array of 4 bytes (0-255)
260+
* @returns {Address4}
261+
*/
262+
static fromByteArray(bytes) {
263+
if (bytes.length !== 4) {
264+
throw new address_error_1.AddressError('IPv4 addresses require exactly 4 bytes');
265+
}
266+
// Validate that all bytes are within valid range (0-255)
267+
for (let i = 0; i < bytes.length; i++) {
268+
if (!Number.isInteger(bytes[i]) || bytes[i] < 0 || bytes[i] > 255) {
269+
throw new address_error_1.AddressError('All bytes must be integers between 0 and 255');
270+
}
271+
}
272+
return this.fromUnsignedByteArray(bytes);
273+
}
274+
/**
275+
* Convert an unsigned byte array to an Address4 object
276+
* @memberof Address4
277+
* @static
278+
* @param {Array<number>} bytes - an array of 4 unsigned bytes (0-255)
279+
* @returns {Address4}
280+
*/
281+
static fromUnsignedByteArray(bytes) {
282+
if (bytes.length !== 4) {
283+
throw new address_error_1.AddressError('IPv4 addresses require exactly 4 bytes');
284+
}
285+
const address = bytes.join('.');
286+
return new Address4(address);
287+
}
255288
/**
256289
* Returns the first n bits of the address, defaulting to the
257290
* subnet mask

node_modules/ip-address/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"browser",
88
"validation"
99
],
10-
"version": "10.0.1",
10+
"version": "10.1.0",
1111
"author": "Beau Gunderson <[email protected]> (https://beaugunderson.com/)",
1212
"license": "MIT",
1313
"main": "dist/ip-address.js",

package-lock.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5999,7 +5999,9 @@
59995999
}
60006000
},
60016001
"node_modules/ip-address": {
6002-
"version": "10.0.1",
6002+
"version": "10.1.0",
6003+
"resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.1.0.tgz",
6004+
"integrity": "sha512-XXADHxXmvT9+CRxhXg56LJovE+bmWnEWB78LB83VZTprKTmaC5QfruXocxzTZ2Kl0DNwKuBdlIhjL8LeY8Sf8Q==",
60036005
"inBundle": true,
60046006
"license": "MIT",
60056007
"engines": {

0 commit comments

Comments
 (0)