JsBarcode
JsBarcode copied to clipboard
Proposal: autoChecksum configuration option
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.