diff --git a/lib/ipv4.ts b/lib/ipv4.ts index b6c61ff..557216e 100644 --- a/lib/ipv4.ts +++ b/lib/ipv4.ts @@ -117,7 +117,6 @@ export class Address4 { return Address4.fromHex(integer.toString(16)); } - /** * Return an address from in-addr.arpa form * @memberof Address4 @@ -132,14 +131,11 @@ export class Address4 { // remove ending ".in-addr.arpa." or just "." const leader = arpaFormAddress.replace(/(\.in-addr\.arpa)?\.$/, ''); - const address = leader.split('.') - .reverse() - .join('.'); + const address = leader.split('.').reverse().join('.'); return new Address4(address); } - /** * Converts an IPv4 address object to a hex string * @memberof Address4 @@ -311,16 +307,13 @@ export class Address4 { options = {}; } - const reversed = this.correctForm() - .split('.') - .reverse() - .join('.'); + const reversed = this.correctForm().split('.').reverse().join('.'); if (options.omitSuffix) { return reversed; - } else { - return sprintf('%s.in-addr.arpa.', reversed); } + + return sprintf('%s.in-addr.arpa.', reversed); } /** diff --git a/test/address-test.ts b/test/address-test.ts index ac209d8..bfa99ba 100644 --- a/test/address-test.ts +++ b/test/address-test.ts @@ -30,12 +30,15 @@ function addressIs(addressString: string, descriptors: string[]) { address4.subnetMask.should.be.at.least(0); address4.subnetMask.should.be.at.most(128); }); + it('converts to arpa format and back', () => { const arpa = address4.reverseForm(); arpa.length.should.be.at.most(29); - const converted = Address4.fromArpa(arpa); + const arpaWithoutSuffix = address4.reverseForm({ omitSuffix: true }); + arpaWithoutSuffix.length.should.be.at.most(15); + const converted = Address4.fromArpa(arpa); address4.correctForm().should.equal(converted.correctForm()); }); }