isahaq-barcode 1.0.0 โ 1.2.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/.eslintrc.js +29 -29
- package/.prettierignore +11 -0
- package/.prettierrc +11 -0
- package/README.md +596 -549
- package/bin/generate.js +274 -274
- package/eslint.config.js +66 -68
- package/examples/basic-usage.js +58 -58
- package/examples/batch-example.json +56 -56
- package/examples/express-server.js +163 -159
- package/index.js +134 -134
- package/jest.config.js +13 -13
- package/package.json +27 -15
- package/src/builders/QrCodeBuilder.js +401 -401
- package/src/renderers/HTMLRenderer.js +212 -212
- package/src/renderers/PDFRenderer.js +184 -184
- package/src/renderers/PNGRenderer.js +123 -123
- package/src/renderers/RenderFormats.js +87 -87
- package/src/renderers/SVGRenderer.js +221 -221
- package/src/services/BarcodeService.js +175 -175
- package/src/types/BarcodeTypes.js +195 -195
- package/src/validators/Validator.js +352 -352
- package/tests/BarcodeGenerator.test.js +187 -187
- package/tests/BarcodeService.test.js +76 -76
- package/tests/QrCodeBuilder.test.js +130 -130
- package/tests/setup.js +59 -59
package/README.md
CHANGED
|
@@ -1,549 +1,596 @@
|
|
|
1
|
-
# Isahaq Barcode Generator
|
|
2
|
-
|
|
3
|
-
A
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
###
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
foregroundColor:
|
|
130
|
-
backgroundColor:
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
.
|
|
182
|
-
.
|
|
183
|
-
.
|
|
184
|
-
.
|
|
185
|
-
.
|
|
186
|
-
.
|
|
187
|
-
.
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
})
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
```
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
##
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
1
|
+
# Isahaq Barcode Generator
|
|
2
|
+
|
|
3
|
+
> A comprehensive Node.js barcode generation library supporting 32+ barcode types with Express.js integration and CLI tools
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/isahaq-barcode)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Table of Contents
|
|
11
|
+
|
|
12
|
+
- [Features](#-features)
|
|
13
|
+
- [Installation](#-installation)
|
|
14
|
+
- [Quick Start](#-quick-start)
|
|
15
|
+
- [Supported Barcode Types](#-supported-barcode-types)
|
|
16
|
+
- [Usage Examples](#-usage-examples)
|
|
17
|
+
- [Express.js Integration](#-expressjs-integration)
|
|
18
|
+
- [CLI Usage](#-cli-usage)
|
|
19
|
+
- [API Reference](#-api-reference)
|
|
20
|
+
- [Contributing](#-contributing)
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## โจ Features
|
|
25
|
+
|
|
26
|
+
| Feature | Description |
|
|
27
|
+
| --------------------- | -------------------------------------------------------- |
|
|
28
|
+
| **32+ Barcode Types** | Linear, 2D, postal, stacked, and auto-detection variants |
|
|
29
|
+
| **Multiple Formats** | PNG, SVG, HTML, JPG, PDF output support |
|
|
30
|
+
| **Framework Ready** | Express.js middleware and route helpers included |
|
|
31
|
+
| **CLI Tool** | Generate barcodes directly from terminal |
|
|
32
|
+
| **Advanced QR Codes** | Logos, watermarks, labels, and customization |
|
|
33
|
+
| **Validation** | Built-in data validation for all barcode types |
|
|
34
|
+
| **Batch Processing** | Generate multiple barcodes simultaneously |
|
|
35
|
+
| **High Performance** | Optimized for enterprise-scale generation |
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## ๐ฆ Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install isahaq-barcode
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Requirements:** Node.js 14.0 or higher
|
|
46
|
+
|
|
47
|
+
**Global CLI Installation:**
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm install -g isahaq-barcode
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## ๐ Quick Start
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
const BarcodeGenerator = require('isahaq-barcode');
|
|
59
|
+
|
|
60
|
+
// Generate PNG barcode
|
|
61
|
+
const pngBuffer = BarcodeGenerator.png('1234567890', 'code128');
|
|
62
|
+
|
|
63
|
+
// Generate SVG barcode
|
|
64
|
+
const svgString = BarcodeGenerator.svg('1234567890', 'ean13');
|
|
65
|
+
|
|
66
|
+
// Generate QR code with logo
|
|
67
|
+
const qrCode = BarcodeGenerator.modernQr({
|
|
68
|
+
data: 'https://example.com',
|
|
69
|
+
size: 300,
|
|
70
|
+
logoPath: 'path/to/logo.png',
|
|
71
|
+
label: 'Scan me!',
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
await qrCode.saveToFile('qr-code.png');
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## ๐ Supported Barcode Types
|
|
80
|
+
|
|
81
|
+
### Linear Barcodes (1D)
|
|
82
|
+
|
|
83
|
+
| Type | Variants | Use Case |
|
|
84
|
+
| -------------- | ---------------------------------- | ----------------------------- |
|
|
85
|
+
| **Code 128** | A, B, C, Auto | General purpose, high density |
|
|
86
|
+
| **Code 39** | Standard, Extended, Checksum, Auto | Alphanumeric, automotive |
|
|
87
|
+
| **Code 93** | - | Compact alphanumeric |
|
|
88
|
+
| **EAN Family** | EAN-13, EAN-8, EAN-2, EAN-5 | Retail products (Europe) |
|
|
89
|
+
| **UPC Family** | UPC-A, UPC-E | Retail products (USA) |
|
|
90
|
+
| **Code 25** | Standard, Interleaved, Auto | Industrial, logistics |
|
|
91
|
+
| **ITF-14** | - | Shipping containers |
|
|
92
|
+
| **MSI** | Standard, Checksum, Auto | Inventory management |
|
|
93
|
+
| **Codabar** | - | Libraries, blood banks |
|
|
94
|
+
| **Code 11** | - | Telecommunications |
|
|
95
|
+
|
|
96
|
+
### 2D Barcodes
|
|
97
|
+
|
|
98
|
+
| Type | Data Capacity | Use Case |
|
|
99
|
+
| --------------- | ----------------- | ----------------------- |
|
|
100
|
+
| **QR Code** | Up to 4,296 chars | URLs, payments, general |
|
|
101
|
+
| **Data Matrix** | Up to 2,335 chars | Small item marking |
|
|
102
|
+
| **Aztec** | Up to 3,832 chars | Transport tickets |
|
|
103
|
+
| **PDF417** | Up to 1,850 chars | IDs, boarding passes |
|
|
104
|
+
| **Micro QR** | Up to 35 chars | Compact applications |
|
|
105
|
+
| **MaxiCode** | Up to 93 chars | Package tracking |
|
|
106
|
+
|
|
107
|
+
### Postal Barcodes
|
|
108
|
+
|
|
109
|
+
**POSTNET** โข **PLANET** โข **RMS4CC** โข **KIX** โข **IMB**
|
|
110
|
+
|
|
111
|
+
### Specialized
|
|
112
|
+
|
|
113
|
+
**Code 32** (Italian Pharmacode) โข **PharmaCode** โข **PharmaCodeTwoTracks** โข **Code 16K** โข **Code 49**
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## ๐ป Usage Examples
|
|
118
|
+
|
|
119
|
+
### Basic Generation
|
|
120
|
+
|
|
121
|
+
```javascript
|
|
122
|
+
const BarcodeGenerator = require('isahaq-barcode');
|
|
123
|
+
|
|
124
|
+
// PNG with custom options
|
|
125
|
+
const barcode = BarcodeGenerator.png('1234567890', 'code128', {
|
|
126
|
+
width: 3,
|
|
127
|
+
height: 150,
|
|
128
|
+
displayValue: true,
|
|
129
|
+
foregroundColor: '#000000',
|
|
130
|
+
backgroundColor: '#FFFFFF',
|
|
131
|
+
margin: 10,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Convert to Base64 for web display
|
|
135
|
+
const base64Image = barcode.toString('base64');
|
|
136
|
+
console.log(`<img src="data:image/png;base64,${base64Image}" alt="Barcode" />`);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Advanced QR Code with Logo
|
|
140
|
+
|
|
141
|
+
```javascript
|
|
142
|
+
const qrCode = BarcodeGenerator.modernQr({
|
|
143
|
+
data: 'https://example.com',
|
|
144
|
+
size: 300,
|
|
145
|
+
margin: 10,
|
|
146
|
+
|
|
147
|
+
// Logo configuration
|
|
148
|
+
logoPath: 'path/to/logo.png',
|
|
149
|
+
logoSize: 60, // Percentage
|
|
150
|
+
|
|
151
|
+
// Text elements
|
|
152
|
+
label: 'Scan me!',
|
|
153
|
+
watermark: 'Company Name',
|
|
154
|
+
watermarkPosition: 'bottom-center',
|
|
155
|
+
|
|
156
|
+
// Colors
|
|
157
|
+
foregroundColor: [0, 0, 0],
|
|
158
|
+
backgroundColor: [255, 255, 255],
|
|
159
|
+
|
|
160
|
+
// Error correction (H recommended for logos)
|
|
161
|
+
errorCorrectionLevel: 'H',
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// Save to file
|
|
165
|
+
await qrCode.saveToFile('qr-code.png');
|
|
166
|
+
|
|
167
|
+
// Get as data URI
|
|
168
|
+
const dataUri = await qrCode.getDataUri();
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### QR Code Builder Pattern
|
|
172
|
+
|
|
173
|
+
```javascript
|
|
174
|
+
const { QrCodeBuilder } = require('isahaq-barcode');
|
|
175
|
+
|
|
176
|
+
const qrCode = QrCodeBuilder.create()
|
|
177
|
+
.data('https://example.com')
|
|
178
|
+
.size(300)
|
|
179
|
+
.margin(10)
|
|
180
|
+
.foregroundColor([0, 0, 0])
|
|
181
|
+
.backgroundColor([255, 255, 255])
|
|
182
|
+
.logoPath('path/to/logo.png')
|
|
183
|
+
.logoSize(60)
|
|
184
|
+
.label('Scan me!')
|
|
185
|
+
.watermark('Watermark Text', 'center')
|
|
186
|
+
.format('png')
|
|
187
|
+
.build();
|
|
188
|
+
|
|
189
|
+
await qrCode.saveToFile('qr-code.png');
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Batch Generation
|
|
193
|
+
|
|
194
|
+
```javascript
|
|
195
|
+
const items = [
|
|
196
|
+
{ data: '1234567890', type: 'code128', format: 'png' },
|
|
197
|
+
{ data: '9876543210', type: 'code39', format: 'svg' },
|
|
198
|
+
{ data: 'https://example.com', type: 'qrcode', format: 'png' },
|
|
199
|
+
];
|
|
200
|
+
|
|
201
|
+
const results = BarcodeGenerator.batch(items);
|
|
202
|
+
|
|
203
|
+
results.forEach((result, index) => {
|
|
204
|
+
if (result.success) {
|
|
205
|
+
console.log(`โ Barcode ${index} generated`);
|
|
206
|
+
// result.data contains the generated barcode
|
|
207
|
+
} else {
|
|
208
|
+
console.error(`โ Barcode ${index} failed: ${result.error}`);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Data Validation
|
|
214
|
+
|
|
215
|
+
```javascript
|
|
216
|
+
const validation = BarcodeGenerator.validate('1234567890', 'code128');
|
|
217
|
+
|
|
218
|
+
if (validation.valid) {
|
|
219
|
+
console.log('โ Valid data');
|
|
220
|
+
console.log(` Length: ${validation.length}`);
|
|
221
|
+
console.log(` Charset: ${validation.charset}`);
|
|
222
|
+
} else {
|
|
223
|
+
console.error(`โ Invalid: ${validation.error}`);
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## ๐ Express.js Integration
|
|
230
|
+
|
|
231
|
+
### Basic Route Implementation
|
|
232
|
+
|
|
233
|
+
```javascript
|
|
234
|
+
const express = require('express');
|
|
235
|
+
const BarcodeGenerator = require('isahaq-barcode');
|
|
236
|
+
|
|
237
|
+
const app = express();
|
|
238
|
+
|
|
239
|
+
// Barcode endpoint
|
|
240
|
+
app.get('/barcode/:data', (req, res) => {
|
|
241
|
+
const { data } = req.params;
|
|
242
|
+
const { type = 'code128', format = 'png' } = req.query;
|
|
243
|
+
|
|
244
|
+
try {
|
|
245
|
+
let result, contentType;
|
|
246
|
+
|
|
247
|
+
switch (format) {
|
|
248
|
+
case 'png':
|
|
249
|
+
result = BarcodeGenerator.png(data, type);
|
|
250
|
+
contentType = 'image/png';
|
|
251
|
+
break;
|
|
252
|
+
case 'svg':
|
|
253
|
+
result = BarcodeGenerator.svg(data, type);
|
|
254
|
+
contentType = 'image/svg+xml';
|
|
255
|
+
break;
|
|
256
|
+
case 'html':
|
|
257
|
+
result = BarcodeGenerator.html(data, type);
|
|
258
|
+
contentType = 'text/html';
|
|
259
|
+
break;
|
|
260
|
+
default:
|
|
261
|
+
return res.status(400).json({ error: 'Invalid format' });
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
res.set('Content-Type', contentType);
|
|
265
|
+
res.send(result);
|
|
266
|
+
} catch (error) {
|
|
267
|
+
res.status(400).json({ error: error.message });
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
// QR code endpoint
|
|
272
|
+
app.get('/qr/:data', async (req, res) => {
|
|
273
|
+
const { data } = req.params;
|
|
274
|
+
const { size = 300, logo, label } = req.query;
|
|
275
|
+
|
|
276
|
+
try {
|
|
277
|
+
const qrCode = BarcodeGenerator.modernQr({
|
|
278
|
+
data: decodeURIComponent(data),
|
|
279
|
+
size: parseInt(size),
|
|
280
|
+
logoPath: logo,
|
|
281
|
+
label: label,
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
const result = await qrCode.generate();
|
|
285
|
+
res.set('Content-Type', 'image/png');
|
|
286
|
+
res.send(result);
|
|
287
|
+
} catch (error) {
|
|
288
|
+
res.status(400).json({ error: error.message });
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
app.listen(3000, () => {
|
|
293
|
+
console.log('๐ Barcode server running on port 3000');
|
|
294
|
+
});
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Middleware Pattern
|
|
298
|
+
|
|
299
|
+
```javascript
|
|
300
|
+
const express = require('express');
|
|
301
|
+
const BarcodeGenerator = require('isahaq-barcode');
|
|
302
|
+
|
|
303
|
+
const app = express();
|
|
304
|
+
|
|
305
|
+
// Barcode middleware
|
|
306
|
+
app.use('/api/barcode', (req, res, next) => {
|
|
307
|
+
req.generateBarcode = (
|
|
308
|
+
data,
|
|
309
|
+
type = 'code128',
|
|
310
|
+
format = 'png',
|
|
311
|
+
options = {}
|
|
312
|
+
) => {
|
|
313
|
+
try {
|
|
314
|
+
switch (format) {
|
|
315
|
+
case 'png':
|
|
316
|
+
return BarcodeGenerator.png(data, type, options);
|
|
317
|
+
case 'svg':
|
|
318
|
+
return BarcodeGenerator.svg(data, type, options);
|
|
319
|
+
case 'html':
|
|
320
|
+
return BarcodeGenerator.html(data, type, options);
|
|
321
|
+
default:
|
|
322
|
+
throw new Error(`Unsupported format: ${format}`);
|
|
323
|
+
}
|
|
324
|
+
} catch (error) {
|
|
325
|
+
throw new Error(`Generation failed: ${error.message}`);
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
next();
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
// Route using middleware
|
|
332
|
+
app.get('/api/barcode/:data', (req, res) => {
|
|
333
|
+
const { data } = req.params;
|
|
334
|
+
const { type, format = 'png', width, height } = req.query;
|
|
335
|
+
|
|
336
|
+
const options = {};
|
|
337
|
+
if (width) options.width = parseInt(width);
|
|
338
|
+
if (height) options.height = parseInt(height);
|
|
339
|
+
|
|
340
|
+
try {
|
|
341
|
+
const result = req.generateBarcode(data, type, format, options);
|
|
342
|
+
const mimeTypes = {
|
|
343
|
+
png: 'image/png',
|
|
344
|
+
svg: 'image/svg+xml',
|
|
345
|
+
html: 'text/html',
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
res.set('Content-Type', mimeTypes[format] || 'image/png');
|
|
349
|
+
res.send(result);
|
|
350
|
+
} catch (error) {
|
|
351
|
+
res.status(400).json({ error: error.message });
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
---
|
|
357
|
+
|
|
358
|
+
## ๐ฅ๏ธ CLI Usage
|
|
359
|
+
|
|
360
|
+
### Generate Barcodes
|
|
361
|
+
|
|
362
|
+
```bash
|
|
363
|
+
# Basic PNG barcode
|
|
364
|
+
barcode-generate barcode -d "1234567890" -t code128 -f png -o barcode.png
|
|
365
|
+
|
|
366
|
+
# SVG with custom dimensions
|
|
367
|
+
barcode-generate barcode -d "1234567890" -t ean13 -f svg -w 3 -h 150 -o barcode.svg
|
|
368
|
+
|
|
369
|
+
# Custom colors
|
|
370
|
+
barcode-generate barcode -d "1234567890" -t code128 \
|
|
371
|
+
--foreground "#FF0000" --background "#FFFFFF" -o red-barcode.png
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
### Generate QR Codes
|
|
375
|
+
|
|
376
|
+
```bash
|
|
377
|
+
# Basic QR code
|
|
378
|
+
barcode-generate qr -d "https://example.com" -s 300 -o qr.png
|
|
379
|
+
|
|
380
|
+
# QR code with logo
|
|
381
|
+
barcode-generate qr -d "https://example.com" -s 300 \
|
|
382
|
+
--logo "path/to/logo.png" --logo-size 60 -o qr-logo.png
|
|
383
|
+
|
|
384
|
+
# QR code with watermark
|
|
385
|
+
barcode-generate qr -d "https://example.com" -s 300 \
|
|
386
|
+
--watermark "Company Name" --watermark-position bottom-center -o qr-watermark.png
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
### Batch Operations
|
|
390
|
+
|
|
391
|
+
```bash
|
|
392
|
+
# Create batch configuration file
|
|
393
|
+
cat > batch.json << EOF
|
|
394
|
+
[
|
|
395
|
+
{"data": "1234567890", "type": "code128", "format": "png"},
|
|
396
|
+
{"data": "9876543210", "type": "code39", "format": "svg"},
|
|
397
|
+
{"data": "https://example.com", "type": "qrcode", "format": "png"}
|
|
398
|
+
]
|
|
399
|
+
EOF
|
|
400
|
+
|
|
401
|
+
# Generate batch
|
|
402
|
+
barcode-generate batch -i batch.json -o ./output
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
### Utility Commands
|
|
406
|
+
|
|
407
|
+
```bash
|
|
408
|
+
# List supported barcode types
|
|
409
|
+
barcode-generate types
|
|
410
|
+
|
|
411
|
+
# List output formats
|
|
412
|
+
barcode-generate formats
|
|
413
|
+
|
|
414
|
+
# Validate data for specific type
|
|
415
|
+
barcode-generate validate -d "1234567890" -t code128
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
---
|
|
419
|
+
|
|
420
|
+
## ๐ API Reference
|
|
421
|
+
|
|
422
|
+
### BarcodeGenerator (Static Methods)
|
|
423
|
+
|
|
424
|
+
#### Generation Methods
|
|
425
|
+
|
|
426
|
+
```javascript
|
|
427
|
+
BarcodeGenerator.png(data, type, options?)
|
|
428
|
+
// Returns: Buffer
|
|
429
|
+
|
|
430
|
+
BarcodeGenerator.svg(data, type, options?)
|
|
431
|
+
// Returns: String
|
|
432
|
+
|
|
433
|
+
BarcodeGenerator.html(data, type, options?)
|
|
434
|
+
// Returns: String
|
|
435
|
+
|
|
436
|
+
BarcodeGenerator.pdf(data, type, options?)
|
|
437
|
+
// Returns: Promise<Buffer>
|
|
438
|
+
|
|
439
|
+
BarcodeGenerator.modernQr(options)
|
|
440
|
+
// Returns: QrCodeInstance
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
#### Utility Methods
|
|
444
|
+
|
|
445
|
+
```javascript
|
|
446
|
+
BarcodeGenerator.validate(data, type);
|
|
447
|
+
// Returns: { valid: boolean, error?: string, length?: number, charset?: string }
|
|
448
|
+
|
|
449
|
+
BarcodeGenerator.batch(items);
|
|
450
|
+
// Returns: Array<{ success: boolean, data?: Buffer|String, error?: string }>
|
|
451
|
+
|
|
452
|
+
BarcodeGenerator.getBarcodeTypes();
|
|
453
|
+
// Returns: Array<string>
|
|
454
|
+
|
|
455
|
+
BarcodeGenerator.getRenderFormats();
|
|
456
|
+
// Returns: Array<string>
|
|
457
|
+
|
|
458
|
+
BarcodeGenerator.getWatermarkPositions();
|
|
459
|
+
// Returns: Array<string>
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
### Options Object
|
|
463
|
+
|
|
464
|
+
```javascript
|
|
465
|
+
{
|
|
466
|
+
// Dimensions
|
|
467
|
+
width: 3, // Bar width
|
|
468
|
+
height: 150, // Bar height
|
|
469
|
+
|
|
470
|
+
// Display
|
|
471
|
+
displayValue: true, // Show text below barcode
|
|
472
|
+
fontSize: 20, // Text font size
|
|
473
|
+
textAlign: 'center', // 'left' | 'center' | 'right'
|
|
474
|
+
textPosition: 'bottom', // 'top' | 'bottom'
|
|
475
|
+
textMargin: 2, // Space between bars and text
|
|
476
|
+
|
|
477
|
+
// Colors
|
|
478
|
+
background: '#ffffff', // Background color
|
|
479
|
+
lineColor: '#000000', // Bar color (alias: foregroundColor)
|
|
480
|
+
|
|
481
|
+
// Margins
|
|
482
|
+
margin: 10, // All sides
|
|
483
|
+
marginTop: 10, // Individual sides
|
|
484
|
+
marginBottom: 10,
|
|
485
|
+
marginLeft: 10,
|
|
486
|
+
marginRight: 10
|
|
487
|
+
}
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
### QrCodeBuilder Methods
|
|
491
|
+
|
|
492
|
+
```javascript
|
|
493
|
+
QrCodeBuilder.create(options?)
|
|
494
|
+
.data(string) // Set data to encode
|
|
495
|
+
.size(number) // QR code size in pixels
|
|
496
|
+
.margin(number) // Margin size
|
|
497
|
+
.errorCorrectionLevel(level) // 'L' | 'M' | 'Q' | 'H'
|
|
498
|
+
.foregroundColor(rgb) // [R, G, B]
|
|
499
|
+
.backgroundColor(rgb) // [R, G, B]
|
|
500
|
+
.logoPath(string) // Path to logo image
|
|
501
|
+
.logoSize(number) // Logo size percentage
|
|
502
|
+
.label(string) // Label text
|
|
503
|
+
.watermark(text, position) // Watermark text and position
|
|
504
|
+
.format(format) // 'png' | 'svg'
|
|
505
|
+
.build() // Build QR code instance
|
|
506
|
+
|
|
507
|
+
// QR Code Instance Methods
|
|
508
|
+
qrCode.generate() // Returns: Promise<Buffer>
|
|
509
|
+
qrCode.saveToFile(path) // Returns: Promise<void>
|
|
510
|
+
qrCode.getDataUri() // Returns: Promise<string>
|
|
511
|
+
qrCode.getString() // Returns: Promise<string>
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
### Watermark Positions
|
|
515
|
+
|
|
516
|
+
```javascript
|
|
517
|
+
('top-left',
|
|
518
|
+
'top-center',
|
|
519
|
+
'top-right',
|
|
520
|
+
'left-center',
|
|
521
|
+
'center',
|
|
522
|
+
'right-center',
|
|
523
|
+
'bottom-left',
|
|
524
|
+
'bottom-center',
|
|
525
|
+
'bottom-right');
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
---
|
|
529
|
+
|
|
530
|
+
## ๐งช Testing
|
|
531
|
+
|
|
532
|
+
```bash
|
|
533
|
+
# Run all tests
|
|
534
|
+
npm test
|
|
535
|
+
|
|
536
|
+
# Run with coverage report
|
|
537
|
+
npm run test:coverage
|
|
538
|
+
|
|
539
|
+
# Watch mode for development
|
|
540
|
+
npm run test:watch
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
---
|
|
544
|
+
|
|
545
|
+
## ๐ค Contributing
|
|
546
|
+
|
|
547
|
+
We welcome contributions! Please follow these steps:
|
|
548
|
+
|
|
549
|
+
1. **Fork** the repository
|
|
550
|
+
2. **Create** a feature branch: `git checkout -b feature/amazing-feature`
|
|
551
|
+
3. **Commit** your changes: `git commit -m 'Add amazing feature'`
|
|
552
|
+
4. **Push** to the branch: `git push origin feature/amazing-feature`
|
|
553
|
+
5. **Open** a Pull Request
|
|
554
|
+
|
|
555
|
+
Please ensure your code:
|
|
556
|
+
|
|
557
|
+
- Follows the existing code style
|
|
558
|
+
- Includes tests for new features
|
|
559
|
+
- Updates documentation as needed
|
|
560
|
+
|
|
561
|
+
---
|
|
562
|
+
|
|
563
|
+
## ๐ License
|
|
564
|
+
|
|
565
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
566
|
+
|
|
567
|
+
---
|
|
568
|
+
|
|
569
|
+
## ๐ Acknowledgments
|
|
570
|
+
|
|
571
|
+
Built with these excellent libraries:
|
|
572
|
+
|
|
573
|
+
- [JsBarcode](https://github.com/lindell/JsBarcode) - Barcode generation
|
|
574
|
+
- [node-qrcode](https://github.com/soldair/node-qrcode) - QR code generation
|
|
575
|
+
- [node-canvas](https://github.com/Automattic/node-canvas) - Canvas implementation
|
|
576
|
+
- [PDFKit](https://github.com/foliojs/pdfkit) - PDF generation
|
|
577
|
+
|
|
578
|
+
---
|
|
579
|
+
|
|
580
|
+
## ๐ Support
|
|
581
|
+
|
|
582
|
+
Need help? Here's how to get support:
|
|
583
|
+
|
|
584
|
+
1. ๐ Check the [documentation](README.md)
|
|
585
|
+
2. ๐ Search [existing issues](https://github.com/isahaq1//npm-barcodegeneratop/issues)
|
|
586
|
+
3. ๐ฌ Create a [new issue](https://github.com/isahaq1//npm-barcodegeneratop/issues/new)
|
|
587
|
+
|
|
588
|
+
---
|
|
589
|
+
|
|
590
|
+
<div align="center">
|
|
591
|
+
|
|
592
|
+
**Made with โค๏ธ by [Isahaq](https://github.com/isahaq1)**
|
|
593
|
+
|
|
594
|
+
[โญ Star this repo](https://github.com/isahaq1//npm-barcodegeneratop) โข [๐ Report Bug](https://github.com/isahaq1//npm-barcodegeneratop/issues) โข [โจ Request Feature](https://github.com/isahaq1//npm-barcodegeneratop/issues)
|
|
595
|
+
|
|
596
|
+
</div>
|