Barcode Utilities
A collection of utilities for working with barcodes.
Installation
npm install barcode-utils
Usage
const { eanCheckDigit } = require('barcode-utils').default;
const eanWithoutCheckDigit = '001200000013';
const checkDigit = eanCheckDigit(eanWithoutCheckDigit);
console.log(checkDigit);
Documentation
eanCheckDigit
- Calculate the check digit for a EAN code, given the first 7 or 12 digits.
- @param {string} code - The first 7 or 12 digits of a EAN code.
- @returns {number} The check digit for the code.
const eanWithoutCheckDigit = '001200000013';
const checkDigit = eanCheckDigit(eanWithoutCheckDigit);
console.log(checkDigit);
upcCheckDigit
- Calculate the check digit for a UPC code, given the first 7 or 11 digits.
- @param {string} code - The first 7 or 11 digits of a UPC code.
- @returns {number} The check digit for the code.
const upcWithoutCheckDigit = '72641217542';
const checkDigit = upcCheckDigit(upcWithoutCheckDigit);
console.log(checkDigit);
expandupce
- Expand a UPC-E code to a UPC-A code.
- @param {string} code - A UPC-E code.
- @returns {string} The expanded UPC-A code.
const upce = '01236432';
const upca = expandupce(upce);
console.log(upca);
validupce
- Check if a UPC-E code is exactly 8 bytes long, consists of digits only, and has a valid check digit.
- @param {string} code - A UPC-E code.
- @returns {boolean} True if the code is valid, false otherwise.
const upce = '01236432';
const valid = validupce(upce);
console.log(valid);
validupca
- Check if a UPC-A code is exactly 12 bytes long, consists of digits only, and has a valid check digit.
- @param {string} code - A UPC-A code.
- @returns {boolean} True if the code is valid, false otherwise.
const upca = '012300000642';
const valid = validupca(upca);
console.log(valid);
upca2ean13
- Convert a UPC-A code to a EAN-13 code.
- @param {string} code - A UPC-A code.
- @returns {string} The EAN-13 code.
const upca = '123456789012';
const ean13 = upca2ean13(upca);
console.log(ean13);
validean13
- Check if a EAN-13 code is exactly 13 bytes long, consists of digits only, and has a valid check digit.
- @param {string} code - A EAN-13 code.
- @returns {boolean} True if the code is valid, false otherwise.
const ean13 = '0123456789012';
const valid = validean13(ean13);
console.log(valid);
isBarCode
- Check if a code is a valid UPC-A, UPC-E, or EAN-13 code.
- @param {string} code - A UPC-A, UPC-E, or EAN-13 code.
- @returns {boolean} True if the code is valid, false otherwise.
const upca = '123456789012';
const valid = isBarCode(upca);
console.log(valid);