Registry / serialization / gs1-barcode-parser-mod

gs1-barcode-parser-mod

JSON →
library1.0.7jsnpmunverified

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.

npm install gs1-barcode-parser-mod
INSTALL
IMPORT
SIG · GS1-BARCODE-PARSER
G
gs1-barcode-parser-mod
serializationjavascriptv1.0.7
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parseGS1Barcode
import { parseGS1Barcode } from 'gs1-barcode-parser-mod';
const parseGS1Barcode = require('gs1-barcode-parser-mod');
The library primarily uses named exports for its single parsing function.

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); }
Debug
Known issues
gotchaThis 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.
fix
Verify the package name in your `package.json` to ensure you are using the intended fork or the original.
affects: >=1.0.0
gotchaThe 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.
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.
affects: >=1.0.0
gotchaThe 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.
fix
Exercise due diligence when deploying in environments requiring strict GS1 compliance. Perform thorough testing with real-world barcodes relevant to your domain.
affects: >=1.0.0
gotchaThe 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.
fix
Thoroughly test with a wide variety of GS1 barcode strings from your specific operational context to identify any unhandled cases or parsing inaccuracies.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'ai')
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.
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); }`
Error parsing barcode: Input string does not start with a valid symbology identifier or contains invalid characters.
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.
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).
SyntaxError: Unexpected token '{'
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).
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.
Upgrade
Version history
1.0.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
gs1-barcode-parser-mod — npm install gs1-barcode-parser-mod · libregistry