Skip to content

Commit

Permalink
update test and fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
beaugunderson committed Jul 19, 2021
1 parent 047b4a0 commit 42027ec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
15 changes: 4 additions & 11 deletions lib/ipv4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ export class Address4 {
return Address4.fromHex(integer.toString(16));
}


/**
* Return an address from in-addr.arpa form
* @memberof Address4
Expand All @@ -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
Expand Down Expand Up @@ -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);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion test/address-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
}
Expand Down

0 comments on commit 42027ec

Please sign in to comment.