GS1 Barcode Parser

1.0.7 · active · verified Sun Apr 19

The `gs1-barcode-parser-mod` library is an active fork designed for parsing the complex data structures found within GS1 barcodes. It provides a single function to decompose the raw string content of a GS1 barcode into an array of structured data elements, each identified by its Application Identifier (AI). This enables JavaScript applications to easily extract specific information such as GTIN, batch/lot numbers, expiration dates, and weights. The current stable version is 1.0.7. It's particularly useful in scenarios where barcode scanning devices provide a raw string, and the application needs to process this data for inventory management, point-of-sale, or logistics. Its key differentiator is its focused utility for GS1 standards, though it's important to note it's based on the GS1 'Version 14, Issue 1, Jan 2014' specification, which might not cover the absolute latest revisions.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates parsing a sample GS1 barcode string and iterating through the extracted data elements, including accessing specific AIs like GTIN and Lot/Batch number.

import { parseGS1Barcode } from 'gs1-barcode-parser-mod';

const scannedBarcodeString = ']C101040123456789011715012910ABC123 39329784711 310300052539224711 42127649716';

try {
  const parsedData = parseGS1Barcode(scannedBarcodeString);

  console.log('Parsed GS1 Barcode Data:');
  parsedData.forEach(item => {
    console.log(`AI: ${item.ai}, Title: ${item.title}, Contents: ${item.content}, Unit: ${item.unit || 'N/A'}`);
  });

  // Example of accessing specific data:
  const gtin = parsedData.find(item => item.ai === '01');
  if (gtin) {
    console.log(`\nGTIN: ${gtin.content}`);
  }

  const lotBatch = parsedData.find(item => item.ai === '10');
  if (lotBatch) {
    console.log(`Lot/Batch Number: ${lotBatch.content}`);
  }

} catch (error) {
  console.error('Error parsing barcode:', error.message);
}

view raw JSON →