From 9fd0c52d513ad363984c5cc5d3d60011320b17fa Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Fri, 28 Aug 2026 21:05:49 -0500 Subject: [PATCH] Add README Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_016uAPiLrcvxP4hyvSLokRrp --- README.md | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ build.zig.zon | 2 +- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..abef0f6 --- /dev/null +++ b/README.md @@ -0,0 +1,79 @@ + + +# isbn.zig + +A Zig library for parsing, validating, and converting International +Standard Book Numbers (ISBNs) in both the 10-digit and 13-digit +formats. + +## Features + +- Parse ISBNs from text, with or without `-` separators. +- Validate check digits during parsing (including the `X` check digit + used by ISBN-10). +- Compute check digits, optionally using SIMD vector operations. +- Upgrade an ISBN-10 to its equivalent ISBN-13. +- Compare ISBNs across formats: an ISBN-10 is equal to its 13-digit + equivalent. + +## Requirements + +- Zig 0.16.0 or later + +## Installation + +Add the dependency to your project: + +```sh +zig fetch --save git+https://tangled.org/jcollie.dev/isbn.zig +``` + +Then wire it up in your `build.zig`: + +```zig +const isbn = b.dependency("isbn", .{ + .target = target, + .optimize = optimize, +}); +exe.root_module.addImport("isbn", isbn.module("isbn")); +``` + +## Usage + +```zig +const ISBN = @import("isbn").ISBN; + +// Parsing validates the check digit. +const ten: ISBN = try .parse("0-306-40615-2"); +const thirteen: ISBN = try .parse("978-0-306-40615-7"); + +// Upgrade an ISBN-10 to an ISBN-13. +const upgraded = ten.upgrade(); + +// Comparison works across formats. +std.debug.assert(ten.eql(&thirteen)); +``` + +`parse` returns `error.ParseError` for malformed input and +`error.InvalidCheckDigit` when the check digit doesn't match. + +## Build options + +- `-Dsimd=[bool]` — use SIMD vector operations for computing check + digits (default: `true`). + +## Testing + +```sh +zig build test +``` + +The test suite includes unit tests and a fuzz test. + +## License + +[MIT](LICENSES/MIT.txt). This project is compliant with the +[REUSE Specification](https://reuse.software/). diff --git a/build.zig.zon b/build.zig.zon index e2258a7..e5cfa7c 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -12,6 +12,6 @@ "build.zig.zon", "src", "LICENSES", - //"README.md", + "README.md", }, } -- 2.51.2