@valentynb/gs1-parser 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Valentyn Blaha
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,247 @@
1
+ # GS1 Barcode Parser
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/gs1-barcode-parser-ts.svg?style=flat-square)](https://www.npmjs.com/package/gs1-barcode-parser-ts)
4
+ [![NPM downloads](https://img.shields.io/npm/dm/gs1-barcode-parser-ts.svg?style=flat-square)](https://www.npmjs.com/package/gs1-barcode-parser-ts)
5
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/YOUR_GITHUB_REPO/build.yml?style=flat-square)](https://github.com/YOUR_GITHUB_REPO/actions)
6
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)
7
+ [![Types Included](https://img.shields.io/badge/types-TypeScript-blue.svg?style=flat-square)](#)
8
+
9
+ A modern TypeScript library for parsing GS1 barcodes, supporting both ESModule and CommonJS formats.
10
+
11
+ ### Based on work from: https://github.com/PeterBrockfeld/BarcodeParser
12
+
13
+ ## Table of Contents
14
+
15
+ * [Purpose](#purpose)
16
+ * [Installation](#installation)
17
+ * [Disclaimer](#disclaimer)
18
+ * [The Specification](#the-specification)
19
+ * [About GS1 Barcodes](#about-gs1-barcodes)
20
+ * [About the Structure of GS1 Barcodes](#about-the-structure-of-gs1-barcodes)
21
+ * [Use Case](#use-case)
22
+ * [How to Use It](#how-to-use-it)
23
+ * [ESModule Usage](#esmodule-usage)
24
+ * [CommonJS Usage](#commonjs-usage)
25
+ * [TypeScript Usage](#typescript-usage)
26
+ * [Limitations](#limitations)
27
+ * [API Reference](#api-reference)
28
+ * [About Barcode Scanning Devices](#about-barcode-scanning-devices)
29
+ * [The FNC1 Character](#the-fnc1-character)
30
+ * [Key Press Detecting](#key-press-detecting)
31
+ * [Examples](#examples)
32
+ * [What's New](#whats-new)
33
+ * [License](#license)
34
+
35
+ ## Purpose
36
+
37
+ The barcode parser is a TypeScript library for handling the contents of GS1 barcodes. GS1 barcodes are used for various purposes, from simple product barcodes to complex codes describing the contents of an entire pallet. Two-dimensional barcodes can hold a significant amount of information, and this library makes it easier to access and process that data.
38
+
39
+ The barcode parser contains functions for parsing GS1 barcodes, yielding individual elements in a format easily processable by JavaScript and TypeScript applications.
40
+
41
+ The barcode parser is meant to be used in applications which:
42
+
43
+ * Take data from a barcode scanning device or barcode reading application
44
+ * Process the data
45
+ * Perform actions based on the barcode contents
46
+
47
+ ## Installation (not available yet)
48
+
49
+ ```bash
50
+ npm install @valentynb/gs1-parser
51
+ # or
52
+ yarn add @valentynb/gs1-parser
53
+ # or
54
+ pnpm add @valentynb/gs1-parser
55
+ ```
56
+
57
+ ## Disclaimer
58
+
59
+ This library is an independent interpretation of the GS1 specification. It is neither endorsed, supported, approved, nor recommended by GS1, and there are no affiliations with GS1.
60
+
61
+ ## The Specification
62
+
63
+ The full "GS1 General Specifications" can be found at [http://www.gs1.org/standards/genspecs](https://ref.gs1.org/standards/genspecs/). This library has been updated to comply with the **2025 version** of the GS1 specification.
64
+
65
+ ## About GS1 Barcodes
66
+
67
+ GS1 barcodes can contain comprehensive product information including:
68
+
69
+ * GTIN (Global Trade Item Number, formerly UPC or EAN)
70
+ * Weight or dimensions
71
+ * Price
72
+ * Lot/batch code
73
+ * Manufacturing date
74
+ * Expiration date
75
+ * And much more
76
+
77
+ ### About the Structure of GS1 Barcodes
78
+
79
+ A GS1 barcode is a concatenation of *data elements*. Each element starts with an *application identifier* (AI), a two to four digit number, followed by the actual information.
80
+
81
+ A *data element* is delimited by:
82
+
83
+ * The end of the barcode
84
+ * A fixed character count specification
85
+ * A special FNC1 character
86
+
87
+ The *application identifiers* and their properties are described in the third chapter of the GS1 General Specifications.
88
+
89
+ The GS1 barcode begins with a *symbology identifier* (a three-character sequence denoting the barcode type), followed by an arbitrary number of *data elements*. The parser decomposes this string into its individual elements.
90
+
91
+ ## Use Case
92
+
93
+ Your application receives a GS1 barcode as a string from a scanning device:
94
+
95
+ ```
96
+ ]C101040123456789011715012910ABC1233932978471131030005253922471142127649716
97
+ ```
98
+
99
+ The library extracts and parses the data into structured elements:
100
+
101
+ | AI | Title | Contents | Unit/Currency |
102
+ |:---|:------|:---------|:--------------|
103
+ | 01 | GTIN | 04012345678901 | |
104
+ | 17 | USE BY OR EXPIRY | 2015-01-29 | |
105
+ | 10 | BATCH/LOT | ABC123 | |
106
+ | 3932 | PRICE | 47.11 | 978 |
107
+ | 3103 | NET WEIGHT (kg) | 0.525 | KGM |
108
+ | 3922 | PRICE | 47.11 | |
109
+ | 421 | SHIP TO POST | 49716 | 276 |
110
+
111
+ ## How to Use It
112
+
113
+ ### ESModule Usage
114
+
115
+ ```typescript
116
+ import { GS1Parser } from '@valentynb/gs1-parser';
117
+
118
+ const gs1Parser = new GS1Parser(
119
+ {
120
+ lotMaxLength: 20 // If not specified, no limit is applied, except the one in the GS1 specs
121
+ fncChar: String.fromCodePoint(29); // If not specified, the GS char is used
122
+ }
123
+ );
124
+
125
+ try {
126
+ const barcodeString = document.getElementById("barcode").value;
127
+ // returns a DecodeResult object or throws an Error in case of parsing errors
128
+ const result = gs1Parser.decode(barcodeString);
129
+
130
+ console.log(result.codeName); // e.g., "GS1-128"
131
+ console.log(result.denormalized); // Full barcode with parentheses
132
+ console.log(result.data); // Dictionary of parsed elements
133
+ } catch (error) {
134
+ console.error('Barcode parsing failed:', error);
135
+ }
136
+ ```
137
+
138
+ ### CommonJS Usage
139
+
140
+ ```javascript
141
+ const { parseBarcode } = require('@valentynb/gs1-parser');
142
+
143
+ try {
144
+ const result = parseBarcode(barcodeString);
145
+ // Process result...
146
+ } catch (error) {
147
+ console.error('Barcode parsing failed:', error);
148
+ }
149
+ ```
150
+
151
+ ### TypeScript Usage
152
+
153
+ The library is written in TypeScript and includes full type definitions:
154
+
155
+ ```typescript
156
+ import { GS1Parser, BarcodeResult, ParsedElement } from '@valentynb/gs1-parser';
157
+
158
+ const gs1Parser = new GS1Parser(
159
+ {
160
+ lotMaxLength: 20 // If not specified, no limit is applied, except the one in the GS1 specs
161
+ fncChar: String.fromCodePoint(29); // If not specified, the GS char is used
162
+ }
163
+ );
164
+
165
+ try {
166
+ const result: BarcodeResult = gs1Parser.decode(barcodeString);
167
+
168
+ result.data.values().forEach((item: ParsedElement) => {
169
+ console.log(`AI: ${item.ai}`);
170
+ console.log(`Title: ${item.dataTitle}`);
171
+ console.log(`Data: ${item.data}`);
172
+ console.log(`Unit: ${item.unit || 'N/A'}`);
173
+ });
174
+ } catch (error) {
175
+ console.error('Error:', error);
176
+ }
177
+ ```
178
+
179
+ ### Limitations
180
+
181
+ The `decode()` method does not perform plausibility checks (as of now). If the barcode contains invalid data (e.g., an invalid GTIN or ISO code), the function will return this invalid content without validation.
182
+
183
+ ## API Reference
184
+
185
+ ### `GS1Parser.decode(barcode: string): BarcodeResult`
186
+
187
+ Parses a GS1 barcode string and returns structured data.
188
+
189
+ **Parameters:**
190
+ - `barcode` (string): The barcode string to parse
191
+
192
+ **Returns:** `BarcodeResult` object containing:
193
+ - `codeName` (string): Barcode type identifier (e.g., "GS1-128", "GS1-DataMatrix")
194
+ - `parsedCodeItems` (ParsedCodeItem[]): Array of parsed data elements
195
+
196
+ **ParsedCodeItem structure:**
197
+ - `ai` (string): Application identifier
198
+ - `title` (string): Description of the data element
199
+ - `data` (string | number | Date): The actual content
200
+ - `unit` (string | undefined): Unit of measurement, country code, or currency (ISO codes)
201
+
202
+ ## About Barcode Scanning Devices
203
+
204
+ GS1 barcodes are typically scanned using hardware barcode scanners configured as HID (Human Interface Device) keyboards. This works well for most characters but presents challenges with the FNC1 character.
205
+
206
+ ### The FNC1 Character
207
+
208
+ The FNC1 is a non-printable control character used to delimit GS1 Element Strings of variable length.
209
+
210
+ GS1 DataMatrix and GS1 QR Code use ASCII Group Separator (GS, ASCII 29, 0x1D, Unicode U+001D) as FNC1.
211
+
212
+ Since this character isn't on standard keyboards, scanners send control sequences as replacements. The canonical sequence is `Ctrl + ]`.
213
+
214
+ **Important:** Keyboard layout matters! A scanner emulating a German keyboard may send `Ctrl + +` instead of `Ctrl + ]`, which can trigger browser zoom. You'll need to:
215
+
216
+ 1. Identify the sequence your scanner sends
217
+ 2. Catch and transform these keyboard events into proper group separators
218
+
219
+ ### Key Press Detecting
220
+
221
+ To determine what control sequence your scanner sends, create a simple test page that logs keyboard events (`keyCode`, `charCode`, `which`) to the console when scanning test barcodes containing the GS character.
222
+
223
+ ## Examples
224
+
225
+ Example usage and test barcodes are included in the repository, demonstrating:
226
+
227
+ * Basic parsing operations
228
+ * Handling different barcode formats (GS1-128, DataMatrix, QR Code)
229
+ * Working with FNC1 characters
230
+ * Building scanning applications
231
+
232
+ ## What's New
233
+
234
+ This modernized version includes:
235
+
236
+ * **TypeScript**: Full TypeScript rewrite with complete type definitions
237
+ * **Dual Module Support**: Works with both ESModule (`import`) and CommonJS (`require`)
238
+ * **Updated Specification**: Complies with 2025 GS1 General Specifications
239
+ * **Reorganized Code**: Improved code structure and maintainability
240
+ * **Modern Build System**: Compatible with current JavaScript tooling
241
+
242
+ ## License
243
+
244
+ Copyright (c) 2014-2015 Peter Brockfeld (original version)
245
+ Copyright (c) 2025 Valentyn Blaha (This version)
246
+
247
+ See the LICENSE.md file for license rights and limitations (MIT).
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var l=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var r=(_,S)=>l(_,"name",{value:S,configurable:!0});var p=(_,S)=>{for(var E in S)l(_,E,{get:S[E],enumerable:!0})},b=(_,S,E,I)=>{if(S&&typeof S=="object"||typeof S=="function")for(let T of w(S))!B.call(_,T)&&T!==E&&l(_,T,{get:()=>S[T],enumerable:!(I=W(S,T))||I.enumerable});return _};var Q=_=>b(l({},"__esModule",{value:!0}),_);var y={};p(y,{GS1Parser:()=>h});module.exports=Q(y);var g={ai00:"sscc",ai01:"gtin",ai02:"content",ai10:"batch",ai11:"prodDate",ai12:"dueDate",ai13:"packDate",ai15:"bestBefore",ai16:"sellBy",ai17:"expDate",ai20:"variant",ai21:"serial",ai22:"hibcc",ai235:"tpx",ai240:"additionalProductID",ai241:"customerPartNumber",ai242:"madeToOrder",ai243:"packaging",ai250:"secondarySerialNumber",ai251:"refSource",ai253:"gdti",ai254:"glnExtension",ai255:"gcn",ai30:"variableCount",ai310:"netWeightKg0",ai3100:"netWeightKg0",ai3101:"netWeightKg1",ai3102:"netWeightKg2",ai3103:"netWeightKg3",ai3104:"netWeightKg4",ai3105:"netWeightKg5",ai3110:"lengthMeters0",ai3111:"lengthMeters1",ai3112:"lengthMeters2",ai3113:"lengthMeters3",ai3114:"lengthMeters4",ai3115:"lengthMeters5",ai3120:"widthMeters0",ai3121:"widthMeters1",ai3122:"widthMeters2",ai3123:"widthMeters3",ai3124:"widthMeters4",ai3125:"widthMeters5",ai3130:"heightMeters0",ai3131:"heightMeters1",ai3132:"heightMeters2",ai3133:"heightMeters3",ai3134:"heightMeters4",ai3135:"heightMeters5",ai3140:"areaSquareMeters0",ai3141:"areaSquareMeters1",ai3142:"areaSquareMeters2",ai3143:"areaSquareMeters3",ai3144:"areaSquareMeters4",ai3145:"areaSquareMeters5",ai3150:"netVolumeLiters0",ai3151:"netVolumeLiters1",ai3152:"netVolumeLiters2",ai3153:"netVolumeLiters3",ai3154:"netVolumeLiters4",ai3155:"netVolumeLiters5",ai3160:"netVolumeCubicMeters0",ai3161:"netVolumeCubicMeters1",ai3162:"netVolumeCubicMeters2",ai3163:"netVolumeCubicMeters3",ai3164:"netVolumeCubicMeters4",ai3165:"netVolumeCubicMeters5",ai3200:"netWeightLb0",ai3201:"netWeightLb1",ai3202:"netWeightLb2",ai3203:"netWeightLb3",ai3204:"netWeightLb4",ai3205:"netWeightLb5",ai3210:"lengthInches0",ai3211:"lengthInches1",ai3212:"lengthInches2",ai3213:"lengthInches3",ai3214:"lengthInches4",ai3215:"lengthInches5",ai3220:"lengthFeet0",ai3221:"lengthFeet1",ai3222:"lengthFeet2",ai3223:"lengthFeet3",ai3224:"lengthFeet4",ai3225:"lengthFeet5",ai3230:"lengthYards0",ai3231:"lengthYards1",ai3232:"lengthYards2",ai3233:"lengthYards3",ai3234:"lengthYards4",ai3235:"lengthYards5",ai3240:"widthInches0",ai3241:"widthInches1",ai3242:"widthInches2",ai3243:"widthInches3",ai3244:"widthInches4",ai3245:"widthInches5",ai3250:"widthFeet0",ai3251:"widthFeet1",ai3252:"widthFeet2",ai3253:"widthFeet3",ai3254:"widthFeet4",ai3255:"widthFeet5",ai3260:"widthYards0",ai3261:"widthYards1",ai3262:"widthYards2",ai3263:"widthYards3",ai3264:"widthYards4",ai3265:"widthYards5",ai3270:"heightInches0",ai3271:"heightInches1",ai3272:"heightInches2",ai3273:"heightInches3",ai3274:"heightInches4",ai3275:"heightInches5",ai3280:"heightFeet0",ai3281:"heightFeet1",ai3282:"heightFeet2",ai3283:"heightFeet3",ai3284:"heightFeet4",ai3285:"heightFeet5",ai3290:"heightYards0",ai3291:"heightYards1",ai3292:"heightYards2",ai3293:"heightYards3",ai3294:"heightYards4",ai3295:"heightYards5",ai3300:"grossWeightKg0",ai3301:"grossWeightKg1",ai3302:"grossWeightKg2",ai3303:"grossWeightKg3",ai3304:"grossWeightKg4",ai3305:"grossWeightKg5",ai3310:"lengthMetersLog0",ai3311:"lengthMetersLog1",ai3312:"lengthMetersLog2",ai3313:"lengthMetersLog3",ai3314:"lengthMetersLog4",ai3315:"lengthMetersLog5",ai3320:"widthMetersLog0",ai3321:"widthMetersLog1",ai3322:"widthMetersLog2",ai3323:"widthMetersLog3",ai3324:"widthMetersLog4",ai3325:"widthMetersLog5",ai3330:"heightMetersLog0",ai3331:"heightMetersLog1",ai3332:"heightMetersLog2",ai3333:"heightMetersLog3",ai3334:"heightMetersLog4",ai3335:"heightMetersLog5",ai3340:"areaSquareInches0",ai3341:"areaSquareInches1",ai3342:"areaSquareInches2",ai3343:"areaSquareInches3",ai3344:"areaSquareInches4",ai3345:"areaSquareInches5",ai3350:"areaSquareFeet0",ai3351:"areaSquareFeet1",ai3352:"areaSquareFeet2",ai3353:"areaSquareFeet3",ai3354:"areaSquareFeet4",ai3355:"areaSquareFeet5",ai3360:"areaSquareYards0",ai3361:"areaSquareYards1",ai3362:"areaSquareYards2",ai3363:"areaSquareYards3",ai3364:"areaSquareYards4",ai3365:"areaSquareYards5",ai3370:"areaSquareMetersLog0",ai3371:"areaSquareMetersLog1",ai3372:"areaSquareMetersLog2",ai3373:"areaSquareMetersLog3",ai3374:"areaSquareMetersLog4",ai3375:"areaSquareMetersLog5",ai3400:"netWeightOunces0",ai3401:"netWeightOunces1",ai3402:"netWeightOunces2",ai3403:"netWeightOunces3",ai3404:"netWeightOunces4",ai3405:"netWeightOunces5",ai3410:"netVolumeQuarts0",ai3411:"netVolumeQuarts1",ai3412:"netVolumeQuarts2",ai3413:"netVolumeQuarts3",ai3414:"netVolumeQuarts4",ai3415:"netVolumeQuarts5",ai3420:"netVolumeGallons0",ai3421:"netVolumeGallons1",ai3422:"netVolumeGallons2",ai3423:"netVolumeGallons3",ai3424:"netVolumeGallons4",ai3425:"netVolumeGallons5",ai3430:"volumeCubicInches0",ai3431:"volumeCubicInches1",ai3432:"volumeCubicInches2",ai3433:"volumeCubicInches3",ai3434:"volumeCubicInches4",ai3435:"volumeCubicInches5",ai3440:"volumeCubicFeet0",ai3441:"volumeCubicFeet1",ai3442:"volumeCubicFeet2",ai3443:"volumeCubicFeet3",ai3444:"volumeCubicFeet4",ai3445:"volumeCubicFeet5",ai3450:"volumeCubicYards0",ai3451:"volumeCubicYards1",ai3452:"volumeCubicYards2",ai3453:"volumeCubicYards3",ai3454:"volumeCubicYards4",ai3455:"volumeCubicYards5",ai3460:"volumeCubicMetersLog0",ai3461:"volumeCubicMetersLog1",ai3462:"volumeCubicMetersLog2",ai3463:"volumeCubicMetersLog3",ai3464:"volumeCubicMetersLog4",ai3465:"volumeCubicMetersLog5",ai3500:"grossWeightLb0",ai3501:"grossWeightLb1",ai3502:"grossWeightLb2",ai3503:"grossWeightLb3",ai3504:"grossWeightLb4",ai3505:"grossWeightLb5",ai3510:"lengthInchesLog0",ai3511:"lengthInchesLog1",ai3512:"lengthInchesLog2",ai3513:"lengthInchesLog3",ai3514:"lengthInchesLog4",ai3515:"lengthInchesLog5",ai3520:"lengthFeetLog0",ai3521:"lengthFeetLog1",ai3522:"lengthFeetLog2",ai3523:"lengthFeetLog3",ai3524:"lengthFeetLog4",ai3525:"lengthFeetLog5",ai3530:"lengthYardsLog0",ai3531:"lengthYardsLog1",ai3532:"lengthYardsLog2",ai3533:"lengthYardsLog3",ai3534:"lengthYardsLog4",ai3535:"lengthYardsLog5",ai3540:"widthInchesLog0",ai3541:"widthInchesLog1",ai3542:"widthInchesLog2",ai3543:"widthInchesLog3",ai3544:"widthInchesLog4",ai3545:"widthInchesLog5",ai3550:"widthFeetLog0",ai3551:"widthFeetLog1",ai3552:"widthFeetLog2",ai3553:"widthFeetLog3",ai3554:"widthFeetLog4",ai3555:"widthFeetLog5",ai3560:"widthYardsLog0",ai3561:"widthYardsLog1",ai3562:"widthYardsLog2",ai3563:"widthYardsLog3",ai3564:"widthYardsLog4",ai3565:"widthYardsLog5",ai3570:"heightInchesLog0",ai3571:"heightInchesLog1",ai3572:"heightInchesLog2",ai3573:"heightInchesLog3",ai3574:"heightInchesLog4",ai3575:"heightInchesLog5",ai3580:"heightFeetLog0",ai3581:"heightFeetLog1",ai3582:"heightFeetLog2",ai3583:"heightFeetLog3",ai3584:"heightFeetLog4",ai3585:"heightFeetLog5",ai3590:"heightYardsLog0",ai3591:"heightYardsLog1",ai3592:"heightYardsLog2",ai3593:"heightYardsLog3",ai3594:"heightYardsLog4",ai3595:"heightYardsLog5",ai3600:"grossWeightOunces0",ai3601:"grossWeightOunces1",ai3602:"grossWeightOunces2",ai3603:"grossWeightOunces3",ai3604:"grossWeightOunces4",ai3605:"grossWeightOunces5",ai3610:"netVolumeFluidOunces0",ai3611:"netVolumeFluidOunces1",ai3612:"netVolumeFluidOunces2",ai3613:"netVolumeFluidOunces3",ai3614:"netVolumeFluidOunces4",ai3615:"netVolumeFluidOunces5",ai3620:"grossVolumeQuarts0",ai3621:"grossVolumeQuarts1",ai3622:"grossVolumeQuarts2",ai3623:"grossVolumeQuarts3",ai3624:"grossVolumeQuarts4",ai3625:"grossVolumeQuarts5",ai3630:"grossVolumeGallons0",ai3631:"grossVolumeGallons1",ai3632:"grossVolumeGallons2",ai3633:"grossVolumeGallons3",ai3634:"grossVolumeGallons4",ai3635:"grossVolumeGallons5",ai3640:"volumeCubicInchesLog0",ai3641:"volumeCubicInchesLog1",ai3642:"volumeCubicInchesLog2",ai3643:"volumeCubicInchesLog3",ai3644:"volumeCubicInchesLog4",ai3645:"volumeCubicInchesLog5",ai3650:"volumeCubicFeetLog0",ai3651:"volumeCubicFeetLog1",ai3652:"volumeCubicFeetLog2",ai3653:"volumeCubicFeetLog3",ai3654:"volumeCubicFeetLog4",ai3655:"volumeCubicFeetLog5",ai3660:"volumeCubicYardsLog0",ai3661:"volumeCubicYardsLog1",ai3662:"volumeCubicYardsLog2",ai3663:"volumeCubicYardsLog3",ai3664:"volumeCubicYardsLog4",ai3665:"volumeCubicYardsLog5",ai37:"count",ai3900:"amountPayable0",ai3901:"amountPayable1",ai3902:"amountPayable2",ai3903:"amountPayable3",ai3904:"amountPayable4",ai3905:"amountPayable5",ai3910:"amountPayableISO0",ai3911:"amountPayableISO1",ai3912:"amountPayableISO2",ai3913:"amountPayableISO3",ai3914:"amountPayableISO4",ai3915:"amountPayableISO5",ai3920:"price0",ai3921:"price1",ai3922:"price2",ai3923:"price3",ai3930:"priceISO0",ai3931:"priceISO1",ai3932:"priceISO2",ai3933:"priceISO3",ai3940:"percentDiscount0",ai3941:"percentDiscount1",ai3942:"percentDiscount2",ai3943:"percentDiscount3",ai3950:"pricePerUnitMeasure0",ai3951:"pricePerUnitMeasure1",ai3952:"pricePerUnitMeasure2",ai3953:"pricePerUnitMeasure3",ai3954:"pricePerUnitMeasure4",ai3955:"pricePerUnitMeasure5",ai400:"orderNumber",ai401:"ginc",ai402:"gsin",ai403:"route",ai410:"shipTo",ai411:"billTo",ai412:"purchaseFrom",ai413:"shipFor",ai414:"locNo",ai415:"payTo",ai416:"prodServLoc",ai417:"party",ai420:"shipToPost",ai421:"shipToPostISO",ai422:"origin",ai423:"countryInitialProcess",ai424:"countryProcess",ai425:"countryDisassembly",ai426:"countryFullProcess",ai427:"originSubdivision",ai7001:"nsn",ai7002:"meatCut",ai7003:"expirationDateTime",ai7004:"activePotency",ai7005:"catchArea",ai7006:"firstFreezeDate",ai7007:"harvestDate",ai7008:"aquaticSpecies",ai7009:"fishingGearType",ai7010:"prodMethod",ai7020:"refurbLot",ai7021:"funcStat",ai7022:"revStat",ai7023:"giaiAssembly",ai7030:"processor",ai7031:"processor2",ai7032:"processor3",ai7033:"processor4",ai7034:"processor5",ai7035:"processor6",ai7036:"processor7",ai7037:"processor8",ai7038:"processor9",ai7039:"processor10",ai7040:"uicExt",ai8001:"rollProducts",ai8002:"cmtNo",ai8003:"grai",ai8004:"giai",ai8005:"pricePerUnit",ai8006:"itip",ai8007:"iban",ai8008:"prodTime",ai8009:"opticalSensor",ai8010:"cpid",ai8011:"cpidSerial",ai8012:"version",ai8013:"gmn",ai8017:"gsrnProvider",ai8018:"gsrnRecipient",ai8019:"srin",ai8020:"refNo",ai8026:"itipContent",ai8030:"coupon",ai8110:"couponExtended",ai8111:"couponExtended2",ai8112:"couponExtended3",ai8200:"productURL",ai90:"internal1",ai91:"internal2",ai92:"internal3",ai93:"internal4",ai94:"internal5",ai95:"internal6",ai96:"internal7",ai97:"internal8",ai98:"internal9",ai99:"internal10"};var M=String.fromCodePoint(29),o=/^\d+$/;var A=class extends Error{static{r(this,"InternalError")}constructor(S,E){super(S),this.name="InternalError",this.code=S,this.ex=E}ex;code},O=class extends Error{static{r(this,"InvalidAiError")}constructor(S,E){let I;S?I=`Invalid AI identifier "${E}" after "${S}"`:I=`Invalid first AI identifier "${E}"`,super(I),this.name="InvalidAiError"}},G=class extends Error{static{r(this,"BarcodeError")}constructor(S,E,I){super(I),this.name="BarcodeError",this.num=S,this.code=E,this.des=I}num;code;des},H=class{static{r(this,"ParsedElementClass")}ai;dataTitle;data;dataString;unit;constructor(S,E,I){switch(this.ai=S,this.dataTitle=E,this.unit="",this.dataString="",I){case"S":this.data="";break;case"N":this.data=0;break;case"D":this.data=new Date,this.data.setHours(0,0,0,0);break;default:this.data="";break}}},C=class{constructor(S,E,I={}){this.codeName=S;this.denormalized=E;this.data=I}static{r(this,"DecodeResult")}};function m(_,S){let E=_,I=E.slice(0,1);for(;I===S;)E=E.slice(1),I=E.slice(0,1);return E}r(m,"cleanCodestring");function F(_,S,E){if(S<0||S>11)return!1;let I=S;E===0&&I++;let T=new Date(_,I,E);return T.getFullYear()===_&&T.getMonth()===S&&(T.getDate()===E||E===0)}r(F,"checkValidDate");function D(_,S){let E=_.length-S,I=_.slice(0,E)+"."+_.slice(E);try{return Number.parseFloat(I)}catch(T){throw new A("36",T)}}r(D,"parseFloatingPoint");function u(_,S,E){let I=new H(_,S,"D"),T=_.length,a=E.slice(T,T+6),e=0,L=0,R=0;try{e=Number.parseInt(a.slice(0,2),10)}catch(N){throw new A("33",N)}try{L=Number.parseInt(a.slice(2,4),10)-1}catch(N){throw new A("34",N)}try{R=Number.parseInt(a.slice(4,6),10)}catch(N){throw new A("35",N)}if(e>50?e=e+1900:e=e+2e3,!F(e,L,R))throw new G(7,"36",`Invalid date "${a}" for AI "${_}".`);return R===0&&L++,I.data.setFullYear(e,L,R),I.dataString=a,{element:I,codestring:E.slice(T+6,E.length)}}r(u,"parseDate");function s(_,S,E,I,T=!1){let a=new H(_,S,"S"),e=_.length,L=I.slice(e,E+e);if(L.length<E)throw new G(9,"37",`Data length ${L.length} is less than expected length ${E} for AI "${_}".`);if(T&&!o.test(L))throw new G(11,"39",`Numeric data expected for AI "${_}", but got "${L}".`);a.data=L,a.dataString=L;let R=I.slice(E+e,I.length);return{element:a,codestring:R}}r(s,"parseFixedLength");function t(_,S,E,I,T,a=!1){let e=new H(_,S,"S"),L=_.length,R=E.indexOf(I),N="";if(R===-1?T&&T>0?(e.data=E.slice(L,T+L),N=E.replace(_+e.data,"")):e.data=E.slice(L,E.length):(e.data=E.slice(L,R),N=E.slice(R+1,E.length)),e.data==="")throw new G(10,"38",`Variable length data for AI "${_}" is empty.`);if(a&&!o.test(e.data))throw new G(11,"39",`Numeric data expected for AI "${_}", but got "${e.data}".`);return e.dataString=e.data,{element:e,codestring:N}}r(t,"parseVariableLength");function c(_,S,E,I,T,a){let e=new H(_+S,E,"N"),L=_.length+1,R=T.indexOf(a),N=Number.parseInt(S,10),n="",U="";return R===-1?n=T.slice(L,T.length):(n=T.slice(L,R),U=T.slice(R+1,T.length)),e.data=D(n,N),e.dataString=n,e.unit=I,{element:e,codestring:U}}r(c,"parseVariableLengthMeasure");function i(_,S,E,I,T){let a=new H(_+S,E,"N"),e=_.length+1,L=Number.parseInt(S,10),R=T.slice(e,e+6);a.data=D(R,L),a.dataString=R,a.unit=I;let N=T.slice(e+6,T.length);return{element:a,codestring:N}}r(i,"parseFixedLengthMeasure");function P(_,S,E,I,T){let a=new H(_+S,E,"N"),e=_.length+1,L=I.indexOf(T),R=Number.parseInt(S,10),N="",n="",U="";return L===-1?N=I.slice(e,I.length):(N=I.slice(e,L),U=I.slice(L+1,I.length)),n=N.slice(3,N.length),a.data=D(n,R),a.dataString=n,a.unit=N.slice(0,3),{element:a,codestring:U}}r(P,"parseVariableLengthWithISONumbers");function V(_,S,E,I){let T=new H(_,S,"S"),a=_.length,e=E.indexOf(I),L="",R="";return e===-1?L=E.slice(a,E.length):(L=E.slice(a,e),R=E.slice(e+1,E.length)),T.data=L.slice(3,L.length),T.unit=L.slice(0,3),T.dataString=L,{element:T,codestring:R}}r(V,"parseVariableLengthWithISOChars");function f(_,S,E){E||(E=M);let I=_.slice(0,1),T=_.slice(1,2),a="",e="";switch(I){case"0":switch(T){case"0":return s("00","SSCC",18,_,!0);case"1":return s("01","GTIN",14,_,!0);case"2":return s("02","CONTENT",14,_);case"3":return s("03","MTO GTIN",14,_);default:throw new O("0",T)}case"1":switch(T){case"0":return t("10","BATCH/LOT",_,E,S??20);case"1":return u("11","PROD DATE",_);case"2":return u("12","DUE DATE",_);case"3":return u("13","PACK DATE",_);case"5":return u("15","BEST BEFORE or BEST BY",_);case"6":return u("16","SELL BY",_);case"7":return u("17","USE BY OR EXPIRY",_);default:throw new O("1",T)}case"2":switch(T){case"0":return s("20","VARIANT",2,_);case"1":return t("21","SERIAL",_,E,S??20);case"2":return t("22","CPV",_,E,20);case"3":switch(a=_.slice(2,3),a){case"5":return t("235","TPX",_,E,28);default:throw new O("23",a)}case"4":switch(a=_.slice(2,3),a){case"0":return t("240","ADDITIONAL ID",_,E,30);case"1":return t("241","CUST. PART NO.",_,E,30);case"2":return t("242","MTO VARIANT",_,E,6);case"3":return t("243","PCN",_,E,20);default:throw new O("24",a)}case"5":switch(a=_.slice(2,3),a){case"0":return t("250","SECONDARY SERIAL",_,E,30);case"1":return t("251","REF. TO SOURCE",_,E,30);case"3":return t("253","GDTI",_,E,42);case"4":return t("254","GLN EXTENSION COMPONENT",_,E,20);case"5":return t("255","GCN",_,E,37);default:throw new O("25",a)}default:throw new O("2",T)}case"3":switch(T){case"0":return t("30","VAR. COUNT",_,E,8);case"1":switch(a=_.slice(2,3),e=_.slice(3,4),a){case"0":return i("310",e,"NET WEIGHT (kg)","KGM",_);case"1":return i("311",e,"LENGTH (m)","MTR",_);case"2":return i("312",e,"WIDTH (m)","MTR",_);case"3":return i("313",e,"HEIGHT (m)","MTR",_);case"4":return i("314",e,"AREA (m2)","MTK",_);case"5":return i("315",e,"NET VOLUME (l)","LTR",_);case"6":return i("316",e,"NET VOLUME (m3)","MTQ",_);default:throw new O("31",a)}case"2":switch(a=_.slice(2,3),e=_.slice(3,4),a){case"0":return i("320",e,"NET WEIGHT (lb)","LBR",_);case"1":return i("321",e,"LENGTH (i)","INH",_);case"2":return i("322",e,"LENGTH (f)","FOT",_);case"3":return i("323",e,"LENGTH (y)","YRD",_);case"4":return i("324",e,"WIDTH (i)","INH",_);case"5":return i("325",e,"WIDTH (f)","FOT",_);case"6":return i("326",e,"WIDTH (y)","YRD",_);case"7":return i("327",e,"HEIGHT (i)","INH",_);case"8":return i("328",e,"HEIGHT (f)","FOT",_);case"9":return i("329",e,"HEIGHT (y)","YRD",_);default:throw new O("32",a)}case"3":switch(a=_.slice(2,3),e=_.slice(3,4),a){case"0":return i("330",e,"GROSS WEIGHT (kg)","KGM",_);case"1":return i("331",e,"LENGTH (m), log","MTR",_);case"2":return i("332",e,"WIDTH (m), log","MTR",_);case"3":return i("333",e,"HEIGHT (m), log","MTR",_);case"4":return i("334",e,"AREA (m2), log","MTK",_);case"5":return i("335",e,"VOLUME (l), log","LTR",_);case"6":return i("336",e,"VOLUME (m3), log","MTQ",_);case"7":return i("337",e,"KG PER m\xB2","28",_);default:throw new O("33",a)}case"4":switch(a=_.slice(2,3),e=_.slice(3,4),a){case"0":return i("340",e,"GROSS WEIGHT (lb)","LBR",_);case"1":return i("341",e,"LENGTH (i), log","INH",_);case"2":return i("342",e,"LENGTH (f), log","FOT",_);case"3":return i("343",e,"LENGTH (y), log","YRD",_);case"4":return i("344",e,"WIDTH (i), log","INH",_);case"5":return i("345",e,"WIDTH (f), log","FOT",_);case"6":return i("346",e,"WIDTH (y), log","YRD",_);case"7":return i("347",e,"HEIGHT (i), log","INH",_);case"8":return i("348",e,"HEIGHT (f), log","FOT",_);case"9":return i("349",e,"HEIGHT (y), log","YRD",_);default:throw new O("33",a)}case"5":switch(a=_.slice(2,3),e=_.slice(3,4),a){case"0":return i("350",e,"AREA (i2)","INK",_);case"1":return i("351",e,"AREA (f2)","FTK",_);case"2":return i("352",e,"AREA (y2)","YDK",_);case"3":return i("353",e,"AREA (i2), log","INK",_);case"4":return i("354",e,"AREA (f2), log","FTK",_);case"5":return i("355",e,"AREA (y2), log","YDK",_);case"6":return i("356",e,"NET WEIGHT (t)","APZ",_);case"7":return i("357",e,"NET VOLUME (oz)","ONZ",_);default:throw new O("35",a)}case"6":switch(a=_.slice(2,3),e=_.slice(3,4),a){case"0":return i("360",e,"NET VOLUME (q)","QT",_);case"1":return i("361",e,"NET VOLUME (g)","GLL",_);case"2":return i("362",e,"VOLUME (q), log","QT",_);case"3":return i("363",e,"VOLUME (g), log","GLL",_);case"4":return i("364",e,"VOLUME (i3)","INQ",_);case"5":return i("365",e,"VOLUME (f3)","FTQ",_);case"6":return i("366",e,"VOLUME (y3)","YDQ",_);case"7":return i("367",e,"VOLUME (i3), log","INQ",_);case"8":return i("368",e,"VOLUME (f3), log","FTQ",_);case"9":return i("369",e,"VOLUME (y3), log","YDQ",_);default:throw new O("36",a)}case"7":return t("37","COUNT",_,E,8);case"9":switch(a=_.slice(2,3),e=_.slice(3,4),a){case"0":return c("390",e,"AMOUNT","",_,E);case"1":return P("391",e,"AMOUNT",_,E);case"2":return c("392",e,"PRICE","",_,E);case"3":return P("393",e,"PRICE",_,E);default:throw new O("39",a)}default:throw new O("3",T)}case"4":switch(T){case"0":switch(a=_.slice(2,3),a){case"0":return t("400","ORDER NUMBER",_,E,30);case"1":return t("401","GINC",_,E);case"2":return t("402","GSIN",_,E,17);case"3":return t("403","ROUTE",_,E,30);default:throw new O("40",a)}case"1":switch(a=_.slice(2,3),a){case"0":return s("410","SHIP TO LOC",13,_);case"1":return s("411","BILL TO",13,_);case"2":return s("412","PURCHASE FROM",13,_);case"3":return s("413","SHIP FOR LOC",13,_);case"4":return s("414","LOC NO",13,_);case"5":return s("415","PAY TO",13,_);case"6":return s("416","PROD/SERV LOC",13,_);case"7":return s("417","PARTY",13,_);default:throw new O("41",a)}case"2":switch(a=_.slice(2,3),a){case"0":return t("420","SHIP TO POST",_,E,20);case"1":return V("421","SHIP TO POST",_,E);case"2":return s("422","ORIGIN",3,_);case"3":return t("423","COUNTRY - INITIAL PROCESS.",_,E,15);case"4":return s("424","COUNTRY - PROCESS.",3,_);case"5":return s("425","COUNTRY - DISASSEMBLY",3,_);case"6":return s("426","COUNTRY - FULL PROCESS",3,_);case"7":return t("427","ORIGIN SUBDIVISION",_,E,3);default:throw new O("42",a)}default:throw new O("4",T)}case"7":switch(T){case"0":switch(a=_.slice(2,3),e=_.slice(3,4),a){case"0":switch(e){case"1":return t("7001","NSN",_,E,13);case"2":return t("7002","MEAT CUT",_,E);case"3":return t("7003","EXPIRY TIME",_,E,10);case"4":return t("7004","ACTIVE POTENCY",_,E,6);default:throw new O("70",a)}case"3":return V("703"+e,"PROCESSOR # "+e,_,E);default:throw new O("70",a)}case"1":switch(a=_.slice(2,3),a){case"0":return t("710","NHRN PZN",_,E);case"1":return t("711","NHRN CIP",_,E);case"2":return t("712","NHRN CN",_,E);case"3":return t("713","NHRN DRN",_,E);default:throw new O("71",a)}default:throw new O("7",T)}case"8":switch(T){case"0":switch(a=_.slice(2,3),e=_.slice(3,4),a){case"0":switch(e){case"1":return t("8001","DIMENSIONS",_,E,14);case"2":return t("8002","CMT No",_,E);case"3":return t("8003","GRAI",_,E);case"4":return t("8004","GIAI",_,E);case"5":return t("8005","PRICE PER UNIT",_,E,6);case"6":return t("8006","GCTIN",_,E,18);case"7":return t("8007","IBAN",_,E);case"8":return t("8008","PROD TIME",_,E,12);default:throw new O("800",e)}case"1":switch(e){case"0":return t("8010","CPID",_,E);case"1":return t("8011","CPID SERIAL",_,E);case"7":return t("8017","GSRN - PROVIDER",_,E,18);case"8":return t("8018","GSRN - RECIPIENT",_,E,18,!0);case"9":return t("8019","SRIN",_,E,void 0,!0);default:throw new O("801",e)}case"2":switch(e){case"0":return t("8020","REF No",_,E);default:throw new O("802",e)}default:throw new O("80",a)}case"1":switch(a=_.slice(2,3),e=_.slice(3,4),a){case"0":switch(e){case"0":return t("8100","-",_,E,6);case"1":return t("8101","-",_,E,10);case"2":return t("8102","-",_,E,2);default:throw new O("810",e)}case"1":switch(e){case"0":return t("8110","-",_,E);default:throw new O("811",e)}default:throw new O("81",a)}case"2":switch(a=_.slice(2,3),a){case"0":return t("8200","PRODUCT URL",_,E);default:throw new O("82",a)}default:throw new O("8",T)}case"9":switch(T){case"0":return t("90","INTERNAL",_,E);case"1":return t("91","INTERNAL",_,E);case"2":return t("92","INTERNAL",_,E);case"3":return t("93","INTERNAL",_,E);case"4":return t("94","INTERNAL",_,E);case"5":return t("95","INTERNAL",_,E);case"6":return t("96","INTERNAL",_,E);case"7":return t("97","INTERNAL",_,E);case"8":return t("98","INTERNAL",_,E);case"9":return t("99","INTERNAL",_,E);default:throw new O("9",T)}default:throw new O("",I)}}r(f,"identifyAI");function Y(_,S,E){if(!_||typeof _!="string")throw new G(2,"31","The barcode is empty or not a string.");let I=_.length,T={codeName:"",denormalized:"",parsedCodeItems:[]},a="",e=_.slice(0,3),L;switch(e){case"]C1":T.codeName="GS1-128",a=_.slice(3,I);break;case"]e0":T.codeName="GS1 DataBar",a=_.slice(3,I);break;case"]e1":case"]e2":T.codeName="GS1 Composite",a=_.slice(3,I);break;case"]d2":T.codeName="GS1 DataMatrix",a=_.slice(3,I);break;case"]Q3":T.codeName="GS1 QR Code",a=_.slice(3,I);break;default:T.codeName="",a=_;break}for(T.parsedCodeItems=[];a.length>0;)try{L=f(a,E),a=m(L.codestring,S),T.parsedCodeItems.push(L.element),T.denormalized+="("+L.element.ai+")"+L.element.dataString}catch(R){if(R instanceof A)v(R);else throw R}return T}r(Y,"parseBarcode");function v(_){switch(_.code){case"32":throw new G(6,32,"Invalid normal AI.");case"33":throw new G(7,33,"L'anno nella data non \xE8 valido.");case"34":throw new G(7,34,"Il mese nella data non \xE8 valido.");case"36":throw new G(8,36,"Numeri non validi");default:throw _}}r(v,"handleInternalError");var h=class{static{r(this,"GS1Parser")}fncChar;lotLen;constructor(S){this.fncChar=S?.fncChar||M,this.lotLen=S?.lotMaxLength}decode(S){let E=S.replaceAll("(",this.fncChar).replaceAll(")","");E.startsWith(this.fncChar)&&(E=E.slice(1));let I=Y(E,this.fncChar,this.lotLen),T={};for(let a of I.parsedCodeItems){let e=g["ai"+a.ai];e&&(T[e]=a)}return new C(I.codeName,I.denormalized,T)}};0&&(module.exports={GS1Parser});