ip-address
Advanced tools
Comparing version 4.1.0 to 4.2.0
@@ -704,1 +704,32 @@ 'use strict'; | ||
}; | ||
v6.Address.prototype.toByteArray = function () { | ||
return this.bigInteger().toByteArray(); | ||
}; | ||
v6.Address.prototype.toUnsignedByteArray = function () { | ||
return this.toByteArray().map(function (b) { | ||
return b & 0xFF; | ||
}); | ||
}; | ||
v6.Address.fromUnsignedByteArray = function (bytes) { | ||
var BYTE_MAX = new BigInteger('256', 10); | ||
var result = new BigInteger('0', 10); | ||
var multiplier = new BigInteger('1', 10); | ||
for (var i = bytes.length - 1; i >= 0; i--) { | ||
result = result.add( | ||
multiplier.multiply(new BigInteger(bytes[i].toString(10), 10))); | ||
multiplier = multiplier.multiply(BYTE_MAX); | ||
} | ||
return v6.Address.fromBigInteger(result); | ||
}; | ||
v6.Address.fromByteArray = function (bytes) { | ||
return this.fromUnsignedByteArray(bytes.map(function (b) { | ||
return b & 0xFF; | ||
})); | ||
}; |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"author": "Beau Gunderson <beau@beaugunderson.com> (https://beaugunderson.com/)", | ||
@@ -13,0 +13,0 @@ "license": "MIT", |
@@ -75,2 +75,16 @@ 'use strict'; | ||
it('converts to and from a signed byte array', function () { | ||
var bytes = topic.toByteArray(); | ||
var address = v6.Address.fromByteArray(bytes); | ||
address.correctForm().should.equal(topic.correctForm()); | ||
}); | ||
it('converts to and from an unsigned byte array', function () { | ||
var unsignedBytes = topic.toUnsignedByteArray(); | ||
var address = v6.Address.fromUnsignedByteArray(unsignedBytes); | ||
address.correctForm().should.equal(topic.correctForm()); | ||
}); | ||
it('gets the correct type', function () { | ||
@@ -77,0 +91,0 @@ topic.getType().should.equal('Global unicast'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
116065
30
4083