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
| /** | |
| * Generates a check digit from a partial EAN13. | |
| * | |
| * https://www.gs1.org/services/how-calculate-check-digit-manually | |
| * | |
| * @param {string} barcode - 12 digit EAN13 barcode without the check digit | |
| */ | |
| function checkDigitEAN13(barcode) { | |
| const sum = barcode.split('') | |
| .map((n, i) => n * (i % 2 ? 3 : 1)) // alternate between multiplying with 3 and 1 |