lindell / lindell/JsBarcode

Proposal: autoChecksum configuration option

Open
#277 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5.9k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

It seems that many of the barcode types will automatically generate a checksum character if the data meets certain requirements:
https://github.com/lindell/JsBarcode/blob/c2c7a5aec7eac60f6aee26bd26f4915cb319dbf6/src/barcodes/EAN_UPC/EAN13.js#L25-L27

I use this library to generate barcodes for user generated products. We assume that the barcode is EAN-13 format unless JsBarcode throws an exception when trying to parse the barcode, then we fall back to CODE128. The issue is that if the user has typed in a 12 character numerical barcode (which isn't a valid EAN-13 code) the library changes the barcode to include the checksum and doesn't throw an exception for an invalid code - then when the barcode is scanned the barcode no longer matches the product's original barcode.

I would like to propose a new configuration option: `autoChecksum`

This config would default to `true` for backwards compatibility, but would expose the ability to disable auto generating barcode checksums - instead simply throwing `"[input]" is not a valid input for EAN13`.

If this is something that could make it into the library I would be happy to create a PR to add this functionality.

Contributor guide

Open the contributing guide

Research direction

Start with src/barcodes/EAN_UPC/EAN13.js, especially the checksum-generation logic linked in the issue, and trace how barcode configuration reaches it. Done means an autoChecksum option defaults to the current behavior while disabling it rejects the described invalid EAN-13 input instead of changing the barcode.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.