Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added utility to calculate EAN barcode type parity bit #56 #57

Merged
merged 1 commit into from
Aug 12, 2017
Merged

Added utility to calculate EAN barcode type parity bit #56 #57

merged 1 commit into from
Aug 12, 2017

Conversation

uyu423
Copy link
Collaborator

@uyu423 uyu423 commented Aug 11, 2017

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

  • If escpos provides the barcode function, I think you also need the code to calculate the parity bit. So I added the part of the Printer.prototype.barcode function that calculates the parity bit of the EAN type barcode.
  • For EAN-13, if code.length is not 12, it is meaningless. So I added an exception for this. EAN-8 also added exception handling when code.length is not 7.
  • I created a new ./barcode.js file. The getParityBit (code, type) function is defined inside. I only looked at the EAN type, so I made it easy to add other types.
  • reduced the barcode length of ./example/index.js from 8 to 7.
  • added a new ./example/barcode.js file.
  • I'm using 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

  • I tried to add the test code but I gave up because I could not check the data inside the buffer. However, I did some tests myself and it worked normally.
  • The barcode containing the calculated parity bits was recognized normally by the barcode scanner.

Feedback is needed.
Thanks.

@lsongdev lsongdev closed this Aug 11, 2017
@uyu423
Copy link
Collaborator Author

uyu423 commented Aug 11, 2017

Why is it closed? It may be a good act to explain why.

@lsongdev lsongdev reopened this Aug 12, 2017
@lsongdev lsongdev merged commit 605c17c into lsongdev:master Aug 12, 2017
@lsongdev
Copy link
Owner

sorry,im wrong .

@uyu423
Copy link
Collaborator Author

uyu423 commented Aug 12, 2017

thank you. I will update the README.md soon and pull request.

@lsongdev
Copy link
Owner

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants