@openrfid/utils 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,40 @@
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
+ declare class RandomGenerator {
9
+ static uniform(min: number, max: number): number;
10
+ static integer(min: number, max: number): number;
11
+ static gaussian(mean?: number, stdDev?: number): number;
12
+ static boolean(probabilityTrue?: number): boolean;
13
+ }
14
+
15
+ /**
16
+ * OpenRFID Simulator - The Open Source RFID Reader Simulator for Developers.
17
+ * Copyright (c) 2026 RFID Software India Private Limited - https://rfidsoftwares.com
18
+ *
19
+ * Licensed under the MIT License.
20
+ * For RFID software, enterprise tools, and hardware drivers, visit https://rfidsoftwares.com
21
+ */
22
+ declare class DataFormatter {
23
+ static toCSV<T extends Record<string, any>>(data: T[]): string;
24
+ static parseCSV(csvContent: string): Record<string, string>[];
25
+ }
26
+
27
+ /**
28
+ * OpenRFID Simulator - The Open Source RFID Reader Simulator for Developers.
29
+ * Copyright (c) 2026 RFID Software India Private Limited - https://rfidsoftwares.com
30
+ *
31
+ * Licensed under the MIT License.
32
+ * For RFID software, enterprise tools, and hardware drivers, visit https://rfidsoftwares.com
33
+ */
34
+ declare class NetworkValidator {
35
+ static isValidIPv4(ip: string): boolean;
36
+ static isValidPort(port: number): boolean;
37
+ static isValidMacAddress(mac: string): boolean;
38
+ }
39
+
40
+ export { DataFormatter, NetworkValidator, RandomGenerator };
@@ -0,0 +1,40 @@
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
+ declare class RandomGenerator {
9
+ static uniform(min: number, max: number): number;
10
+ static integer(min: number, max: number): number;
11
+ static gaussian(mean?: number, stdDev?: number): number;
12
+ static boolean(probabilityTrue?: number): boolean;
13
+ }
14
+
15
+ /**
16
+ * OpenRFID Simulator - The Open Source RFID Reader Simulator for Developers.
17
+ * Copyright (c) 2026 RFID Software India Private Limited - https://rfidsoftwares.com
18
+ *
19
+ * Licensed under the MIT License.
20
+ * For RFID software, enterprise tools, and hardware drivers, visit https://rfidsoftwares.com
21
+ */
22
+ declare class DataFormatter {
23
+ static toCSV<T extends Record<string, any>>(data: T[]): string;
24
+ static parseCSV(csvContent: string): Record<string, string>[];
25
+ }
26
+
27
+ /**
28
+ * OpenRFID Simulator - The Open Source RFID Reader Simulator for Developers.
29
+ * Copyright (c) 2026 RFID Software India Private Limited - https://rfidsoftwares.com
30
+ *
31
+ * Licensed under the MIT License.
32
+ * For RFID software, enterprise tools, and hardware drivers, visit https://rfidsoftwares.com
33
+ */
34
+ declare class NetworkValidator {
35
+ static isValidIPv4(ip: string): boolean;
36
+ static isValidPort(port: number): boolean;
37
+ static isValidMacAddress(mac: string): boolean;
38
+ }
39
+
40
+ export { DataFormatter, NetworkValidator, RandomGenerator };
package/dist/index.js ADDED
@@ -0,0 +1,103 @@
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
+ DataFormatter: () => DataFormatter,
24
+ NetworkValidator: () => NetworkValidator,
25
+ RandomGenerator: () => RandomGenerator
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+
29
+ // src/random.ts
30
+ var RandomGenerator = class {
31
+ static uniform(min, max) {
32
+ return min + Math.random() * (max - min);
33
+ }
34
+ static integer(min, max) {
35
+ return Math.floor(this.uniform(min, max + 1));
36
+ }
37
+ // Box-Muller transform for Gaussian / Normal distribution
38
+ static gaussian(mean = 0, stdDev = 1) {
39
+ let u = 0, v = 0;
40
+ while (u === 0) u = Math.random();
41
+ while (v === 0) v = Math.random();
42
+ const num = Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
43
+ return num * stdDev + mean;
44
+ }
45
+ static boolean(probabilityTrue = 0.5) {
46
+ return Math.random() < probabilityTrue;
47
+ }
48
+ };
49
+
50
+ // src/formatters.ts
51
+ var DataFormatter = class {
52
+ static toCSV(data) {
53
+ if (data.length === 0) return "";
54
+ const headers = Object.keys(data[0]);
55
+ const csvRows = [headers.join(",")];
56
+ for (const row of data) {
57
+ const values = headers.map((header) => {
58
+ const val = row[header];
59
+ const escaped = ("" + (val ?? "")).replace(/"/g, '""');
60
+ return `"${escaped}"`;
61
+ });
62
+ csvRows.push(values.join(","));
63
+ }
64
+ return csvRows.join("\n");
65
+ }
66
+ static parseCSV(csvContent) {
67
+ const lines = csvContent.trim().split(/\r?\n/);
68
+ if (lines.length === 0) return [];
69
+ const headers = lines[0].split(",").map((h) => h.trim().replace(/^"|"$/g, ""));
70
+ const results = [];
71
+ for (let i = 1; i < lines.length; i++) {
72
+ if (!lines[i].trim()) continue;
73
+ const values = lines[i].split(",").map((v) => v.trim().replace(/^"|"$/g, ""));
74
+ const obj = {};
75
+ headers.forEach((header, index) => {
76
+ obj[header] = values[index] ?? "";
77
+ });
78
+ results.push(obj);
79
+ }
80
+ return results;
81
+ }
82
+ };
83
+
84
+ // src/network.ts
85
+ var NetworkValidator = class {
86
+ static isValidIPv4(ip) {
87
+ const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
88
+ return ipv4Regex.test(ip);
89
+ }
90
+ static isValidPort(port) {
91
+ return Number.isInteger(port) && port >= 1 && port <= 65535;
92
+ }
93
+ static isValidMacAddress(mac) {
94
+ const macRegex = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/;
95
+ return macRegex.test(mac);
96
+ }
97
+ };
98
+ // Annotate the CommonJS export names for ESM import in node:
99
+ 0 && (module.exports = {
100
+ DataFormatter,
101
+ NetworkValidator,
102
+ RandomGenerator
103
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,74 @@
1
+ // src/random.ts
2
+ var RandomGenerator = class {
3
+ static uniform(min, max) {
4
+ return min + Math.random() * (max - min);
5
+ }
6
+ static integer(min, max) {
7
+ return Math.floor(this.uniform(min, max + 1));
8
+ }
9
+ // Box-Muller transform for Gaussian / Normal distribution
10
+ static gaussian(mean = 0, stdDev = 1) {
11
+ let u = 0, v = 0;
12
+ while (u === 0) u = Math.random();
13
+ while (v === 0) v = Math.random();
14
+ const num = Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
15
+ return num * stdDev + mean;
16
+ }
17
+ static boolean(probabilityTrue = 0.5) {
18
+ return Math.random() < probabilityTrue;
19
+ }
20
+ };
21
+
22
+ // src/formatters.ts
23
+ var DataFormatter = class {
24
+ static toCSV(data) {
25
+ if (data.length === 0) return "";
26
+ const headers = Object.keys(data[0]);
27
+ const csvRows = [headers.join(",")];
28
+ for (const row of data) {
29
+ const values = headers.map((header) => {
30
+ const val = row[header];
31
+ const escaped = ("" + (val ?? "")).replace(/"/g, '""');
32
+ return `"${escaped}"`;
33
+ });
34
+ csvRows.push(values.join(","));
35
+ }
36
+ return csvRows.join("\n");
37
+ }
38
+ static parseCSV(csvContent) {
39
+ const lines = csvContent.trim().split(/\r?\n/);
40
+ if (lines.length === 0) return [];
41
+ const headers = lines[0].split(",").map((h) => h.trim().replace(/^"|"$/g, ""));
42
+ const results = [];
43
+ for (let i = 1; i < lines.length; i++) {
44
+ if (!lines[i].trim()) continue;
45
+ const values = lines[i].split(",").map((v) => v.trim().replace(/^"|"$/g, ""));
46
+ const obj = {};
47
+ headers.forEach((header, index) => {
48
+ obj[header] = values[index] ?? "";
49
+ });
50
+ results.push(obj);
51
+ }
52
+ return results;
53
+ }
54
+ };
55
+
56
+ // src/network.ts
57
+ var NetworkValidator = class {
58
+ static isValidIPv4(ip) {
59
+ const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
60
+ return ipv4Regex.test(ip);
61
+ }
62
+ static isValidPort(port) {
63
+ return Number.isInteger(port) && port >= 1 && port <= 65535;
64
+ }
65
+ static isValidMacAddress(mac) {
66
+ const macRegex = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/;
67
+ return macRegex.test(mac);
68
+ }
69
+ };
70
+ export {
71
+ DataFormatter,
72
+ NetworkValidator,
73
+ RandomGenerator
74
+ };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@openrfid/utils",
3
+ "version": "0.1.0",
4
+ "description": "Shared simulation utilities, random distribution generators, data format parsers, and network validators.",
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
+ "devDependencies": {
19
+ "tsup": "^8.0.2",
20
+ "typescript": "^5.4.5",
21
+ "vitest": "^1.5.0"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "license": "MIT",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/rfidsoftwares/openrfid-simulator.git"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/rfidsoftwares/openrfid-simulator/issues"
33
+ },
34
+ "homepage": "https://rfidsoftwares.com",
35
+ "scripts": {
36
+ "build": "tsup src/index.ts --format cjs,esm --dts",
37
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
38
+ "test": "vitest run",
39
+ "typecheck": "tsc --noEmit"
40
+ }
41
+ }