Added utility to calculate EAN barcode type parity bit #56 #57
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.
Background
EAN bar codes have parity bits by default.
If the parity bit is not correct, the barcode scanner will not recognize it.
For example, for EAN-13 only 12 characters can be specified by the user and the last 13th bit must be calculated as parity bit.
This can be found on Wikipedia. (Https://en.wikipedia.org/wiki/International_Article_Number#Calculation_of_checksum_digit)
Commit Details
Printer.prototype.barcode
function that calculates the parity bit of the EAN type barcode.code.length
is not 12, it is meaningless. So I added an exception for this. EAN-8 also added exception handling whencode.length
is not 7../barcode.js
file. ThegetParityBit (code, type)
function is defined inside. I only looked at the EAN type, so I made it easy to add other types../example/index.js
from 8 to 7../example/barcode.js
file.Npm v5
now.package-lock.json
file is automatically generated, but it is considered unnecessary for this project and added to.gitignore
(I tried not to use the latest JavaScript function as much as possible.)Testing
Feedback is needed.
Thanks.