hyperjump-io / uri

A small and fast library for validating, parsing, and resolving URIs (RFC 3986) and IRIs (RFC 3987).
MIT License
3 stars 1 forks source link

Why use it over `URL` interface? #1

Open GabenGar opened 1 year ago

GabenGar commented 1 year ago

The docs should explain the usecase because looking at the readme it looks like a less convenient URL. Didn't read the RFCs because they are tl;dr, as always.

jdesrosiers commented 1 year ago

The README certainly could say more here. I guess I expected that if you're looking for a URI library at all, you've already realized that URL isn't what need and you already know why you would need it.

It's an unfortunately situation that there are two competing specifications for URIs/URLs that aren't entirely compatible. There's the WHATWG spec and the various IETF specs. The URL class implemented in browsers and NodeJS implements the WHATWG spec, which means it's not going to be 100% compatible in situations where an IETF URI is expected, like JSON Schema. For example, IETF URIs allow for URIs without an authority component such as is used by the urn: scheme, urn:example:foo. This is not a valid WHATWG URL and the URL class will raise an error which is not what we want for something like JSON Schema that uses the IETF URI spec.

This library was created as a replacement for the uri-js which is the most used library for IETF URIs. I wanted a replacement because uri-js huge for some reason and it doesn't support IRIs. This implementation was not only much smaller, but also turned out to be much faster than both uri-js and URL.

GabenGar commented 1 year ago

I guess I expected that if you're looking for a URI library at all, you've already realized that URL isn't what need and you already know why you would need it.

Well I was looking at repos onhyperjump-io, not searching specifically for an URI library. Always assumed URI is some sort of deprecated spec, hence browsers implementing URL and not URI, and was surprised this lib is not at least 5 years old.

jdesrosiers commented 1 year ago

Ha, no, it's not deprecated and it's still widely used. I think it would be hard to find an IETF RFC that doesn't reference RFC 3986. Generally, WHATWG URL is used by web browsers and IETF URI is used by things that defined in IETF RFCs.