Skip to content

v2.0.0

Choose a tag to compare

@jdesrosiers jdesrosiers released this 14 Nov 06:43
· 6 commits to main since this release

A rewrite of @hyperjump/uri. The documentation is now at https://hyperjump.io/uri/.

What's new

  • Scheme rules. The validation functions check the rules of http, https, file, urn, tag, did, and data, as well as the generic syntax. Other schemes are checked with the generic syntax only. See Schemes.
  • Checked once. Only the validation functions check their input. The other functions trust what they're given, and TypeScript types like Iri and AbsoluteIri mark the strings that were checked. See Validate and parse.
  • Scheme normalization. normalizeIri and normalizeUri apply the scheme's normalization too. See Normalize.
  • assert functions and error classes. assertIri and the other assert functions throw an InvalidUriError or an InvalidIriError that says what's wrong and where.
  • New functions. parseUrn, getScheme, hasScheme, getPath, getQuery, getFragment, and urlToIri, which makes a URL an IRI. See Convert URLs.

Breaking changes

  • The validation functions apply scheme rules, so some identifiers that v1 accepted aren't valid.
  • Functions other than the validation functions don't check their arguments. Check identifiers with an is or assert function first.
  • resolveIri, toAbsoluteIri, and toRelativeIri don't normalize their results.
  • toRelativeIri takes the target first and the base second, and both have to be normalized.
  • The functions that work the same for URIs and IRIs have only their IRI names: parseIri, resolveIri, toRelativeIri, and toAbsoluteIri.
  • resolveIri doesn't take "" as a base.
  • A component that isn't in an identifier isn't a property of the parsed result.
  • Future IP literals, like [v1.fe80::a+en1], are valid instead of throwing.
  • It needs Node.js 22.1 or later, or a browser released since 2024.

See Migrate from v1 for each change and what to do about it.