Closed zctya closed 4 years ago
the fact that you got an Address6 and not an exception means it’s valid—can you help me understand what’s different than what you expect to happen? :)
On Mon, Oct 26 2020 at 19:35, zctya notifications@github.com wrote:
[image: WX20201027-103509] https://user-images.githubusercontent.com/10741844/97250082-22750500-1840-11eb-9f01-efefbee3484f.png
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/beaugunderson/ip-address/issues/121, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAPCX4BQWT5OSHJOA3UORLSMYWYRANCNFSM4TAGDDKA .
// ip-address: 7.0.1 var Address6 = require('ip-address').Address6; var address6 = new Address6('0:0:0:0:0:0:0:0') address6.isCorrect() // return false except true
that's not what isCorrect is for—"::" is the "correct" representation of that address; I think that function should be renamed to make it more obvious what it does :)
you can use the static Address6.isValid (added in 7.1.0) for checking validity; and if you do instantiate an address (e.g. with new Address6('0:0:0:0:0:0:0:0')
) then it will throw an exception if the address is inValid and succeed otherwise (this was a change based on user feedback and made in 7.0.0; previously the returned Address6 had an isValid()
method but this was made static).
to further explain; if you visit v6decode.com (which uses this library) and enter an address you can see how the various flags work out, e.g. for 0:0:0:0:0:0:0:0:
the definition of "correct" is the one detailed here: https://tools.ietf.org/html/rfc5952#page-10
const a = new Address6('0:0:0:0:0:0:0:0');
a.isValid(); // true
const b = new Address6('invalid address');
b.isValid(); // false
const a = new Address6('0:0:0:0:0:0:0:0'); // doesn't throw an exception, so you know the address is valid
const b = new Address6('invalid address'); // throws an exception
// or you can use the new static method
Address6.isValid('0:0:0:0:0:0:0:0'); // true
Address6.isValid('invalid address'); // false
Thanks
in 7.1.0 passed Address6.isValid('0:0:0:0:0:0:0:0'); // true
Address6.isValid('invalid address'); // false