isahaq-barcode 1.6.0 → 1.8.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/README.md +31 -17
- package/browser.js +228 -0
- package/eslint.config.js +1 -0
- package/examples/basic-usage.js +1 -1
- package/examples/express-server.js +1 -1
- package/index.js +134 -114
- package/package.json +7 -2
- package/src/builders/QrCodeBuilder.js +1 -1
package/README.md
CHANGED
|
@@ -39,20 +39,28 @@
|
|
|
39
39
|
## 📦 Installation
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
|
-
npm install
|
|
42
|
+
npm install isahaq-barcode
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
**Requirements:** Node.js 18.0 or higher
|
|
46
46
|
|
|
47
|
-
## 🌐
|
|
47
|
+
## 🌐 Universal Compatibility
|
|
48
48
|
|
|
49
|
-
> **
|
|
49
|
+
> **Great News:** This package now works in **both Node.js and browser environments**!
|
|
50
50
|
|
|
51
|
-
###
|
|
51
|
+
### ✅ Server-Side (Node.js)
|
|
52
52
|
|
|
53
|
-
- **
|
|
54
|
-
- **
|
|
55
|
-
- **
|
|
53
|
+
- **Full Features**: All barcode types, formats, and advanced features
|
|
54
|
+
- **Canvas Support**: High-quality image generation with Node.js canvas
|
|
55
|
+
- **File Operations**: Save files directly to filesystem
|
|
56
|
+
- **CLI Tools**: Command-line interface available
|
|
57
|
+
|
|
58
|
+
### ✅ Client-Side (Browser)
|
|
59
|
+
|
|
60
|
+
- **Core Features**: PNG, SVG, HTML generation
|
|
61
|
+
- **QR Codes**: Full QR code generation with customization
|
|
62
|
+
- **Barcode Types**: Code128, Code39, EAN13, UPC, and more
|
|
63
|
+
- **No Dependencies**: Works with just jsbarcode and qrcode
|
|
56
64
|
|
|
57
65
|
### Recommended Usage Patterns
|
|
58
66
|
|
|
@@ -60,7 +68,7 @@ npm install @isahaq/barcode
|
|
|
60
68
|
|
|
61
69
|
```javascript
|
|
62
70
|
// Node.js/Express.js server
|
|
63
|
-
const BarcodeGenerator = require('
|
|
71
|
+
const BarcodeGenerator = require('isahaq-barcode');
|
|
64
72
|
|
|
65
73
|
// Generate barcode on server
|
|
66
74
|
app.get('/barcode/:data', (req, res) => {
|
|
@@ -74,7 +82,7 @@ app.get('/barcode/:data', (req, res) => {
|
|
|
74
82
|
|
|
75
83
|
```javascript
|
|
76
84
|
// pages/api/barcode.js or app/api/barcode/route.js
|
|
77
|
-
import BarcodeGenerator from '
|
|
85
|
+
import BarcodeGenerator from 'isahaq-barcode';
|
|
78
86
|
|
|
79
87
|
export default function handler(req, res) {
|
|
80
88
|
const barcode = BarcodeGenerator.png(req.query.data, 'code128');
|
|
@@ -83,11 +91,17 @@ export default function handler(req, res) {
|
|
|
83
91
|
}
|
|
84
92
|
```
|
|
85
93
|
|
|
86
|
-
|
|
94
|
+
**✅ Client-Side (Browser/React/Vue):**
|
|
87
95
|
|
|
88
96
|
```javascript
|
|
89
|
-
//
|
|
90
|
-
import BarcodeGenerator from '
|
|
97
|
+
// Browser/React/Vue components
|
|
98
|
+
import BarcodeGenerator from 'isahaq-barcode';
|
|
99
|
+
|
|
100
|
+
// Generate barcode in browser
|
|
101
|
+
const generateBarcode = async () => {
|
|
102
|
+
const barcode = await BarcodeGenerator.png('123456789', 'code128');
|
|
103
|
+
// Use the barcode buffer
|
|
104
|
+
};
|
|
91
105
|
```
|
|
92
106
|
|
|
93
107
|
### Alternative for Client-Side
|
|
@@ -101,7 +115,7 @@ For browser-based barcode generation, consider:
|
|
|
101
115
|
**Global CLI Installation:**
|
|
102
116
|
|
|
103
117
|
```bash
|
|
104
|
-
npm install -g
|
|
118
|
+
npm install -g isahaq-barcode
|
|
105
119
|
```
|
|
106
120
|
|
|
107
121
|
---
|
|
@@ -109,7 +123,7 @@ npm install -g @isahaq/barcode
|
|
|
109
123
|
## 🚀 Quick Start
|
|
110
124
|
|
|
111
125
|
```javascript
|
|
112
|
-
const BarcodeGenerator = require('
|
|
126
|
+
const BarcodeGenerator = require('isahaq-barcode');
|
|
113
127
|
|
|
114
128
|
// Generate PNG barcode
|
|
115
129
|
const pngBuffer = BarcodeGenerator.png('1234567890', 'code128');
|
|
@@ -173,7 +187,7 @@ await qrCode.saveToFile('qr-code.png');
|
|
|
173
187
|
### Basic Generation
|
|
174
188
|
|
|
175
189
|
```javascript
|
|
176
|
-
const BarcodeGenerator = require('
|
|
190
|
+
const BarcodeGenerator = require('isahaq-barcode');
|
|
177
191
|
|
|
178
192
|
// PNG with custom options
|
|
179
193
|
const barcode = BarcodeGenerator.png('1234567890', 'code128', {
|
|
@@ -286,7 +300,7 @@ if (validation.valid) {
|
|
|
286
300
|
|
|
287
301
|
```javascript
|
|
288
302
|
const express = require('express');
|
|
289
|
-
const BarcodeGenerator = require('
|
|
303
|
+
const BarcodeGenerator = require('isahaq-barcode');
|
|
290
304
|
|
|
291
305
|
const app = express();
|
|
292
306
|
|
|
@@ -352,7 +366,7 @@ app.listen(3000, () => {
|
|
|
352
366
|
|
|
353
367
|
```javascript
|
|
354
368
|
const express = require('express');
|
|
355
|
-
const BarcodeGenerator = require('
|
|
369
|
+
const BarcodeGenerator = require('isahaq-barcode');
|
|
356
370
|
|
|
357
371
|
const app = express();
|
|
358
372
|
|
package/browser.js
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-compatible version of Isahaq Barcode Generator
|
|
3
|
+
* This version uses client-side libraries instead of Node.js modules
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Browser-compatible QR code generation
|
|
7
|
+
const QRCode = require('qrcode');
|
|
8
|
+
|
|
9
|
+
// Browser-compatible barcode generation using jsbarcode
|
|
10
|
+
const JsBarcode = require('jsbarcode');
|
|
11
|
+
|
|
12
|
+
class BrowserBarcodeGenerator {
|
|
13
|
+
/**
|
|
14
|
+
* Generate PNG barcode (browser-compatible)
|
|
15
|
+
* @param {string} data - Data to encode
|
|
16
|
+
* @param {string} type - Barcode type
|
|
17
|
+
* @param {Object} options - Options
|
|
18
|
+
* @returns {Promise<Buffer>} PNG buffer
|
|
19
|
+
*/
|
|
20
|
+
static async png(data, type = 'code128', options = {}) {
|
|
21
|
+
try {
|
|
22
|
+
// Create a canvas element
|
|
23
|
+
const canvas = document.createElement('canvas');
|
|
24
|
+
|
|
25
|
+
// Generate barcode using jsbarcode
|
|
26
|
+
JsBarcode(canvas, data, {
|
|
27
|
+
format: type.toUpperCase(),
|
|
28
|
+
width: options.width || 2,
|
|
29
|
+
height: options.height || 100,
|
|
30
|
+
displayValue: options.displayValue !== false,
|
|
31
|
+
fontSize: options.fontSize || 20,
|
|
32
|
+
textAlign: options.textAlign || 'center',
|
|
33
|
+
textPosition: options.textPosition || 'bottom',
|
|
34
|
+
textMargin: options.textMargin || 2,
|
|
35
|
+
background: options.background || '#ffffff',
|
|
36
|
+
lineColor: options.lineColor || '#000000',
|
|
37
|
+
margin: options.margin || 10,
|
|
38
|
+
...options,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Convert canvas to blob
|
|
42
|
+
return new Promise(resolve => {
|
|
43
|
+
canvas.toBlob(blob => {
|
|
44
|
+
const reader = new FileReader();
|
|
45
|
+
reader.onload = () => resolve(Buffer.from(reader.result));
|
|
46
|
+
reader.readAsArrayBuffer(blob);
|
|
47
|
+
}, 'image/png');
|
|
48
|
+
});
|
|
49
|
+
} catch (error) {
|
|
50
|
+
throw new Error(`Failed to generate PNG barcode: ${error.message}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Generate SVG barcode (browser-compatible)
|
|
56
|
+
* @param {string} data - Data to encode
|
|
57
|
+
* @param {string} type - Barcode type
|
|
58
|
+
* @param {Object} options - Options
|
|
59
|
+
* @returns {string} SVG string
|
|
60
|
+
*/
|
|
61
|
+
static svg(data, type = 'code128', options = {}) {
|
|
62
|
+
try {
|
|
63
|
+
// Create a temporary div to hold the SVG
|
|
64
|
+
const tempDiv = document.createElement('div');
|
|
65
|
+
|
|
66
|
+
// Generate barcode using jsbarcode
|
|
67
|
+
JsBarcode(tempDiv, data, {
|
|
68
|
+
format: type.toUpperCase(),
|
|
69
|
+
width: options.width || 2,
|
|
70
|
+
height: options.height || 100,
|
|
71
|
+
displayValue: options.displayValue !== false,
|
|
72
|
+
fontSize: options.fontSize || 20,
|
|
73
|
+
textAlign: options.textAlign || 'center',
|
|
74
|
+
textPosition: options.textPosition || 'bottom',
|
|
75
|
+
textMargin: options.textMargin || 2,
|
|
76
|
+
background: options.background || '#ffffff',
|
|
77
|
+
lineColor: options.lineColor || '#000000',
|
|
78
|
+
margin: options.margin || 10,
|
|
79
|
+
xmlDocument: document,
|
|
80
|
+
...options,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return tempDiv.innerHTML;
|
|
84
|
+
} catch (error) {
|
|
85
|
+
throw new Error(`Failed to generate SVG barcode: ${error.message}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Generate HTML barcode (browser-compatible)
|
|
91
|
+
* @param {string} data - Data to encode
|
|
92
|
+
* @param {string} type - Barcode type
|
|
93
|
+
* @param {Object} options - Options
|
|
94
|
+
* @returns {string} HTML string
|
|
95
|
+
*/
|
|
96
|
+
static html(data, type = 'code128', options = {}) {
|
|
97
|
+
const svg = this.svg(data, type, options);
|
|
98
|
+
return `<div class="barcode-container">${svg}</div>`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Generate QR code (browser-compatible)
|
|
103
|
+
* @param {string} data - Data to encode
|
|
104
|
+
* @param {Object} options - Options
|
|
105
|
+
* @returns {Promise<Buffer>} PNG buffer
|
|
106
|
+
*/
|
|
107
|
+
static async qrCode(data, options = {}) {
|
|
108
|
+
try {
|
|
109
|
+
const canvas = document.createElement('canvas');
|
|
110
|
+
await QRCode.toCanvas(canvas, data, {
|
|
111
|
+
width: options.size || 300,
|
|
112
|
+
margin: options.margin || 10,
|
|
113
|
+
color: {
|
|
114
|
+
dark: options.foregroundColor || '#000000',
|
|
115
|
+
light: options.backgroundColor || '#FFFFFF',
|
|
116
|
+
},
|
|
117
|
+
errorCorrectionLevel: options.errorCorrectionLevel || 'M',
|
|
118
|
+
...options,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
return new Promise(resolve => {
|
|
122
|
+
canvas.toBlob(blob => {
|
|
123
|
+
const reader = new FileReader();
|
|
124
|
+
reader.onload = () => resolve(Buffer.from(reader.result));
|
|
125
|
+
reader.readAsArrayBuffer(blob);
|
|
126
|
+
}, 'image/png');
|
|
127
|
+
});
|
|
128
|
+
} catch (error) {
|
|
129
|
+
throw new Error(`Failed to generate QR code: ${error.message}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Validate barcode data (browser-compatible)
|
|
135
|
+
* @param {string} data - Data to validate
|
|
136
|
+
* @param {string} type - Barcode type
|
|
137
|
+
* @returns {Object} Validation result
|
|
138
|
+
*/
|
|
139
|
+
static validate(data, type) {
|
|
140
|
+
if (!data || typeof data !== 'string') {
|
|
141
|
+
return {
|
|
142
|
+
valid: false,
|
|
143
|
+
error: 'Data must be a non-empty string',
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Basic validation for common barcode types
|
|
148
|
+
switch (type.toLowerCase()) {
|
|
149
|
+
case 'code128':
|
|
150
|
+
if (!/^[\x00-\x7F]+$/.test(data)) {
|
|
151
|
+
return {
|
|
152
|
+
valid: false,
|
|
153
|
+
error: 'Code 128 supports ASCII characters only',
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
break;
|
|
157
|
+
case 'code39':
|
|
158
|
+
if (!/^[A-Z0-9\s\-\.\$\/\+\%]+$/.test(data)) {
|
|
159
|
+
return {
|
|
160
|
+
valid: false,
|
|
161
|
+
error: 'Code 39 supports characters: A-Z, 0-9, space, -.$/+%',
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
165
|
+
case 'ean13':
|
|
166
|
+
if (!/^\d{12,13}$/.test(data)) {
|
|
167
|
+
return {
|
|
168
|
+
valid: false,
|
|
169
|
+
error: 'EAN-13 must be 12 or 13 digits',
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
case 'qrcode':
|
|
174
|
+
if (data.length === 0) {
|
|
175
|
+
return {
|
|
176
|
+
valid: false,
|
|
177
|
+
error: 'QR Code data cannot be empty',
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return { valid: true };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Get supported barcode types
|
|
188
|
+
* @returns {Array} Array of supported types
|
|
189
|
+
*/
|
|
190
|
+
static getBarcodeTypes() {
|
|
191
|
+
return [
|
|
192
|
+
'code128',
|
|
193
|
+
'code128a',
|
|
194
|
+
'code128b',
|
|
195
|
+
'code128c',
|
|
196
|
+
'code128auto',
|
|
197
|
+
'code39',
|
|
198
|
+
'code39extended',
|
|
199
|
+
'code39checksum',
|
|
200
|
+
'code39auto',
|
|
201
|
+
'code93',
|
|
202
|
+
'ean13',
|
|
203
|
+
'ean8',
|
|
204
|
+
'upca',
|
|
205
|
+
'upce',
|
|
206
|
+
'codabar',
|
|
207
|
+
'code11',
|
|
208
|
+
'msi',
|
|
209
|
+
'pharmazentral',
|
|
210
|
+
'interleaved25',
|
|
211
|
+
'standard25',
|
|
212
|
+
'qrcode',
|
|
213
|
+
'datamatrix',
|
|
214
|
+
'pdf417',
|
|
215
|
+
'aztec',
|
|
216
|
+
];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Get supported render formats
|
|
221
|
+
* @returns {Array} Array of supported formats
|
|
222
|
+
*/
|
|
223
|
+
static getRenderFormats() {
|
|
224
|
+
return ['png', 'svg', 'html'];
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
module.exports = BrowserBarcodeGenerator;
|
package/eslint.config.js
CHANGED
package/examples/basic-usage.js
CHANGED
package/index.js
CHANGED
|
@@ -3,132 +3,152 @@
|
|
|
3
3
|
* A universal barcode generator package supporting multiple barcode types and output formats
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const { RenderFormats } = require('./src/renderers/RenderFormats');
|
|
6
|
+
// Detect environment
|
|
7
|
+
const isBrowser =
|
|
8
|
+
typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
if (isBrowser) {
|
|
11
|
+
// Browser environment - use browser-compatible version
|
|
12
|
+
module.exports = require('./browser');
|
|
13
|
+
} else {
|
|
14
|
+
// Node.js environment - use full-featured version
|
|
15
|
+
const BarcodeService = require('./src/services/BarcodeService');
|
|
16
|
+
const QrCodeBuilder = require('./src/builders/QrCodeBuilder');
|
|
17
|
+
const { BarcodeTypes } = require('./src/types/BarcodeTypes');
|
|
18
|
+
const { RenderFormats } = require('./src/renderers/RenderFormats');
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*/
|
|
17
|
-
class BarcodeGenerator {
|
|
18
|
-
/**
|
|
19
|
-
* Generate a barcode in PNG format
|
|
20
|
-
* @param {string} data - The data to encode
|
|
21
|
-
* @param {string} type - The barcode type
|
|
22
|
-
* @param {Object} options - Additional options
|
|
23
|
-
* @returns {Buffer} PNG buffer
|
|
24
|
-
*/
|
|
25
|
-
static png(data, type = 'code128', options = {}) {
|
|
26
|
-
return barcodeService.generate(data, type, 'png', options);
|
|
27
|
-
}
|
|
20
|
+
// Main service instance
|
|
21
|
+
const barcodeService = new BarcodeService();
|
|
28
22
|
|
|
29
23
|
/**
|
|
30
|
-
*
|
|
31
|
-
* @param {string} data - The data to encode
|
|
32
|
-
* @param {string} type - The barcode type
|
|
33
|
-
* @param {Object} options - Additional options
|
|
34
|
-
* @returns {string} SVG string
|
|
24
|
+
* Main Barcode Generator Class
|
|
35
25
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
class BarcodeGenerator {
|
|
27
|
+
/**
|
|
28
|
+
* Generate a barcode in PNG format
|
|
29
|
+
* @param {string} data - The data to encode
|
|
30
|
+
* @param {string} type - The barcode type
|
|
31
|
+
* @param {Object} options - Generation options
|
|
32
|
+
* @returns {Buffer} PNG buffer
|
|
33
|
+
*/
|
|
34
|
+
static png(data, type = 'code128', options = {}) {
|
|
35
|
+
return barcodeService.generate(data, type, 'png', options);
|
|
36
|
+
}
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Generate a barcode in SVG format
|
|
40
|
+
* @param {string} data - The data to encode
|
|
41
|
+
* @param {string} type - The barcode type
|
|
42
|
+
* @param {Object} options - Generation options
|
|
43
|
+
* @returns {string} SVG string
|
|
44
|
+
*/
|
|
45
|
+
static svg(data, type = 'code128', options = {}) {
|
|
46
|
+
return barcodeService.generate(data, type, 'svg', options);
|
|
47
|
+
}
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Generate a barcode in HTML format
|
|
51
|
+
* @param {string} data - The data to encode
|
|
52
|
+
* @param {string} type - The barcode type
|
|
53
|
+
* @param {Object} options - Generation options
|
|
54
|
+
* @returns {string} HTML string
|
|
55
|
+
*/
|
|
56
|
+
static html(data, type = 'code128', options = {}) {
|
|
57
|
+
return barcodeService.generate(data, type, 'html', options);
|
|
58
|
+
}
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Generate a barcode in PDF format
|
|
62
|
+
* @param {string} data - The data to encode
|
|
63
|
+
* @param {string} type - The barcode type
|
|
64
|
+
* @param {Object} options - Generation options
|
|
65
|
+
* @returns {Promise<Buffer>} PDF buffer
|
|
66
|
+
*/
|
|
67
|
+
static async pdf(data, type = 'code128', options = {}) {
|
|
68
|
+
return barcodeService.generate(data, type, 'pdf', options);
|
|
69
|
+
}
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Generate a QR code
|
|
73
|
+
* @param {string} data - The data to encode
|
|
74
|
+
* @param {Object} options - Generation options
|
|
75
|
+
* @returns {QrCodeBuilder} QR code builder instance
|
|
76
|
+
*/
|
|
77
|
+
static qrCode(data, options = {}) {
|
|
78
|
+
return new QrCodeBuilder({ data, ...options });
|
|
79
|
+
}
|
|
78
80
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Validate barcode data
|
|
83
|
+
* @param {string} data - The data to validate
|
|
84
|
+
* @param {string} type - The barcode type
|
|
85
|
+
* @returns {Object} Validation result
|
|
86
|
+
*/
|
|
87
|
+
static validate(data, type) {
|
|
88
|
+
return barcodeService.validate(data, type);
|
|
89
|
+
}
|
|
86
90
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
91
|
+
/**
|
|
92
|
+
* Generate multiple barcodes in batch
|
|
93
|
+
* @param {Array} items - Array of barcode configurations
|
|
94
|
+
* @returns {Promise<Array>} Array of generated barcodes
|
|
95
|
+
*/
|
|
96
|
+
static async batch(items) {
|
|
97
|
+
return barcodeService.batch(items);
|
|
98
|
+
}
|
|
96
99
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
100
|
+
/**
|
|
101
|
+
* Get supported barcode types
|
|
102
|
+
* @returns {Array} Array of supported types
|
|
103
|
+
*/
|
|
104
|
+
static getBarcodeTypes() {
|
|
105
|
+
return BarcodeTypes.getTypes();
|
|
106
|
+
}
|
|
105
107
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
'top-right',
|
|
114
|
-
'bottom-left',
|
|
115
|
-
'bottom-right',
|
|
116
|
-
'center',
|
|
117
|
-
'top-center',
|
|
118
|
-
'bottom-center',
|
|
119
|
-
'left-center',
|
|
120
|
-
'right-center',
|
|
121
|
-
];
|
|
122
|
-
}
|
|
123
|
-
}
|
|
108
|
+
/**
|
|
109
|
+
* Get supported render formats
|
|
110
|
+
* @returns {Array} Array of supported formats
|
|
111
|
+
*/
|
|
112
|
+
static getRenderFormats() {
|
|
113
|
+
return RenderFormats.getFormats();
|
|
114
|
+
}
|
|
124
115
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Get watermark positions
|
|
118
|
+
* @returns {Array} Array of watermark positions
|
|
119
|
+
*/
|
|
120
|
+
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
|
+
];
|
|
132
|
+
}
|
|
132
133
|
|
|
133
|
-
|
|
134
|
-
|
|
134
|
+
/**
|
|
135
|
+
* Get barcode type information
|
|
136
|
+
* @param {string} type - The barcode type
|
|
137
|
+
* @returns {Object} Type information
|
|
138
|
+
*/
|
|
139
|
+
static getBarcodeTypeInfo(type) {
|
|
140
|
+
return BarcodeTypes.getTypeInfo(type);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Get render format information
|
|
145
|
+
* @param {string} format - The render format
|
|
146
|
+
* @returns {Object} Format information
|
|
147
|
+
*/
|
|
148
|
+
static getRenderFormatInfo(format) {
|
|
149
|
+
return RenderFormats.getFormatInfo(format);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
module.exports = BarcodeGenerator;
|
|
154
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isahaq-barcode",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
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",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"browser": {
|
|
7
7
|
"fs": false,
|
|
8
8
|
"path": false,
|
|
9
|
-
"os": false
|
|
9
|
+
"os": false,
|
|
10
|
+
"canvas": false
|
|
10
11
|
},
|
|
11
12
|
"bin": {
|
|
12
13
|
"barcode-generate": "./bin/generate.js"
|
|
@@ -54,6 +55,10 @@
|
|
|
54
55
|
"pdfkit": "^0.17.2",
|
|
55
56
|
"qrcode": "^1.5.4"
|
|
56
57
|
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"jsbarcode": "^3.12.1",
|
|
60
|
+
"qrcode": "^1.5.4"
|
|
61
|
+
},
|
|
57
62
|
"devDependencies": {
|
|
58
63
|
"@types/node": "^22.10.0",
|
|
59
64
|
"eslint": "^9.38.0",
|