Repository navigation
Fix user-facing correctness bugs (UPC-E check digit, silent validation passes, CJS types) - #1
Merged
Merged
Conversation
- UPC-E check digit was computed with direct 7-digit weights instead of on
the UPC-A expansion (per GS1), so computeCheckDigit/validate/buildSequential
gave wrong answers and ~42% of generateRandom("upce") codes failed the
library's own validation.
- Unknown format strings (e.g. "UPCA") made validateBarcodeText return
{ ok: true } for anything; all functions now throw a clear error.
- validateBarcodeText accepted text with stray letters ("hello 0360...");
computeCheckDigit silently truncated over-long payloads and turned letters
into zeros. Only digits, spaces and hyphens are accepted now.
- ISBN-13 now requires the 978/979 prefix; random ISBNs also use 979.
- UPC-E number system must be 0/1; upcEExpand validates its inputs.
- buildSequential rejects negative/fractional/NaN start and count and
detects overflow up front.
- Variable-length validation rejects empty text and non-ASCII Code 128/FNSKU.
- package exports: CJS consumers got ESM typings (index.d.ts); now resolve
index.d.cts.
- README: wrong buildSequential example output, broken sponsor badge URL.
- CI: npm ci + typecheck step.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Mx4zmKAWVwBdSCtc7W97k
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015Mx4zmKAWVwBdSCtc7W97k
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes bugs found in a full audit of the library. Each fix has a regression test (13 → 27 tests).
Correctness
computeCheckDigit("upce"),validateBarcodeText("upce")andbuildSequential("upce")returned wrong answers, and about 42% ofgenerateRandom("upce")codes failed the library's own validation. Checked against the reference code01234565.validateBarcodeText("UPCA", "garbage")returned{ ok: true }, andgenerateRandom("UPCA")crashed with aTypeError. Every function now throws a descriptive error.validateBarcodeText("upca", "hello 036000291452")wasok.computeCheckDigitturned"ABC"into000000000000and silently cut off payloads that were too long. Now only digits, spaces and hyphens are accepted. Short payloads are still left-padded with zeros.buildSequential("isbn", "")used to produce0000000000017. Random ISBNs now also use 979.upcEExpandvalidates its inputs; a short body used to return"0120000undefined".buildSequentialrejects a negative, fractional or NaNstart/count(a negative start produced garbage codes) and checks for overflow before generating anything.Packaging
exports.requirenow points atindex.d.cts. arethetypeswrong is green for node10, node16 (CJS and ESM) and bundler.Docs / CI
buildSequentialexample output was wrong (…012→…019), the sponsor badge URL had a stray space, and the behaviour description is updated.npm ciand adds atypecheckstep, which also runs before publishing.Behaviour changes to note
Inputs that used to be silently accepted now throw or fail validation, so this is worth a minor version bump (0.2.0) before publishing. Code 128 is still upper-cased by
normalizeText, as before. That was left alone because it looks like a deliberate product choice.🤖 Generated with Claude Code
https://claude.ai/code/session_015Mx4zmKAWVwBdSCtc7W97k
Generated by Claude Code