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/README.md CHANGED
@@ -1,549 +1,596 @@
1
- # Isahaq Barcode Generator
2
-
3
- A universal barcode generator package supporting **32+ barcode types** (linear, 2D, postal, stacked, and auto-detection variants), multiple output formats, CLI, and Express.js integration.
4
-
5
- ## ๐Ÿš€ Features
6
-
7
- - **32+ Barcode Types**: Linear, 2D, postal, stacked, and auto-detection variants
8
- - **Multiple Output Formats**: PNG, SVG, HTML, JPG, PDF
9
- - **Express.js Integration**: Middleware and route helpers
10
- - **CLI Tool**: Command-line interface for quick barcode generation
11
- - **QR Code Builder**: Fluent API for advanced QR code generation
12
- - **Validation**: Built-in data validation for different barcode types
13
- - **Customization**: Size, colors, margins, and more options
14
- - **Batch Generation**: Generate multiple barcodes at once
15
- - **Watermarking**: Add logos and watermarks to QR codes
16
-
17
- ## ๐Ÿ“ฆ Installation
18
-
19
- ### Via npm
20
-
21
- ```bash
22
- npm install isahaq-barcode
23
- ```
24
-
25
- ### Requirements
26
-
27
- - Node.js 14.0 or higher
28
- - Canvas library (automatically installed)
29
-
30
- ## ๐Ÿ”ง Why Use This Package?
31
-
32
- 1. **Comprehensive Support**: 32+ barcode types including industry standards and auto-detection
33
- 2. **Multiple Formats**: Generate barcodes in PNG, SVG, HTML, JPG, and PDF
34
- 3. **Express.js Ready**: Seamless integration with Express.js framework
35
- 4. **CLI Support**: Generate barcodes from command line
36
- 5. **Advanced QR Codes**: Customizable QR codes with logos and labels
37
- 6. **Validation**: Built-in data validation for each barcode type
38
- 7. **Performance**: Optimized for high-volume generation
39
- 8. **Extensible**: Easy to add new barcode types and renderers
40
-
41
- ## ๐Ÿ“‹ Supported Barcode Types (32+ Types)
42
-
43
- ### Linear Barcodes
44
-
45
- - **Code128** (A, B, C, Auto)
46
- - **Code39** (Standard, Checksum, Extended, Auto)
47
- - **Code93**
48
- - **Code25** (Standard, Auto)
49
- - **Code32** (Italian Pharmacode)
50
- - **Standard25** (Standard, Checksum)
51
- - **Interleaved25** (Standard, Checksum, Auto)
52
- - **MSI** (Standard, Checksum, Auto)
53
-
54
- ### EAN/UPC Family
55
-
56
- - **EAN13**, **EAN8**, **EAN2**, **EAN5**
57
- - **UPC-A**, **UPC-E**
58
- - **ITF14**
59
-
60
- ### Postal Barcodes
61
-
62
- - **POSTNET**, **PLANET**, **RMS4CC**, **KIX**, **IMB**
63
-
64
- ### Specialized Barcodes
65
-
66
- - **Codabar**, **Code11**, **PharmaCode**, **PharmaCodeTwoTracks**
67
-
68
- ### 2D Matrix Codes
69
-
70
- - **QRCode**, **DataMatrix**, **Aztec**, **PDF417**, **MicroQR**, **Maxicode**
71
-
72
- ### Stacked Linear Codes
73
-
74
- - **Code16K**, **Code49**
75
-
76
- ## ๐Ÿ› ๏ธ Usage
77
-
78
- ### Basic Node.js Usage
79
-
80
- ```javascript
81
- const BarcodeGenerator = require("isahaq-barcode");
82
-
83
- // Generate PNG barcode
84
- const pngBuffer = BarcodeGenerator.png("1234567890", "code128");
85
-
86
- // Generate SVG barcode
87
- const svgString = BarcodeGenerator.svg("1234567890", "ean13");
88
-
89
- // Generate HTML barcode
90
- const htmlString = BarcodeGenerator.html("1234567890", "code39");
91
-
92
- // Generate PDF barcode
93
- const pdfBuffer = await BarcodeGenerator.pdf("1234567890", "code128");
94
- ```
95
-
96
- ### Display Barcode as Base64 Image (PNG)
97
-
98
- ```javascript
99
- const BarcodeGenerator = require("isahaq-barcode");
100
-
101
- // Generate barcode
102
- const barcodeBuffer = BarcodeGenerator.png("1234567890", "code128");
103
-
104
- // Convert to base64
105
- const barcodeImage = barcodeBuffer.toString("base64");
106
- console.log(
107
- `<img src="data:image/png;base64,${barcodeImage}" alt="Barcode" />`
108
- );
109
-
110
- // With custom options
111
- const customBarcode = BarcodeGenerator.png("1234567890", "code128", {
112
- width: 3,
113
- height: 150,
114
- displayValue: false,
115
- foregroundColor: "#FF0000",
116
- backgroundColor: "#FFFFFF",
117
- });
118
- ```
119
-
120
- ### QR Code with Logo and Watermark
121
-
122
- ```javascript
123
- const BarcodeGenerator = require("isahaq-barcode");
124
-
125
- const qrCode = BarcodeGenerator.modernQr({
126
- data: "https://example.com",
127
- size: 300,
128
- margin: 10,
129
- foregroundColor: [0, 0, 0],
130
- backgroundColor: [255, 255, 255],
131
- logoPath: "path/to/logo.png", // Logo in the center
132
- logoSize: 60, // Logo size as percentage
133
- label: "Scan me!", // Label below QR code
134
- watermark: "Watermark Text", // Watermark
135
- watermarkPosition: "center",
136
- errorCorrectionLevel: "H", // Use H for better logo support
137
- });
138
-
139
- // Save to file
140
- await qrCode.saveToFile("qr-code-with-logo.png");
141
-
142
- // Get as data URI
143
- const dataUri = await qrCode.getDataUri();
144
- console.log(`<img src="${dataUri}" alt="QR Code with Logo" />`);
145
- ```
146
-
147
- ### Using the Service Class
148
-
149
- ```javascript
150
- const { BarcodeService } = require("isahaq-barcode");
151
-
152
- const barcodeService = new BarcodeService();
153
-
154
- // Generate different formats
155
- const pngData = barcodeService.png("1234567890", "code128");
156
- const svgData = barcodeService.svg("1234567890", "ean13");
157
- const htmlData = barcodeService.html("1234567890", "code39");
158
-
159
- // Generate with custom options
160
- const options = {
161
- width: 300,
162
- height: 100,
163
- displayValue: true,
164
- foregroundColor: "#000000",
165
- backgroundColor: "#FFFFFF",
166
- };
167
- const customBarcode = barcodeService.generate(
168
- "1234567890",
169
- "code128",
170
- "png",
171
- options
172
- );
173
- ```
174
-
175
- ### QR Code Builder (Advanced)
176
-
177
- ```javascript
178
- const { QrCodeBuilder } = require("isahaq-barcode");
179
-
180
- const qrCode = QrCodeBuilder.create()
181
- .data("https://example.com")
182
- .size(300)
183
- .margin(10)
184
- .foregroundColor([0, 0, 0])
185
- .backgroundColor([255, 255, 255])
186
- .logoPath("path/to/logo.png")
187
- .logoSize(60)
188
- .label("Scan me!")
189
- .watermark("Watermark Text", "center")
190
- .format("png")
191
- .build();
192
-
193
- // Save to file
194
- await qrCode.saveToFile("qr-code.png");
195
-
196
- // Get data URI
197
- const dataUri = await qrCode.getDataUri();
198
- console.log(`<img src="${dataUri}" alt="QR Code">`);
199
- ```
200
-
201
- ## ๐ŸŽฏ Express.js Integration
202
-
203
- ### Basic Express.js Usage
204
-
205
- ```javascript
206
- const express = require('express')
207
- const BarcodeGenerator = require('isahaq-barcode')
208
-
209
- const app = express()
210
-
211
- // Generate barcode endpoint
212
- app.get('/barcode/:data', (req, res) => {
213
- const { data } = req.params
214
- const { type = 'code128', format = 'png' } = req.query
215
-
216
- try {
217
- let result
218
- switch (format) {
219
- case 'png':
220
- result = BarcodeGenerator.png(data, type)
221
- res.set('Content-Type', 'image/png')
222
- break
223
- case 'svg':
224
- result = BarcodeGenerator.svg(data, type)
225
- res.set('Content-Type', 'image/svg+xml')
226
- break
227
- case 'html':
228
- result = BarcodeGenerator.html(data, type)
229
- res.set('Content-Type', 'text/html')
230
- break
231
- default:
232
- throw new Error(`Unsupported format: ${format}`)
233
- }
234
-
235
- res.send(result)
236
- } catch (error) {
237
- res.status(400).json({ error: error.message })
238
- }
239
- })
240
-
241
- // Generate QR code endpoint
242
- app.get('/qr/:data', (req, res) => {
243
- const { data } = req.params
244
- const { size = 300, logo, label } = req.query
245
-
246
- try {
247
- const qrOptions = {
248
- data: decodeURIComponent(data),
249
- size: parseInt(size),
250
- logoPath: logo,
251
- label: label
252
- }
253
-
254
- const qrCode = BarcodeGenerator.modernQr(qrOptions)
255
- const result = await qrCode.generate()
256
-
257
- res.set('Content-Type', 'image/png')
258
- res.send(result)
259
- } catch (error) {
260
- res.status(400).json({ error: error.message })
261
- }
262
- })
263
-
264
- app.listen(3000, () => {
265
- console.log('Server running on port 3000')
266
- })
267
- ```
268
-
269
- ### Express.js Middleware
270
-
271
- ```javascript
272
- const express = require("express");
273
- const BarcodeGenerator = require("isahaq-barcode");
274
-
275
- const app = express();
276
-
277
- // Barcode middleware
278
- app.use("/api/barcode", (req, res, next) => {
279
- req.generateBarcode = (
280
- data,
281
- type = "code128",
282
- format = "png",
283
- options = {}
284
- ) => {
285
- try {
286
- switch (format) {
287
- case "png":
288
- return BarcodeGenerator.png(data, type, options);
289
- case "svg":
290
- return BarcodeGenerator.svg(data, type, options);
291
- case "html":
292
- return BarcodeGenerator.html(data, type, options);
293
- default:
294
- throw new Error(`Unsupported format: ${format}`);
295
- }
296
- } catch (error) {
297
- throw new Error(`Barcode generation failed: ${error.message}`);
298
- }
299
- };
300
- next();
301
- });
302
-
303
- // Use the middleware
304
- app.get("/api/barcode/:data", (req, res) => {
305
- const { data } = req.params;
306
- const { type, format, width, height } = req.query;
307
-
308
- const options = {};
309
- if (width) options.width = parseInt(width);
310
- if (height) options.height = parseInt(height);
311
-
312
- try {
313
- const result = req.generateBarcode(data, type, format, options);
314
- res.set("Content-Type", getMimeType(format));
315
- res.send(result);
316
- } catch (error) {
317
- res.status(400).json({ error: error.message });
318
- }
319
- });
320
-
321
- function getMimeType(format) {
322
- const mimeTypes = {
323
- png: "image/png",
324
- svg: "image/svg+xml",
325
- html: "text/html",
326
- };
327
- return mimeTypes[format] || "image/png";
328
- }
329
- ```
330
-
331
- ## ๐Ÿ–ฅ๏ธ CLI Usage
332
-
333
- ### Install CLI globally
334
-
335
- ```bash
336
- npm install -g isahaq-barcode
337
- ```
338
-
339
- ### Generate Barcode
340
-
341
- ```bash
342
- # Generate PNG barcode
343
- barcode-generate barcode -d "1234567890" -t code128 -f png -o barcode.png
344
-
345
- # Generate SVG barcode
346
- barcode-generate barcode -d "1234567890" -t ean13 -f svg -o barcode.svg
347
-
348
- # Generate with custom options
349
- barcode-generate barcode -d "1234567890" -t code128 -f png -w 3 -h 150 --foreground "#FF0000" --background "#FFFFFF"
350
- ```
351
-
352
- ### Generate QR Code
353
-
354
- ```bash
355
- # Generate QR code
356
- barcode-generate qr -d "https://example.com" -s 300 -f png -o qr.png
357
-
358
- # Generate QR code with logo
359
- barcode-generate qr -d "https://example.com" -s 300 --logo "path/to/logo.png" --logo-size 60 -o qr-with-logo.png
360
-
361
- # Generate QR code with watermark
362
- barcode-generate qr -d "https://example.com" -s 300 --watermark "Watermark Text" --watermark-position center -o qr-with-watermark.png
363
- ```
364
-
365
- ### Batch Generation
366
-
367
- ```bash
368
- # Create batch file (batch.json)
369
- echo '[
370
- {"data": "1234567890", "type": "code128", "format": "png"},
371
- {"data": "9876543210", "type": "code39", "format": "svg"},
372
- {"data": "https://example.com", "type": "qrcode", "format": "png"}
373
- ]' > batch.json
374
-
375
- # Generate batch
376
- barcode-generate batch -i batch.json -o ./output
377
- ```
378
-
379
- ### List Supported Types and Formats
380
-
381
- ```bash
382
- # List barcode types
383
- barcode-generate types
384
-
385
- # List output formats
386
- barcode-generate formats
387
-
388
- # Validate data
389
- barcode-generate validate -d "1234567890" -t code128
390
- ```
391
-
392
- ## ๐Ÿ“Š Advanced Features
393
-
394
- ### Batch Generation
395
-
396
- ```javascript
397
- const BarcodeGenerator = require("isahaq-barcode");
398
-
399
- const items = [
400
- { data: "1234567890", type: "code128", format: "png" },
401
- { data: "9876543210", type: "code39", format: "svg" },
402
- { data: "https://example.com", type: "qrcode", format: "png" },
403
- ];
404
-
405
- const results = BarcodeGenerator.batch(items);
406
- results.forEach((result, index) => {
407
- if (result.success) {
408
- console.log(`Barcode ${index} generated successfully`);
409
- } else {
410
- console.error(`Barcode ${index} failed: ${result.error}`);
411
- }
412
- });
413
- ```
414
-
415
- ### Validation
416
-
417
- ```javascript
418
- const BarcodeGenerator = require("isahaq-barcode");
419
-
420
- // Validate data for specific barcode type
421
- const validation = BarcodeGenerator.validate("1234567890", "code128");
422
- if (validation.valid) {
423
- console.log("Data is valid");
424
- console.log(`Length: ${validation.length}`);
425
- console.log(`Charset: ${validation.charset}`);
426
- } else {
427
- console.error(`Invalid data: ${validation.error}`);
428
- }
429
- ```
430
-
431
- ### Custom Renderer Options
432
-
433
- ```javascript
434
- const BarcodeGenerator = require("isahaq-barcode");
435
-
436
- const options = {
437
- width: 3,
438
- height: 150,
439
- displayValue: true,
440
- fontSize: 20,
441
- textAlign: "center",
442
- textPosition: "bottom",
443
- textMargin: 2,
444
- background: "#ffffff",
445
- lineColor: "#000000",
446
- margin: 10,
447
- marginTop: 10,
448
- marginBottom: 10,
449
- marginLeft: 10,
450
- marginRight: 10,
451
- };
452
-
453
- const barcode = BarcodeGenerator.png("1234567890", "code128", options);
454
- ```
455
-
456
- ### Available Watermark Positions
457
-
458
- ```javascript
459
- const BarcodeGenerator = require("isahaq-barcode");
460
-
461
- const positions = BarcodeGenerator.getWatermarkPositions();
462
- // Returns: ['top-left', 'top-right', 'bottom-left', 'bottom-right', 'center',
463
- // 'top-center', 'bottom-center', 'left-center', 'right-center']
464
- ```
465
-
466
- ## ๐Ÿงช Testing
467
-
468
- ```bash
469
- # Run tests
470
- npm test
471
-
472
- # Run tests with coverage
473
- npm run test:coverage
474
-
475
- # Run tests in watch mode
476
- npm run test:watch
477
- ```
478
-
479
- ## ๐Ÿ“ API Reference
480
-
481
- ### BarcodeGenerator
482
-
483
- #### Methods
484
-
485
- - `png(data, type, options)` - Generate PNG barcode
486
- - `svg(data, type, options)` - Generate SVG barcode
487
- - `html(data, type, options)` - Generate HTML barcode
488
- - `pdf(data, type, options)` - Generate PDF barcode
489
- - `modernQr(options)` - Generate QR code with advanced features
490
- - `validate(data, type)` - Validate data for barcode type
491
- - `batch(items)` - Generate multiple barcodes
492
- - `getBarcodeTypes()` - Get supported barcode types
493
- - `getRenderFormats()` - Get supported output formats
494
- - `getWatermarkPositions()` - Get watermark positions
495
-
496
- ### QrCodeBuilder
497
-
498
- #### Methods
499
-
500
- - `create(options)` - Create new builder instance
501
- - `data(data)` - Set data to encode
502
- - `size(size)` - Set QR code size
503
- - `margin(margin)` - Set margin
504
- - `errorCorrectionLevel(level)` - Set error correction level
505
- - `foregroundColor(color)` - Set foreground color
506
- - `backgroundColor(color)` - Set background color
507
- - `logoPath(path)` - Set logo path
508
- - `logoSize(size)` - Set logo size
509
- - `label(text)` - Set label text
510
- - `watermark(text, position)` - Set watermark
511
- - `format(format)` - Set output format
512
- - `build()` - Build QR code
513
- - `generate()` - Generate QR code buffer
514
- - `saveToFile(path)` - Save to file
515
- - `getDataUri()` - Get data URI
516
- - `getString()` - Get QR code string
517
-
518
- ## ๐Ÿค Contributing
519
-
520
- 1. Fork the repository
521
- 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
522
- 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
523
- 4. Push to the branch (`git push origin feature/amazing-feature`)
524
- 5. Open a Pull Request
525
-
526
- ## ๐Ÿ“„ License
527
-
528
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
529
-
530
- ## ๐Ÿ™ Acknowledgments
531
-
532
- - [JsBarcode](https://github.com/lindell/JsBarcode) - Barcode generation library
533
- - [QRCode](https://github.com/soldair/node-qrcode) - QR code generation library
534
- - [Canvas](https://github.com/Automattic/node-canvas) - Canvas implementation for Node.js
535
- - [PDFKit](https://github.com/foliojs/pdfkit) - PDF generation library
536
-
537
- ## ๐Ÿ“ž Support
538
-
539
- If you have any questions or need help, please:
540
-
541
- 1. Check the [documentation](README.md)
542
- 2. Search [existing issues](https://github.com/isahaq1/barcode-generator-npm/issues)
543
- 3. Create a [new issue](https://github.com/isahaq1/barcode-generator-npm/issues/new)
544
-
545
- ---
546
-
547
- **Made with โค๏ธ by [Isahaq](https://github.com/isahaq1)**
548
- # npm-barcodegeneratop
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
+ [![npm version](https://img.shields.io/npm/v/isahaq-barcode.svg)](https://www.npmjs.com/package/isahaq-barcode)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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>