(ip)
| 29 | ]; |
| 30 | |
| 31 | function ipv4ToInt(ip) { |
| 32 | // Parses an IPv4 dotted-decimal string into an unsigned 32-bit integer |
| 33 | // without allocating a split('.') array. Walks the string character by |
| 34 | // character, accumulating each decimal octet then shifting it into the |
| 35 | // result. The final >>> 0 ensures an unsigned value. |
| 36 | let result = 0; |
| 37 | let octet = 0; |
| 38 | for (let i = 0; i <= ip.length; i++) { |
| 39 | if (i === ip.length || ip.charCodeAt(i) === 46 /* '.' */) { |
| 40 | result = result * 256 + octet; // * 256 is equivalent to << 8 |
| 41 | octet = 0; |
| 42 | } else { |
| 43 | octet = octet * 10 + ip.charCodeAt(i) - 48; // 48 is '0'.charCodeAt(0) |
| 44 | } |
| 45 | } |
| 46 | return result >>> 0; |
| 47 | } |
| 48 | |
| 49 | function expandIPv6(address) { |
| 50 | // Expands a potentially shortened IPv6 address into a 32-char lowercase |
no outgoing calls
no test coverage detected