Skip to content

v1.2.0

Latest

Choose a tag to compare

@jdesrosiers jdesrosiers released this 20 Nov 19:24

The documentation is now at https://hyperjump.io/json-schema-formats/.

What's new

  • assert functions and error classes. Each format has an assert function, like assertDate, that throws an error of its own class when a value isn't valid. The error says what's wrong, which part of the value it's in, and where. See Find what's wrong.

  • Formats from the JSON Schema and OpenAPI format registries. The registry formats that say exactly what's valid:

    • For strings: date-time-local, time-local, ipv4-cidr, ipv6-cidr, language, http-date, media-range, sf-binary, sf-boolean, sf-string, and sf-token.
    • For numbers: int8, int16, int32, uint8, uint16, uint32, double-int, sf-integer, and sf-decimal.

    See Registry formats.

  • Scheme rules for URIs and IRIs. isUri, isUriReference, isIri, and isIriReference come from @hyperjump/uri v2, which checks the rules of http, https, file, urn, tag, data, and did, as well as the generic syntax. See URIs and IRIs.

  • Types for URIs and IRIs. The URI and IRI functions are type guards, and the package exports the types that they narrow to: Uri, UriReference, Iri, and IriReference. It also exports InvalidUriError and InvalidIriError.

  • Faster. For a valid value, isDate and isDateTime are 7 to 9 times as fast as in 1.1.0, isDateTimeExt 5 times, and isAsciiIdn and isEmail about twice.

Changes

  • Scheme rules make some URIs and IRIs that 1.1.0 accepted not valid, like http:///a, which has no host, and urn:uuid:x. A scheme that @hyperjump/uri doesn't know is still checked with the generic syntax only.
  • isIdnEmail throws an Error for an address literal with a tag other than IPv6, like ada@[x-example:abc], as isEmail does. It accepted one before.
  • isEmail and isIdnEmail return false for an IPv6 address literal that isn't an IPv6 address. isEmail threw, and isIdnEmail accepted it.
  • idn-hostname is updated to 16, which is Unicode 16.0.
  • The package declares the Node.js versions that it supports: 22.12 or later, but not 23.