whitequark / ipaddr.js

IP address manipulation library in JavaScript
MIT License
570 stars 92 forks source link

Fix IPv6 shortening #163

Closed Darkwa closed 2 years ago

Darkwa commented 2 years ago

A simple fix that solves the IPv6 shortening issue.

Fixing the toString method is useful when printing CIDR addresses.

console.log(IPv6.parseCIDR('0:0:0:ff:ff:0:0:0/64').toString()); // prints ::ff:ff:0:0:0

const ipv6: [IPv6, number] = IPv6.parseCIDR(ip);
console.log(`${ipv6[0].toRFC5952String()}/${ipv6[1]}`); // prints ::ff:ff:0:0:0/64
console.log(IPv6.parseCIDR('0:0:0:ff:ff:0:0:0/64').toString()); // prints ::ff:ff:0:0:0/64

fixes #155

whitequark commented 2 years ago

Thanks!