Skip to content

feat: add string.isbn keyword for ISBN validation#1622

Draft
Ojoxux wants to merge 1 commit into
arktypeio:mainfrom
Ojoxux:ojoxux/add-isbn-validation
Draft

feat: add string.isbn keyword for ISBN validation#1622
Ojoxux wants to merge 1 commit into
arktypeio:mainfrom
Ojoxux:ojoxux/add-isbn-validation

Conversation

@Ojoxux
Copy link
Copy Markdown

@Ojoxux Ojoxux commented May 28, 2026

Summary

Following the precedent set by string.creditCard, this PR introduces string.isbn as a built-in validator.

I've encountered the need for this in my own projects before, where I ended up relying on custom validation.

Validating ISBNs requires more than a simple format check, since ISBN-10 and ISBN-13 use distinct checksum algorithms:

As a result, rolling a custom implementation with narrow can be easy to get subtly wrong.

Behavior:

  • Accepts ISBN-10 or ISBN-13
  • Allows hyphen/space separators, which are stripped before validation
  • Validates the appropriate checksum
  • Rejects lowercase x as a check digit

Examples:

Input Result
"978-4-87311-873-4" ✅ valid
"4-87311-873-5" ✅ valid
"020530902X" ✅ valid
"9784873118735" ❌ invalid checksum
"020530902x" ❌ invalid

Implementation notes:

  • Adds the validator in ark/type/keywords/string.ts
  • Exposes it via rootSchema({ domain: "string", predicate: ... })
  • Registers it in Scope.module
  • Adds the corresponding namespace $ type

Test plan

  • Valid ISBN-10 and ISBN-13 inputs are accepted, with and without separators
  • Invalid checksum, lowercase x, wrong length, and non-digit input are rejected
  • pnpm prChecks passes

@github-project-automation github-project-automation Bot moved this to To do in arktypeio May 28, 2026
@Ojoxux Ojoxux changed the title feat: add string.isbn keyword for ISBN-10 / ISBN-13 validation feat: add string.isbn keyword for ISBN validation May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To do

Development

Successfully merging this pull request may close these issues.

1 participant