Skip to content

String-format long tail - #23

Merged
cryo2010 merged 2 commits into
mainfrom
feat/string-formats
Jul 24, 2026
Merged

cryo2010 merged 2 commits into
mainfrom
feat/string-formats

Conversation

@cryo2010

Copy link
Copy Markdown
Owner

Summary

Closes the string-format gap against zod with thirteen new refinements on Schema[string], all chainable, all with the standard message override:

Refinement Accepts
url scheme + host, parser-based via std/uri (URL regexes are unreliable)
ipv4 / ipv6 dotted quad with range-checked octets / full or ::-compressed form
hostname RFC 1123 labels
e164 + and 2-15 digits
base64 / base64url padded base64 / url-safe alphabet, optional padding
hex(n = 0) hex digits, exactly n when given
ulid / nanoid(len = 21) Crockford base32 / url-safe alphabet
jwt three dot-separated base64url segments (structural only)
semver the official semver.org grammar
slug lowercase kebab

Two commits:

  1. Plumbing: ckPattern gains an optional JSON Schema format name emitted alongside pattern, which retroactively gives uuid/date/datetime their proper format: uuid/date/date-time; plus a new parser-based ckUrl check emitting format: uri with no pattern.
  2. The formats themselves, each a patternCheck one-liner except url.

Deliberately omitted: emoji (unicode property classes, low value), cuid/cuid2 (ULID/nanoid cover the niche), and a combined ip() (already expressible as oneOfSchema(str().ipv4, str().ipv6)). ipv6 accepts full and compressed forms but not zone indices or IPv4-embedded notation, documented in the doc comment.

Tests

4 new tests (235 total, passing under orc and arc locally): a table-driven accept/reject matrix across all thirteen formats (~60 cases), message overrides, format emission in toJsonSchema including the no-pattern url case, and chaining with array/optional.

README (refinements table, string formats section) and DESIGN.md updated.

cryo2010 added 2 commits July 24, 2026 13:40
ckPattern gains an optional JSON Schema format name, emitted alongside
pattern by toJsonSchema; uuid/date/datetime now carry uuid/date/
date-time. Adds ckUrl backed by std/uri (a scheme and host required)
since URL regexes are unreliable; it emits format: uri. Plumbing for
the string-format refinements that follow.
Adds url (parser-based via std/uri: scheme and host required), ipv4,
ipv6, hostname, e164, base64, base64url, hex(n), ulid, nanoid(len),
jwt (structural), semver, and slug refinements on string schemas. All
are pattern checks except url, all take the standard message override,
and toJsonSchema emits format names where JSON Schema defines them
(uri, ipv4, ipv6, hostname).
@cryo2010
cryo2010 merged commit 64939ed into main Jul 24, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant