Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

barcode-utils

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

barcode-utils

A collection of utilities for working with barcodes.

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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); // 3

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); // 3

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); // 5

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); // 012300000642

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); // true

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); // true

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); // 0123456789012

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); // true

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); // true

Keywords

FAQs

Package last updated on 28 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc