URI.js is a Javascript library for working with URLs.
—
Specialized support for IPv6 address handling and normalization with optimal text representation.
/**
* Convert IPv6 address to best text representation
* @param address - IPv6 address string to normalize
* @returns Optimized IPv6 address representation
*/
IPv6.best(address: string): string;
/**
* Restore previous IPv6 variable
* @returns Previous IPv6 variable value
*/
IPv6.noConflict(): any;Usage Examples:
// Import IPv6 module
import IPv6 from 'urijs/src/IPv6';
// Normalize IPv6 addresses
const longForm = '2001:0db8:0000:0000:0000:0000:0000:0001';
const optimized = IPv6.best(longForm);
console.log(optimized); // '2001:db8::1'
// Handle zero compression
const withZeros = '2001:db8:0:0:1:0:0:1';
const compressed = IPv6.best(withZeros);
console.log(compressed); // '2001:db8::1:0:0:1'
// Mixed IPv4-IPv6 addresses
const mixed = '::ffff:192.168.1.1';
const mixedOpt = IPv6.best(mixed);
console.log(mixedOpt); // '::ffff:192.168.1.1' (already optimal)
// Use with URI.js
const uri = new URI('http://[2001:db8::1]:8080/path');
console.log(uri.hostname()); // '2001:db8::1'
console.log(uri.is('ip6')); // trueInstall with Tessl CLI
npx tessl i tessl/npm-urijs