function expandIPv6(string, parts) {
        // More than one '::' means invalid adddress
        if (string.indexOf("::") !== string.lastIndexOf("::")) {
            return null;
        }

        let colonCount = 0;
        let lastColon = -1;
        let zoneId = (string.match(ipv6Regexes.zoneIndex) || [])[0];
        let replacement;
        let
            replacementCount;

        // Remove zone index and save it for later
        if (zoneId) {
            zoneId = zoneId.substring(1);
            string = string.replace(/%.+$/, "");
        }

        // How many parts do we already have?
        while ((lastColon = string.indexOf(":", lastColon + 1)) >= 0) {
            colonCount++;
        }

        // 0::0 is two parts more than ::
        if (string.substr(0, 2) === "::") {
            colonCount--;
        }

        if (string.substr(-2, 2) === "::") {
            colonCount--;
        }

        // The following loop would hang if colonCount > parts
        if (colonCount > parts) {
            return null;
        }

        // replacement = ':' + '0:' * (parts - colonCount)
        replacementCount = parts - colonCount;
        replacement = ":";
        while (replacementCount--) {
            replacement += "0:";
        }

        // Insert the missing zeroes
        string = string.replace("::", replacement);

        // Trim any garbage which may be hanging around if :: was at the edge in
        // the source strin
        if (string[0] === ":") {
            string = string.slice(1);
        }

        if (string[string.length - 1] === ":") {
            string = string.slice(0, -1);
        }

        parts = (function () {
            const ref = string.split(":");
            const results = [];

            for (let i = 0; i < ref.length; i++) {
                results.push(parseInt(ref[i], 16));
            }

            return results;
        }());

        return {
            parts,
            zoneId
        };
    }
// Expand :: in an IPv6 address or address part consisting of `parts` groups.
Expand :: in an IPv6 address or address part consisting of `parts` groups.
Expand :: in an IPv6 address or address part consisting of ` parts ` groups .
function expandIPv6(string, parts) {
        if (string.indexOf("::") !== string.lastIndexOf("::")) {
            return null;
        }
        let colonCount = 0;
        let lastColon = -1;
        let zoneId = (string.match(ipv6Regexes.zoneIndex) || [])[0];
        let replacement;
        let
            replacementCount;
        if (zoneId) {
            zoneId = zoneId.substring(1);
            string = string.replace(/%.+$/, "");
        }
        while ((lastColon = string.indexOf(":", lastColon + 1)) >= 0) {
            colonCount++;
        }
        if (string.substr(0, 2) === "::") {
            colonCount--;
        }
        if (string.substr(-2, 2) === "::") {
            colonCount--;
        }
        if (colonCount > parts) {
            return null;
        }
        replacementCount = parts - colonCount;
        replacement = ":";
        while (replacementCount--) {
            replacement += "0:";
        }
        string = string.replace("::", replacement);
        if (string[0] === ":") {
            string = string.slice(1);
        }
        if (string[string.length - 1] === ":") {
            string = string.slice(0, -1);
        }
        parts = (function () {
            const ref = string.split(":");
            const results = [];
            for (let i = 0; i < ref.length; i++) {
                results.push(parseInt(ref[i], 16));
            }
            return results;
        }());
        return {
            parts,
            zoneId
        };
    }
function expandIPv6 ( string , parts ) { if ( string . indexOf ( "::" ) !== string . lastIndexOf ( "::" ) ) { return null ; } let colonCount = 0 ; let lastColon = - 1 ; let zoneId = ( string . match ( ipv6Regexes . zoneIndex ) || [ ] ) [ 0 ] ; let replacement ; let replacementCount ; if ( zoneId ) { zoneId = zoneId . substring ( 1 ) ; string = string . replace ( / %.+$ / , "" ) ; } while ( ( lastColon = string . indexOf ( ":" , lastColon + 1 ) ) >= 0 ) { colonCount ++ ; } if ( string . substr ( 0 , 2 ) === "::" ) { colonCount -- ; } if ( string . substr ( - 2 , 2 ) === "::" ) { colonCount -- ; } if ( colonCount > parts ) { return null ; } replacementCount = parts - colonCount ; replacement = ":" ; while ( replacementCount -- ) { replacement += "0:" ; } string = string . replace ( "::" , replacement ) ; if ( string [ 0 ] === ":" ) { string = string . slice ( 1 ) ; } if ( string [ string . length - 1 ] === ":" ) { string = string . slice ( 0 , - 1 ) ; } parts = ( function ( ) { const ref = string . split ( ":" ) ; const results = [ ] ; for ( let i = 0 ; i < ref . length ; i ++ ) { results . push ( parseInt ( ref [ i ] , 16 ) ) ; } return results ; } ( ) ) ; return { parts , zoneId } ; }
Expand :: in an IPv6 address or address part consisting of `parts` groups.
Expand :: in an IPv6 address or address part consisting of ` parts ` groups .
// More than one '::' means invalid adddress // Remove zone index and save it for later // How many parts do we already have? // 0::0 is two parts more than :: // The following loop would hang if colonCount > parts // replacement = ':' + '0:' * (parts - colonCount) // Insert the missing zeroes // Trim any garbage which may be hanging around if :: was at the edge in // the source strin