URIs and IRIs
The functions for the uri, uri-reference, iri, and iri-reference
formats come from
@hyperjump/uri.
They check the generic syntax of RFC 3986 or RFC 3987, and then the rules
of the scheme that the value has. For example, RFC 9110 says that an
http URI needs a host, so http:///a follows the generic syntax but
isn’t a valid uri:
import { isUri } from "@hyperjump/json-schema-formats";
isUri("https://example.com/schema"); // trueisUri("http:///a"); // falseA relative reference doesn’t have a scheme, so isUriReference and
isIriReference check it with the generic syntax only.
Schemes that aren’t known
Section titled “Schemes that aren’t known”Added in v1.2.0
@hyperjump/uri knows the http, https, file, urn, tag, data,
and did schemes, and the uuid namespace of urn. An identifier with
any other scheme, or a URN of another namespace, is checked with the
generic syntax only:
import { isUri } from "@hyperjump/json-schema-formats";
isUri("urn:isbn:0451450523"); // trueisUri("urn:uuid:x"); // falseFor the rules of each scheme that it knows, see
Schemes
in the @hyperjump/uri docs.
Errors
Section titled “Errors”Added in v1.2.0
assertUri and assertUriReference throw an InvalidUriError, and
assertIri and assertIriReference throw an InvalidIriError:
InvalidUriError: Invalid URI: https://exa mple.com — " " isn't allowed in a host, at 11These errors have value, reason, start, and end, like the other
errors in this package. In place of part, they have rule, the RFC
rule that the value doesn’t match, and component, the component that’s
wrong. For more information, see
Errors
in the @hyperjump/uri docs.
The package exports these errors, so you don’t need to import them from
@hyperjump/uri.