build/lib/Hostname.js
function getSocketAddressFromURLSafeHostname(hostname) {
    return __awaiter(this, void 0, void 0, function* () {
        // IPv4 addresses are fine
        if (net_1.isIPv4(hostname))
            return hostname;
        // IPv6 addresses are wrapped in [], which need to be removed
        if (/^\[.+\]$/.test(hostname)) {
            const potentialIPv6 = hostname.slice(1, -1);
            if (net_1.isIPv6(potentialIPv6))
                return potentialIPv6;
        }
        // This is a hostname, look it up
        try {
            const address = yield lookupAsync(hostname);
            // We found an address
            if (address)
                return address;
        }
        catch (e) {
            // Lookup failed, continue working with the hostname
        }
        return hostname;
    });
}
function getSocketAddressFromURLSafeHostname(hostname) {
    return __awaiter(this, void 0, void 0, function* () {
        // IPv4 addresses are fine
        if (net_1.isIPv4(hostname))
            return hostname;
        // IPv6 addresses are wrapped in [], which need to be removed
        if (/^\[.+\]$/.test(hostname)) {
            const potentialIPv6 = hostname.slice(1, -1);
            if (net_1.isIPv6(potentialIPv6))
                return potentialIPv6;
        }
        // This is a hostname, look it up
        try {
            const address = yield lookupAsync(hostname);
            // We found an address
            if (address)
                return address;
        }
        catch (e) {
            // Lookup failed, continue working with the hostname
        }
        return hostname;
    });
}
function getSocketAddressFromURLSafeHostname ( hostname ) { return __awaiter ( this , void 0 , void 0 , function * ( ) { // IPv4 addresses are fine if ( net_1 . isIPv4 ( hostname ) ) return hostname ; // IPv6 addresses are wrapped in [], which need to be removed if ( / ^\[.+\]$ / . test ( hostname ) ) { const potentialIPv6 = hostname . slice ( 1 , - 1 ) ; if ( net_1 . isIPv6 ( potentialIPv6 ) ) return potentialIPv6 ; } // This is a hostname, look it up try { const address = yield lookupAsync ( hostname ) ; // We found an address if ( address ) return address ; } catch ( e ) { // Lookup failed, continue working with the hostname } return hostname ; } ) ; }
Takes an URL-safe hostname and converts it to an address to be used in UDP sockets
Takes an URL - safe hostname and converts it to an address to be used in UDP sockets