MCPcopy Create free account
hub / github.com/Effect-TS/effect / inetAddressFromHostString

Function inetAddressFromHostString

packages/effect/src/net/NetAddress.ts:1838–1858  ·  view source on GitHub ↗
(
  host: string,
  port: number,
  scopeIds?: ReadonlyMap<string, number>
)

Source from the content-addressed store, hash-verified

1836 * @since 4.0.0
1837 */
1838export 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.

Callers

nothing calls this directly

Calls 4

addressErrorFunction · 0.85
inetAddressFromStringFunction · 0.85
sliceMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected