- From: James M Snell <notifications@github.com>
- Date: Mon, 13 Jun 2022 12:24:33 -0700
- To: whatwg/url <url@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/url/issues/696@github.com>
I've had a few discussions with folks (most recently at the OpenJS World conference in Austin last week) about the possibility of exposing the IPv4/IPv6 parser included in the URL parser via static functions on the `URL` class, e.g. something like a `URL.parseIPv4(input)` and `URL.parseIPv6(input)`. The intent is to both validate and normalize the input (e.g. validate that an IPv6 address is conformant, or converting some IPv4 variant into the standard 4-segment syntax, etc). Hanging these APIs of the proposed [`URLHost`](https://github.com/whatwg/url/pull/288) would also make sense. The usage of the proposed APIs would be straightforward: ``` const normalizedIpv4 = URL.parseIPv4(input); // normalizedIpv4 is a string with the serialized parsed result of `input`. ``` If the input is invalid, a `TypeError` is thrown. To make quick checks possible without incurring the cost of allocating the `TypeError` and associated stack, corresponding `URL.isIPv4()` and `URL.isIPv6()` utilities could also be provided. To give an idea as to whether this would be useful for the ecosystem, consider that the [`ip-regex`](https://www.npmjs.com/package/ip-regex) module on npm currently has over 12 million downloads per week. Given that this is functionality that is already included internally by `URL` implementations, it would be fairly trivial to expose it via a new API, thereby eliminating yet another dependency. -- Reply to this email directly or view it on GitHub: https://github.com/whatwg/url/issues/696 You are receiving this because you are subscribed to this thread. Message ID: <whatwg/url/issues/696@github.com>
Received on Monday, 13 June 2022 19:24:45 UTC