( host: string, port: number, scopeIds?: ReadonlyMap<string, number> )
| 1836 | * @since 4.0.0 |
| 1837 | */ |
| 1838 | export const inetAddressFromHostString = ( |
| 1839 | host: string, |
| 1840 | port: number, |
| 1841 | scopeIds?: ReadonlyMap<string, number> |
| 1842 | ): Result.Result<InetAddress, NetAddressError> => { |
| 1843 | const separator = host.indexOf("%") |
| 1844 | if (separator !== -1) { |
| 1845 | const zone = host.slice(separator + 1) |
| 1846 | if (zone.length === 0 || zone.includes("%")) { |
| 1847 | return addressError(host, "invalid IPv6 scope identifier") |
| 1848 | } |
| 1849 | if (!/^\d+$/.test(zone)) { |
| 1850 | const scopeId = scopeIds?.get(zone) |
| 1851 | if (scopeId === undefined) { |
| 1852 | return addressError(host, `unknown IPv6 interface: ${zone}`) |
| 1853 | } |
| 1854 | host = `${host.slice(0, separator)}%${scopeId}` |
| 1855 | } |
| 1856 | } |
| 1857 | return inetAddressFromString(host.includes(":") ? `[${host}]:${port}` : `${host}:${port}`) |
| 1858 | } |
| 1859 | |
| 1860 | /** |
| 1861 | * Network interface address metadata used to resolve IPv6 scope IDs. |
nothing calls this directly
no test coverage detected