isahaq-barcode 1.8.0 → 2.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/index.js CHANGED
@@ -1,38 +1,65 @@
1
1
  /**
2
2
  * Isahaq Barcode Generator
3
- * A universal barcode generator package supporting multiple barcode types and output formats
3
+ * A universal barcode generator supporting 40+ symbologies and PNG/SVG/HTML/PDF output.
4
+ *
5
+ * Bundlers pick up ./browser.js through the "browser" field in package.json;
6
+ * the check below is a backstop for environments that load this file directly.
4
7
  */
5
8
 
6
- // Detect environment
7
9
  const isBrowser =
8
- typeof window !== 'undefined' && typeof document !== 'undefined';
10
+ typeof window !== 'undefined' &&
11
+ typeof document !== 'undefined' &&
12
+ typeof process === 'undefined';
9
13
 
10
14
  if (isBrowser) {
11
- // Browser environment - use browser-compatible version
12
15
  module.exports = require('./browser');
13
16
  } else {
14
- // Node.js environment - use full-featured version
15
17
  const BarcodeService = require('./src/services/BarcodeService');
16
18
  const QrCodeBuilder = require('./src/builders/QrCodeBuilder');
17
19
  const { BarcodeTypes } = require('./src/types/BarcodeTypes');
18
20
  const { RenderFormats } = require('./src/renderers/RenderFormats');
21
+ const { BarcodeEncoder } = require('./src/encoders/BarcodeEncoder');
22
+ const { Validator } = require('./src/validators/Validator');
23
+
24
+ const WATERMARK_POSITIONS = [
25
+ 'top-left',
26
+ 'top-center',
27
+ 'top-right',
28
+ 'left-center',
29
+ 'center',
30
+ 'right-center',
31
+ 'bottom-left',
32
+ 'bottom-center',
33
+ 'bottom-right',
34
+ ];
19
35
 
20
- // Main service instance
21
36
  const barcodeService = new BarcodeService();
22
37
 
23
38
  /**
24
39
  * Main Barcode Generator Class
25
40
  */
26
41
  class BarcodeGenerator {
42
+ /**
43
+ * Generate a barcode in any supported format
44
+ * @param {string} data - The data to encode
45
+ * @param {string} type - The barcode type
46
+ * @param {string} format - The output format (png, svg, html, pdf)
47
+ * @param {Object} options - Generation options
48
+ * @returns {Promise<Buffer|string>} Generated barcode
49
+ */
50
+ static generate(data, type = 'code128', format = 'png', options = {}) {
51
+ return barcodeService.generate(data, type, format, options);
52
+ }
53
+
27
54
  /**
28
55
  * Generate a barcode in PNG format
29
56
  * @param {string} data - The data to encode
30
57
  * @param {string} type - The barcode type
31
58
  * @param {Object} options - Generation options
32
- * @returns {Buffer} PNG buffer
59
+ * @returns {Promise<Buffer>} PNG buffer
33
60
  */
34
61
  static png(data, type = 'code128', options = {}) {
35
- return barcodeService.generate(data, type, 'png', options);
62
+ return barcodeService.png(data, type, options);
36
63
  }
37
64
 
38
65
  /**
@@ -40,21 +67,43 @@ if (isBrowser) {
40
67
  * @param {string} data - The data to encode
41
68
  * @param {string} type - The barcode type
42
69
  * @param {Object} options - Generation options
43
- * @returns {string} SVG string
70
+ * @returns {Promise<string>} SVG markup
44
71
  */
45
72
  static svg(data, type = 'code128', options = {}) {
46
- return barcodeService.generate(data, type, 'svg', options);
73
+ return barcodeService.svg(data, type, options);
74
+ }
75
+
76
+ /**
77
+ * Generate a barcode in SVG format synchronously
78
+ * @param {string} data - The data to encode
79
+ * @param {string} type - The barcode type
80
+ * @param {Object} options - Generation options
81
+ * @returns {string} SVG markup
82
+ */
83
+ static svgSync(data, type = 'code128', options = {}) {
84
+ return barcodeService.svgSync(data, type, options);
47
85
  }
48
86
 
49
87
  /**
50
- * Generate a barcode in HTML format
88
+ * Generate a barcode as an HTML fragment
51
89
  * @param {string} data - The data to encode
52
90
  * @param {string} type - The barcode type
53
91
  * @param {Object} options - Generation options
54
- * @returns {string} HTML string
92
+ * @returns {Promise<string>} HTML markup
55
93
  */
56
94
  static html(data, type = 'code128', options = {}) {
57
- return barcodeService.generate(data, type, 'html', options);
95
+ return barcodeService.html(data, type, options);
96
+ }
97
+
98
+ /**
99
+ * Generate a barcode as an HTML fragment synchronously
100
+ * @param {string} data - The data to encode
101
+ * @param {string} type - The barcode type
102
+ * @param {Object} options - Generation options
103
+ * @returns {string} HTML markup
104
+ */
105
+ static htmlSync(data, type = 'code128', options = {}) {
106
+ return barcodeService.htmlSync(data, type, options);
58
107
  }
59
108
 
60
109
  /**
@@ -64,12 +113,12 @@ if (isBrowser) {
64
113
  * @param {Object} options - Generation options
65
114
  * @returns {Promise<Buffer>} PDF buffer
66
115
  */
67
- static async pdf(data, type = 'code128', options = {}) {
68
- return barcodeService.generate(data, type, 'pdf', options);
116
+ static pdf(data, type = 'code128', options = {}) {
117
+ return barcodeService.pdf(data, type, options);
69
118
  }
70
119
 
71
120
  /**
72
- * Generate a QR code
121
+ * Create a QR code builder for logo, label and watermark support
73
122
  * @param {string} data - The data to encode
74
123
  * @param {Object} options - Generation options
75
124
  * @returns {QrCodeBuilder} QR code builder instance
@@ -78,6 +127,15 @@ if (isBrowser) {
78
127
  return new QrCodeBuilder({ data, ...options });
79
128
  }
80
129
 
130
+ /**
131
+ * Create a QR code builder from an options object
132
+ * @param {Object} options - QR code options
133
+ * @returns {QrCodeBuilder} QR code builder instance
134
+ */
135
+ static modernQr(options = {}) {
136
+ return new QrCodeBuilder(options);
137
+ }
138
+
81
139
  /**
82
140
  * Validate barcode data
83
141
  * @param {string} data - The data to validate
@@ -90,51 +148,58 @@ if (isBrowser) {
90
148
 
91
149
  /**
92
150
  * Generate multiple barcodes in batch
93
- * @param {Array} items - Array of barcode configurations
94
- * @returns {Promise<Array>} Array of generated barcodes
151
+ * @param {Array<Object>} items - Array of barcode configurations
152
+ * @returns {Promise<Array<Object>>} Array of results
95
153
  */
96
- static async batch(items) {
154
+ static batch(items) {
97
155
  return barcodeService.batch(items);
98
156
  }
99
157
 
100
158
  /**
101
159
  * Get supported barcode types
102
- * @returns {Array} Array of supported types
160
+ * @returns {string[]} Array of supported types
103
161
  */
104
162
  static getBarcodeTypes() {
105
- return BarcodeTypes.getTypes();
163
+ return BarcodeTypes.getAll();
164
+ }
165
+
166
+ /**
167
+ * Get supported barcode categories
168
+ * @returns {string[]} Array of category names
169
+ */
170
+ static getBarcodeCategories() {
171
+ return BarcodeTypes.getCategories();
172
+ }
173
+
174
+ /**
175
+ * Get supported barcode types in a category
176
+ * @param {string} category - The category name
177
+ * @returns {string[]} Array of types
178
+ */
179
+ static getBarcodeTypesByCategory(category) {
180
+ return BarcodeTypes.getByCategory(category);
106
181
  }
107
182
 
108
183
  /**
109
184
  * Get supported render formats
110
- * @returns {Array} Array of supported formats
185
+ * @returns {string[]} Array of supported formats
111
186
  */
112
187
  static getRenderFormats() {
113
- return RenderFormats.getFormats();
188
+ return RenderFormats.getAll();
114
189
  }
115
190
 
116
191
  /**
117
- * Get watermark positions
118
- * @returns {Array} Array of watermark positions
192
+ * Get watermark positions supported by the QR code builder
193
+ * @returns {string[]} Array of watermark positions
119
194
  */
120
195
  static getWatermarkPositions() {
121
- return [
122
- 'top-left',
123
- 'top-center',
124
- 'top-right',
125
- 'left-center',
126
- 'center',
127
- 'right-center',
128
- 'bottom-left',
129
- 'bottom-center',
130
- 'bottom-right',
131
- ];
196
+ return [...WATERMARK_POSITIONS];
132
197
  }
133
198
 
134
199
  /**
135
200
  * Get barcode type information
136
201
  * @param {string} type - The barcode type
137
- * @returns {Object} Type information
202
+ * @returns {Object|null} Type information
138
203
  */
139
204
  static getBarcodeTypeInfo(type) {
140
205
  return BarcodeTypes.getTypeInfo(type);
@@ -143,12 +208,27 @@ if (isBrowser) {
143
208
  /**
144
209
  * Get render format information
145
210
  * @param {string} format - The render format
146
- * @returns {Object} Format information
211
+ * @returns {Object|null} Format information
147
212
  */
148
213
  static getRenderFormatInfo(format) {
149
214
  return RenderFormats.getFormatInfo(format);
150
215
  }
216
+
217
+ /**
218
+ * Get the default render options
219
+ * @returns {Object} Default options
220
+ */
221
+ static getDefaultOptions() {
222
+ return BarcodeEncoder.getDefaultOptions();
223
+ }
151
224
  }
152
225
 
226
+ BarcodeGenerator.QrCodeBuilder = QrCodeBuilder;
227
+ BarcodeGenerator.BarcodeTypes = BarcodeTypes;
228
+ BarcodeGenerator.RenderFormats = RenderFormats;
229
+ BarcodeGenerator.BarcodeEncoder = BarcodeEncoder;
230
+ BarcodeGenerator.BarcodeService = BarcodeService;
231
+ BarcodeGenerator.Validator = Validator;
232
+
153
233
  module.exports = BarcodeGenerator;
154
234
  }
package/package.json CHANGED
@@ -1,88 +1,122 @@
1
1
  {
2
2
  "name": "isahaq-barcode",
3
- "version": "1.8.0",
4
- "description": "A universal barcode generator package supporting multiple barcode types and output formats, with extra features like batch generation, watermarking, validation, CLI, and Express.js integration",
3
+ "version": "2.0.0",
4
+ "description": "Universal barcode and QR code generator for Node.js and the browser: 40+ symbologies, PNG/SVG/HTML/PDF output, batch generation, logo and watermark support, validation, CLI and Express.js integration",
5
5
  "main": "index.js",
6
- "browser": {
7
- "fs": false,
8
- "path": false,
9
- "os": false,
10
- "canvas": false
6
+ "types": "index.d.ts",
7
+ "browser": "./browser.js",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./index.d.ts",
11
+ "browser": "./browser.js",
12
+ "require": "./index.js",
13
+ "default": "./index.js"
14
+ },
15
+ "./package.json": "./package.json"
11
16
  },
12
17
  "bin": {
13
18
  "barcode-generate": "./bin/generate.js"
14
19
  },
15
20
  "scripts": {
16
- "test": "npx jest",
17
- "test:watch": "npx jest --watch",
18
- "test:coverage": "npx jest --coverage",
19
- "lint": "npx eslint .",
20
- "lint:fix": "npx eslint . --fix",
21
- "format": "npx prettier --write .",
22
- "format:check": "npx prettier --check .",
23
- "build": "npm run lint && npm run format:check",
24
- "prepare": "husky install",
25
- "prepublishOnly": "npm run build",
21
+ "test": "jest",
22
+ "test:watch": "jest --watch",
23
+ "test:coverage": "jest --coverage",
24
+ "lint": "eslint .",
25
+ "lint:fix": "eslint . --fix",
26
+ "format": "prettier --write .",
27
+ "format:check": "prettier --check .",
28
+ "typecheck": "tsc --noEmit index.d.ts",
29
+ "verify:scan": "node scripts/verify-scannability.mjs",
30
+ "build": "npm run lint && npm run format:check && npm run typecheck && npm test",
31
+ "prepare": "husky",
32
+ "prepublishOnly": "npm run build && npm run verify:scan",
26
33
  "dev": "node examples/express-server.js",
27
34
  "start": "node examples/express-server.js"
28
35
  },
29
36
  "keywords": [
30
37
  "barcode",
38
+ "barcode-generator",
31
39
  "qrcode",
40
+ "qr-code",
32
41
  "generator",
33
42
  "code128",
34
43
  "code39",
44
+ "code93",
35
45
  "ean13",
46
+ "ean8",
36
47
  "upc",
48
+ "itf14",
37
49
  "datamatrix",
38
50
  "pdf417",
39
51
  "aztec",
52
+ "maxicode",
53
+ "postnet",
54
+ "codabar",
55
+ "pharmacode",
40
56
  "svg",
41
57
  "png",
42
58
  "pdf",
59
+ "html",
43
60
  "cli",
44
61
  "express",
45
- "node"
62
+ "node",
63
+ "browser"
46
64
  ],
47
- "author": "hmisahaq01@gmail.com",
65
+ "author": "Isahaq <hmisahaq01@gmail.com>",
48
66
  "license": "MIT",
49
67
  "dependencies": {
50
- "canvas": "^3.2.0",
51
- "chalk": "^5.6.2",
68
+ "bwip-js": "^4.11.2",
52
69
  "commander": "^14.0.1",
53
- "jsbarcode": "^3.12.1",
54
- "ora": "^9.0.0",
55
70
  "pdfkit": "^0.17.2",
56
71
  "qrcode": "^1.5.4"
57
72
  },
58
- "peerDependencies": {
59
- "jsbarcode": "^3.12.1",
60
- "qrcode": "^1.5.4"
73
+ "optionalDependencies": {
74
+ "canvas": "^3.2.0"
61
75
  },
62
76
  "devDependencies": {
63
77
  "@types/node": "^22.10.0",
64
78
  "eslint": "^9.38.0",
65
79
  "eslint-config-prettier": "^10.1.8",
66
- "eslint-config-standard": "^17.1.0",
67
- "eslint-plugin-import": "^2.32.0",
68
- "eslint-plugin-node": "^11.1.0",
69
80
  "eslint-plugin-prettier": "^5.5.4",
70
- "eslint-plugin-promise": "^7.2.1",
81
+ "express": "^5.2.1",
71
82
  "husky": "^9.1.7",
72
83
  "jest": "^30.2.0",
73
84
  "lint-staged": "^15.2.10",
74
85
  "prettier": "^3.4.0",
75
- "typescript": "^5.7.0"
86
+ "typescript": "^5.7.0",
87
+ "zxing-wasm": "^2.2.4"
88
+ },
89
+ "lint-staged": {
90
+ "*.js": [
91
+ "eslint --fix",
92
+ "prettier --write"
93
+ ],
94
+ "*.{json,md,yml}": [
95
+ "prettier --write"
96
+ ]
76
97
  },
77
98
  "engines": {
78
99
  "node": ">=18.0.0"
79
100
  },
80
101
  "repository": {
81
102
  "type": "git",
82
- "url": "https://github.com/isahaq1/barcode-generator-npm.git"
103
+ "url": "git+https://github.com/isahaq1/npm-barcodegenerator.git"
83
104
  },
84
105
  "bugs": {
85
- "url": "https://github.com/isahaq1/barcode-generator-npm/issues"
106
+ "url": "https://github.com/isahaq1/npm-barcodegenerator/issues"
107
+ },
108
+ "homepage": "https://github.com/isahaq1/npm-barcodegenerator#readme",
109
+ "publishConfig": {
110
+ "access": "public"
86
111
  },
87
- "homepage": "https://github.com/isahaq1/barcode-generator-npm#readme"
112
+ "files": [
113
+ "index.js",
114
+ "index.d.ts",
115
+ "browser.js",
116
+ "bin/",
117
+ "src/",
118
+ "README.md",
119
+ "CHANGELOG.md",
120
+ "LICENSE"
121
+ ]
88
122
  }