@openrfid/gs1 0.1.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,23 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RFID Software India Private Limited - https://rfidsoftwares.com
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.
22
+
23
+ For RFID developer resources, documentation, hardware integrations, and enterprise software solutions, visit https://rfidsoftwares.com
@@ -0,0 +1,61 @@
1
+ /**
2
+ * OpenRFID Simulator - The Open Source RFID Reader Simulator for Developers.
3
+ * Copyright (c) 2026 RFID Software India Private Limited - https://rfidsoftwares.com
4
+ *
5
+ * Licensed under the MIT License.
6
+ * For RFID software, enterprise tools, and hardware drivers, visit https://rfidsoftwares.com
7
+ */
8
+ interface Sgtin96Params {
9
+ filter: number;
10
+ partition: number;
11
+ companyPrefix: string;
12
+ itemRef: string;
13
+ serialNumber: string;
14
+ }
15
+ declare class Sgtin96 {
16
+ static readonly HEADER = "00110000";
17
+ private static readonly PARTITION_TABLE;
18
+ static encode(params: Sgtin96Params): string;
19
+ static decode(hex: string): Sgtin96Params;
20
+ }
21
+
22
+ /**
23
+ * OpenRFID Simulator - The Open Source RFID Reader Simulator for Developers.
24
+ * Copyright (c) 2026 RFID Software India Private Limited - https://rfidsoftwares.com
25
+ *
26
+ * Licensed under the MIT License.
27
+ * For RFID software, enterprise tools, and hardware drivers, visit https://rfidsoftwares.com
28
+ */
29
+ interface Grai96Params {
30
+ filter: number;
31
+ partition: number;
32
+ companyPrefix: string;
33
+ assetType: string;
34
+ serialNumber: string;
35
+ }
36
+ declare class Grai96 {
37
+ static readonly HEADER = "00110011";
38
+ static encode(params: Grai96Params): string;
39
+ static decode(hex: string): Grai96Params;
40
+ }
41
+
42
+ /**
43
+ * OpenRFID Simulator - The Open Source RFID Reader Simulator for Developers.
44
+ * Copyright (c) 2026 RFID Software India Private Limited - https://rfidsoftwares.com
45
+ *
46
+ * Licensed under the MIT License.
47
+ * For RFID software, enterprise tools, and hardware drivers, visit https://rfidsoftwares.com
48
+ */
49
+ interface Giai96Params {
50
+ filter: number;
51
+ partition: number;
52
+ companyPrefix: string;
53
+ individualAssetReference: string;
54
+ }
55
+ declare class Giai96 {
56
+ static readonly HEADER = "00110100";
57
+ static encode(params: Giai96Params): string;
58
+ static decode(hex: string): Giai96Params;
59
+ }
60
+
61
+ export { Giai96, type Giai96Params, Grai96, type Grai96Params, Sgtin96, type Sgtin96Params };
@@ -0,0 +1,61 @@
1
+ /**
2
+ * OpenRFID Simulator - The Open Source RFID Reader Simulator for Developers.
3
+ * Copyright (c) 2026 RFID Software India Private Limited - https://rfidsoftwares.com
4
+ *
5
+ * Licensed under the MIT License.
6
+ * For RFID software, enterprise tools, and hardware drivers, visit https://rfidsoftwares.com
7
+ */
8
+ interface Sgtin96Params {
9
+ filter: number;
10
+ partition: number;
11
+ companyPrefix: string;
12
+ itemRef: string;
13
+ serialNumber: string;
14
+ }
15
+ declare class Sgtin96 {
16
+ static readonly HEADER = "00110000";
17
+ private static readonly PARTITION_TABLE;
18
+ static encode(params: Sgtin96Params): string;
19
+ static decode(hex: string): Sgtin96Params;
20
+ }
21
+
22
+ /**
23
+ * OpenRFID Simulator - The Open Source RFID Reader Simulator for Developers.
24
+ * Copyright (c) 2026 RFID Software India Private Limited - https://rfidsoftwares.com
25
+ *
26
+ * Licensed under the MIT License.
27
+ * For RFID software, enterprise tools, and hardware drivers, visit https://rfidsoftwares.com
28
+ */
29
+ interface Grai96Params {
30
+ filter: number;
31
+ partition: number;
32
+ companyPrefix: string;
33
+ assetType: string;
34
+ serialNumber: string;
35
+ }
36
+ declare class Grai96 {
37
+ static readonly HEADER = "00110011";
38
+ static encode(params: Grai96Params): string;
39
+ static decode(hex: string): Grai96Params;
40
+ }
41
+
42
+ /**
43
+ * OpenRFID Simulator - The Open Source RFID Reader Simulator for Developers.
44
+ * Copyright (c) 2026 RFID Software India Private Limited - https://rfidsoftwares.com
45
+ *
46
+ * Licensed under the MIT License.
47
+ * For RFID software, enterprise tools, and hardware drivers, visit https://rfidsoftwares.com
48
+ */
49
+ interface Giai96Params {
50
+ filter: number;
51
+ partition: number;
52
+ companyPrefix: string;
53
+ individualAssetReference: string;
54
+ }
55
+ declare class Giai96 {
56
+ static readonly HEADER = "00110100";
57
+ static encode(params: Giai96Params): string;
58
+ static decode(hex: string): Giai96Params;
59
+ }
60
+
61
+ export { Giai96, type Giai96Params, Grai96, type Grai96Params, Sgtin96, type Sgtin96Params };
package/dist/index.js ADDED
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Giai96: () => Giai96,
24
+ Grai96: () => Grai96,
25
+ Sgtin96: () => Sgtin96
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+
29
+ // src/sgtin96.ts
30
+ var import_epc = require("@openrfid/epc");
31
+ var Sgtin96 = class {
32
+ static HEADER = "00110000";
33
+ // 0x30 in binary (8 bits)
34
+ // Partition table bit allocations: [companyPrefixBits, companyPrefixDigits, itemRefBits, itemRefDigits]
35
+ static PARTITION_TABLE = {
36
+ 0: [40, 12, 4, 1],
37
+ 1: [37, 11, 7, 2],
38
+ 2: [34, 10, 10, 3],
39
+ 3: [30, 9, 14, 4],
40
+ 4: [27, 8, 17, 5],
41
+ 5: [24, 7, 20, 6],
42
+ 6: [20, 6, 24, 7]
43
+ };
44
+ static encode(params) {
45
+ const partitionInfo = this.PARTITION_TABLE[params.partition];
46
+ if (!partitionInfo) {
47
+ throw new Error(`Invalid SGTIN-96 partition value: ${params.partition}`);
48
+ }
49
+ const [companyBits, , itemBits] = partitionInfo;
50
+ const headerBin = this.HEADER;
51
+ const filterBin = params.filter.toString(2).padStart(3, "0");
52
+ const partitionBin = params.partition.toString(2).padStart(3, "0");
53
+ const companyBin = BigInt(params.companyPrefix).toString(2).padStart(companyBits, "0");
54
+ const itemBin = BigInt(params.itemRef).toString(2).padStart(itemBits, "0");
55
+ const serialBin = BigInt(params.serialNumber).toString(2).padStart(38, "0");
56
+ const binary96 = headerBin + filterBin + partitionBin + companyBin + itemBin + serialBin;
57
+ if (binary96.length !== 96) {
58
+ throw new Error(`Invalid total bit length for SGTIN-96: ${binary96.length} bits (expected 96)`);
59
+ }
60
+ return import_epc.EpcGen2.binaryToHex(binary96);
61
+ }
62
+ static decode(hex) {
63
+ const binary = import_epc.EpcGen2.hexToBinary(hex);
64
+ if (binary.length < 96) {
65
+ throw new Error("Hex string is too short for SGTIN-96");
66
+ }
67
+ const header = binary.substring(0, 8);
68
+ if (header !== this.HEADER) {
69
+ throw new Error(`Invalid SGTIN-96 header binary: ${header} (expected 0x30 / ${this.HEADER})`);
70
+ }
71
+ const filter = parseInt(binary.substring(8, 11), 2);
72
+ const partition = parseInt(binary.substring(11, 14), 2);
73
+ const partitionInfo = this.PARTITION_TABLE[partition];
74
+ if (!partitionInfo) {
75
+ throw new Error(`Invalid partition code in SGTIN-96 binary: ${partition}`);
76
+ }
77
+ const [companyBits, companyDigits, itemBits, itemDigits] = partitionInfo;
78
+ let offset = 14;
79
+ const companyPrefixBin = binary.substring(offset, offset + companyBits);
80
+ offset += companyBits;
81
+ const itemRefBin = binary.substring(offset, offset + itemBits);
82
+ offset += itemBits;
83
+ const serialBin = binary.substring(offset, offset + 38);
84
+ const companyPrefix = BigInt(`0b${companyPrefixBin}`).toString().padStart(companyDigits, "0");
85
+ const itemRef = BigInt(`0b${itemRefBin}`).toString().padStart(itemDigits, "0");
86
+ const serialNumber = BigInt(`0b${serialBin}`).toString();
87
+ return {
88
+ filter,
89
+ partition,
90
+ companyPrefix,
91
+ itemRef,
92
+ serialNumber
93
+ };
94
+ }
95
+ };
96
+
97
+ // src/grai96.ts
98
+ var import_epc2 = require("@openrfid/epc");
99
+ var Grai96 = class {
100
+ static HEADER = "00110011";
101
+ // 0x33 in binary (8 bits)
102
+ static encode(params) {
103
+ const headerBin = this.HEADER;
104
+ const filterBin = params.filter.toString(2).padStart(3, "0");
105
+ const partitionBin = params.partition.toString(2).padStart(3, "0");
106
+ const companyBin = BigInt(params.companyPrefix).toString(2).padStart(24, "0");
107
+ const assetBin = BigInt(params.assetType).toString(2).padStart(20, "0");
108
+ const serialBin = BigInt(params.serialNumber).toString(2).padStart(38, "0");
109
+ const binary96 = headerBin + filterBin + partitionBin + companyBin + assetBin + serialBin;
110
+ return import_epc2.EpcGen2.binaryToHex(binary96);
111
+ }
112
+ static decode(hex) {
113
+ const binary = import_epc2.EpcGen2.hexToBinary(hex);
114
+ const filter = parseInt(binary.substring(8, 11), 2);
115
+ const partition = parseInt(binary.substring(11, 14), 2);
116
+ const companyPrefix = BigInt(`0b${binary.substring(14, 38)}`).toString();
117
+ const assetType = BigInt(`0b${binary.substring(38, 58)}`).toString();
118
+ const serialNumber = BigInt(`0b${binary.substring(58, 96)}`).toString();
119
+ return { filter, partition, companyPrefix, assetType, serialNumber };
120
+ }
121
+ };
122
+
123
+ // src/giai96.ts
124
+ var import_epc3 = require("@openrfid/epc");
125
+ var Giai96 = class {
126
+ static HEADER = "00110100";
127
+ // 0x34 in binary (8 bits)
128
+ static encode(params) {
129
+ const headerBin = this.HEADER;
130
+ const filterBin = params.filter.toString(2).padStart(3, "0");
131
+ const partitionBin = params.partition.toString(2).padStart(3, "0");
132
+ const companyBin = BigInt(params.companyPrefix).toString(2).padStart(24, "0");
133
+ const assetRefBin = BigInt(params.individualAssetReference).toString(2).padStart(58, "0");
134
+ const binary96 = headerBin + filterBin + partitionBin + companyBin + assetRefBin;
135
+ return import_epc3.EpcGen2.binaryToHex(binary96);
136
+ }
137
+ static decode(hex) {
138
+ const binary = import_epc3.EpcGen2.hexToBinary(hex);
139
+ const filter = parseInt(binary.substring(8, 11), 2);
140
+ const partition = parseInt(binary.substring(11, 14), 2);
141
+ const companyPrefix = BigInt(`0b${binary.substring(14, 38)}`).toString();
142
+ const individualAssetReference = BigInt(`0b${binary.substring(38, 96)}`).toString();
143
+ return { filter, partition, companyPrefix, individualAssetReference };
144
+ }
145
+ };
146
+ // Annotate the CommonJS export names for ESM import in node:
147
+ 0 && (module.exports = {
148
+ Giai96,
149
+ Grai96,
150
+ Sgtin96
151
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,122 @@
1
+ // src/sgtin96.ts
2
+ import { EpcGen2 } from "@openrfid/epc";
3
+ var Sgtin96 = class {
4
+ static HEADER = "00110000";
5
+ // 0x30 in binary (8 bits)
6
+ // Partition table bit allocations: [companyPrefixBits, companyPrefixDigits, itemRefBits, itemRefDigits]
7
+ static PARTITION_TABLE = {
8
+ 0: [40, 12, 4, 1],
9
+ 1: [37, 11, 7, 2],
10
+ 2: [34, 10, 10, 3],
11
+ 3: [30, 9, 14, 4],
12
+ 4: [27, 8, 17, 5],
13
+ 5: [24, 7, 20, 6],
14
+ 6: [20, 6, 24, 7]
15
+ };
16
+ static encode(params) {
17
+ const partitionInfo = this.PARTITION_TABLE[params.partition];
18
+ if (!partitionInfo) {
19
+ throw new Error(`Invalid SGTIN-96 partition value: ${params.partition}`);
20
+ }
21
+ const [companyBits, , itemBits] = partitionInfo;
22
+ const headerBin = this.HEADER;
23
+ const filterBin = params.filter.toString(2).padStart(3, "0");
24
+ const partitionBin = params.partition.toString(2).padStart(3, "0");
25
+ const companyBin = BigInt(params.companyPrefix).toString(2).padStart(companyBits, "0");
26
+ const itemBin = BigInt(params.itemRef).toString(2).padStart(itemBits, "0");
27
+ const serialBin = BigInt(params.serialNumber).toString(2).padStart(38, "0");
28
+ const binary96 = headerBin + filterBin + partitionBin + companyBin + itemBin + serialBin;
29
+ if (binary96.length !== 96) {
30
+ throw new Error(`Invalid total bit length for SGTIN-96: ${binary96.length} bits (expected 96)`);
31
+ }
32
+ return EpcGen2.binaryToHex(binary96);
33
+ }
34
+ static decode(hex) {
35
+ const binary = EpcGen2.hexToBinary(hex);
36
+ if (binary.length < 96) {
37
+ throw new Error("Hex string is too short for SGTIN-96");
38
+ }
39
+ const header = binary.substring(0, 8);
40
+ if (header !== this.HEADER) {
41
+ throw new Error(`Invalid SGTIN-96 header binary: ${header} (expected 0x30 / ${this.HEADER})`);
42
+ }
43
+ const filter = parseInt(binary.substring(8, 11), 2);
44
+ const partition = parseInt(binary.substring(11, 14), 2);
45
+ const partitionInfo = this.PARTITION_TABLE[partition];
46
+ if (!partitionInfo) {
47
+ throw new Error(`Invalid partition code in SGTIN-96 binary: ${partition}`);
48
+ }
49
+ const [companyBits, companyDigits, itemBits, itemDigits] = partitionInfo;
50
+ let offset = 14;
51
+ const companyPrefixBin = binary.substring(offset, offset + companyBits);
52
+ offset += companyBits;
53
+ const itemRefBin = binary.substring(offset, offset + itemBits);
54
+ offset += itemBits;
55
+ const serialBin = binary.substring(offset, offset + 38);
56
+ const companyPrefix = BigInt(`0b${companyPrefixBin}`).toString().padStart(companyDigits, "0");
57
+ const itemRef = BigInt(`0b${itemRefBin}`).toString().padStart(itemDigits, "0");
58
+ const serialNumber = BigInt(`0b${serialBin}`).toString();
59
+ return {
60
+ filter,
61
+ partition,
62
+ companyPrefix,
63
+ itemRef,
64
+ serialNumber
65
+ };
66
+ }
67
+ };
68
+
69
+ // src/grai96.ts
70
+ import { EpcGen2 as EpcGen22 } from "@openrfid/epc";
71
+ var Grai96 = class {
72
+ static HEADER = "00110011";
73
+ // 0x33 in binary (8 bits)
74
+ static encode(params) {
75
+ const headerBin = this.HEADER;
76
+ const filterBin = params.filter.toString(2).padStart(3, "0");
77
+ const partitionBin = params.partition.toString(2).padStart(3, "0");
78
+ const companyBin = BigInt(params.companyPrefix).toString(2).padStart(24, "0");
79
+ const assetBin = BigInt(params.assetType).toString(2).padStart(20, "0");
80
+ const serialBin = BigInt(params.serialNumber).toString(2).padStart(38, "0");
81
+ const binary96 = headerBin + filterBin + partitionBin + companyBin + assetBin + serialBin;
82
+ return EpcGen22.binaryToHex(binary96);
83
+ }
84
+ static decode(hex) {
85
+ const binary = EpcGen22.hexToBinary(hex);
86
+ const filter = parseInt(binary.substring(8, 11), 2);
87
+ const partition = parseInt(binary.substring(11, 14), 2);
88
+ const companyPrefix = BigInt(`0b${binary.substring(14, 38)}`).toString();
89
+ const assetType = BigInt(`0b${binary.substring(38, 58)}`).toString();
90
+ const serialNumber = BigInt(`0b${binary.substring(58, 96)}`).toString();
91
+ return { filter, partition, companyPrefix, assetType, serialNumber };
92
+ }
93
+ };
94
+
95
+ // src/giai96.ts
96
+ import { EpcGen2 as EpcGen23 } from "@openrfid/epc";
97
+ var Giai96 = class {
98
+ static HEADER = "00110100";
99
+ // 0x34 in binary (8 bits)
100
+ static encode(params) {
101
+ const headerBin = this.HEADER;
102
+ const filterBin = params.filter.toString(2).padStart(3, "0");
103
+ const partitionBin = params.partition.toString(2).padStart(3, "0");
104
+ const companyBin = BigInt(params.companyPrefix).toString(2).padStart(24, "0");
105
+ const assetRefBin = BigInt(params.individualAssetReference).toString(2).padStart(58, "0");
106
+ const binary96 = headerBin + filterBin + partitionBin + companyBin + assetRefBin;
107
+ return EpcGen23.binaryToHex(binary96);
108
+ }
109
+ static decode(hex) {
110
+ const binary = EpcGen23.hexToBinary(hex);
111
+ const filter = parseInt(binary.substring(8, 11), 2);
112
+ const partition = parseInt(binary.substring(11, 14), 2);
113
+ const companyPrefix = BigInt(`0b${binary.substring(14, 38)}`).toString();
114
+ const individualAssetReference = BigInt(`0b${binary.substring(38, 96)}`).toString();
115
+ return { filter, partition, companyPrefix, individualAssetReference };
116
+ }
117
+ };
118
+ export {
119
+ Giai96,
120
+ Grai96,
121
+ Sgtin96
122
+ };
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@openrfid/gs1",
3
+ "version": "0.1.0",
4
+ "description": "GS1 Tag Data Standard encoding and decoding for SGTIN-96, GRAI-96, GIAI-96.",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "@openrfid/epc": "0.1.0"
20
+ },
21
+ "devDependencies": {
22
+ "tsup": "^8.0.2",
23
+ "typescript": "^5.4.5",
24
+ "vitest": "^1.5.0"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "license": "MIT",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/rfidsoftwares/openrfid-simulator.git"
33
+ },
34
+ "bugs": {
35
+ "url": "https://github.com/rfidsoftwares/openrfid-simulator/issues"
36
+ },
37
+ "homepage": "https://rfidsoftwares.com",
38
+ "scripts": {
39
+ "build": "tsup src/index.ts --format cjs,esm --dts",
40
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
41
+ "test": "vitest run",
42
+ "typecheck": "tsc --noEmit"
43
+ }
44
+ }