Repository navigation
v2.0.0
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, anddata, 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
IriandAbsoluteIrimark the strings that were checked. See Validate and parse. - Scheme normalization.
normalizeIriandnormalizeUriapply the scheme's normalization too. See Normalize. assertfunctions and error classes.assertIriand the otherassertfunctions throw anInvalidUriErroror anInvalidIriErrorthat says what's wrong and where.- New functions.
parseUrn,getScheme,hasScheme,getPath,getQuery,getFragment, andurlToIri, which makes aURLan 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
isorassertfunction first. resolveIri,toAbsoluteIri, andtoRelativeIridon't normalize their results.toRelativeIritakes 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, andtoAbsoluteIri. resolveIridoesn'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.