{"id":14612,"library":"gs1-barcode-parser-mod","title":"GS1 Barcode Parser","description":"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.","status":"active","version":"1.0.7","language":"javascript","source_language":"en","source_url":"https://github.com/MaximBelov/BarcodeParser","tags":["javascript","GS1","barcode","parser"],"install":[{"cmd":"npm install gs1-barcode-parser-mod","lang":"bash","label":"npm"},{"cmd":"yarn add gs1-barcode-parser-mod","lang":"bash","label":"yarn"},{"cmd":"pnpm add gs1-barcode-parser-mod","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library primarily uses named exports for its single parsing function.","wrong":"const parseGS1Barcode = require('gs1-barcode-parser-mod');","symbol":"parseGS1Barcode","correct":"import { parseGS1Barcode } from 'gs1-barcode-parser-mod';"}],"quickstart":{"code":"import { parseGS1Barcode } from 'gs1-barcode-parser-mod';\n\nconst scannedBarcodeString = ']C101040123456789011715012910ABC123 39329784711 310300052539224711 42127649716';\n\ntry {\n  const parsedData = parseGS1Barcode(scannedBarcodeString);\n\n  console.log('Parsed GS1 Barcode Data:');\n  parsedData.forEach(item => {\n    console.log(`AI: ${item.ai}, Title: ${item.title}, Contents: ${item.content}, Unit: ${item.unit || 'N/A'}`);\n  });\n\n  // Example of accessing specific data:\n  const gtin = parsedData.find(item => item.ai === '01');\n  if (gtin) {\n    console.log(`\\nGTIN: ${gtin.content}`);\n  }\n\n  const lotBatch = parsedData.find(item => item.ai === '10');\n  if (lotBatch) {\n    console.log(`Lot/Batch Number: ${lotBatch.content}`);\n  }\n\n} catch (error) {\n  console.error('Error parsing barcode:', error.message);\n}","lang":"javascript","description":"Demonstrates parsing a sample GS1 barcode string and iterating through the extracted data elements, including accessing specific AIs like GTIN and Lot/Batch number."},"warnings":[{"fix":"Verify the package name in your `package.json` to ensure you are using the intended fork or the original.","message":"This package is an active fork (`gs1-barcode-parser-mod`) of the original `BarcodeParser` by Peter Brockfeld. Ensure you are installing the correct package if you have existing dependencies or expect a specific maintainer.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For critical applications, cross-reference parsed data with the official GS1 specification relevant to your use case. If newer AIs are required, consider contributing to the project or using an alternative library.","message":"The parser is based on 'GS1 General Specifications Version 14, Issue 1, Jan 2014'. Newer GS1 specifications or recently introduced Application Identifiers (AIs) might not be fully supported or correctly parsed.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Exercise due diligence when deploying in environments requiring strict GS1 compliance. Perform thorough testing with real-world barcodes relevant to your domain.","message":"The library is explicitly stated as an independent interpretation of the GS1 specification and is not endorsed, supported, or approved by GS1. Official compliance cannot be guaranteed.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Thoroughly test with a wide variety of GS1 barcode strings from your specific operational context to identify any unhandled cases or parsing inaccuracies.","message":"The README mentions 'Limitations' but the details are truncated. There may be specific edge cases or complex barcode structures that the parser does not handle as expected.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Always check if the result of `find()` is defined before accessing its properties, e.g., `const gtin = parsedData.find(item => item.ai === '01'); if (gtin) { console.log(gtin.content); }`","cause":"Attempting to access properties of a parsed data element that was not found by `find()` or similar array methods, indicating the expected Application Identifier (AI) was not present in the barcode string.","error":"TypeError: Cannot read properties of undefined (reading 'ai')"},{"fix":"Ensure the input string is a clean, raw GS1 barcode payload obtained directly from a scanner, usually starting with `]C1` for GS1 DataMatrix or similar symbology identifiers, and contains only valid barcode characters (digits, letters, FNC1).","cause":"The input string passed to `parseGS1Barcode` does not conform to the expected starting characters or overall structure of a GS1 barcode string, or contains characters not typically found in a barcode payload.","error":"Error parsing barcode: Input string does not start with a valid symbology identifier or contains invalid characters."},{"fix":"Ensure your environment supports ES modules (Node.js 12+ with `\"type\": \"module\"` in `package.json` or by using `.mjs` files), or switch to CommonJS `require` syntax if available, although this library primarily uses named ES module exports.","cause":"This error often indicates that you are trying to use ES module import syntax (`import`) in a CommonJS (`require`) environment (e.g., an older Node.js version or a non-transpiled script).","error":"SyntaxError: Unexpected token '{'"}],"ecosystem":"npm"}