isahaq-barcode 1.1.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.
Files changed (2) hide show
  1. package/README.md +354 -308
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,178 +1,174 @@
1
1
  # Isahaq Barcode Generator
2
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.
3
+ > A comprehensive Node.js barcode generation library supporting 32+ barcode types with Express.js integration and CLI tools
4
4
 
5
- ## ๐Ÿš€ Features
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)
6
7
 
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
8
+ ---
18
9
 
19
- ### Via npm
10
+ ## Table of Contents
20
11
 
21
- ```bash
22
- npm install isahaq-barcode
23
- ```
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)
24
21
 
25
- ### Requirements
22
+ ---
26
23
 
27
- - Node.js 14.0 or higher
28
- - Canvas library (automatically installed)
24
+ ## โœจ Features
29
25
 
30
- ## ๐Ÿ”ง Why Use This Package?
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 |
31
36
 
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
37
+ ---
40
38
 
41
- ## ๐Ÿ“‹ Supported Barcode Types (32+ Types)
39
+ ## ๐Ÿ“ฆ Installation
42
40
 
43
- ### Linear Barcodes
41
+ ```bash
42
+ npm install isahaq-barcode
43
+ ```
44
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)
45
+ **Requirements:** Node.js 14.0 or higher
53
46
 
54
- ### EAN/UPC Family
47
+ **Global CLI Installation:**
55
48
 
56
- - **EAN13**, **EAN8**, **EAN2**, **EAN5**
57
- - **UPC-A**, **UPC-E**
58
- - **ITF14**
49
+ ```bash
50
+ npm install -g isahaq-barcode
51
+ ```
59
52
 
60
- ### Postal Barcodes
53
+ ---
61
54
 
62
- - **POSTNET**, **PLANET**, **RMS4CC**, **KIX**, **IMB**
55
+ ## ๐Ÿš€ Quick Start
63
56
 
64
- ### Specialized Barcodes
57
+ ```javascript
58
+ const BarcodeGenerator = require('isahaq-barcode');
65
59
 
66
- - **Codabar**, **Code11**, **PharmaCode**, **PharmaCodeTwoTracks**
60
+ // Generate PNG barcode
61
+ const pngBuffer = BarcodeGenerator.png('1234567890', 'code128');
67
62
 
68
- ### 2D Matrix Codes
63
+ // Generate SVG barcode
64
+ const svgString = BarcodeGenerator.svg('1234567890', 'ean13');
69
65
 
70
- - **QRCode**, **DataMatrix**, **Aztec**, **PDF417**, **MicroQR**, **Maxicode**
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
+ });
71
73
 
72
- ### Stacked Linear Codes
74
+ await qrCode.saveToFile('qr-code.png');
75
+ ```
73
76
 
74
- - **Code16K**, **Code49**
77
+ ---
75
78
 
76
- ## ๐Ÿ› ๏ธ Usage
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 |
77
106
 
78
- ### Basic Node.js Usage
107
+ ### Postal Barcodes
79
108
 
80
- ```javascript
81
- const BarcodeGenerator = require('isahaq-barcode');
109
+ **POSTNET** โ€ข **PLANET** โ€ข **RMS4CC** โ€ข **KIX** โ€ข **IMB**
82
110
 
83
- // Generate PNG barcode
84
- const pngBuffer = BarcodeGenerator.png('1234567890', 'code128');
111
+ ### Specialized
85
112
 
86
- // Generate SVG barcode
87
- const svgString = BarcodeGenerator.svg('1234567890', 'ean13');
113
+ **Code 32** (Italian Pharmacode) โ€ข **PharmaCode** โ€ข **PharmaCodeTwoTracks** โ€ข **Code 16K** โ€ข **Code 49**
88
114
 
89
- // Generate HTML barcode
90
- const htmlString = BarcodeGenerator.html('1234567890', 'code39');
115
+ ---
91
116
 
92
- // Generate PDF barcode
93
- const pdfBuffer = await BarcodeGenerator.pdf('1234567890', 'code128');
94
- ```
117
+ ## ๐Ÿ’ป Usage Examples
95
118
 
96
- ### Display Barcode as Base64 Image (PNG)
119
+ ### Basic Generation
97
120
 
98
121
  ```javascript
99
122
  const BarcodeGenerator = require('isahaq-barcode');
100
123
 
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', {
124
+ // PNG with custom options
125
+ const barcode = BarcodeGenerator.png('1234567890', 'code128', {
112
126
  width: 3,
113
127
  height: 150,
114
- displayValue: false,
115
- foregroundColor: '#FF0000',
128
+ displayValue: true,
129
+ foregroundColor: '#000000',
116
130
  backgroundColor: '#FFFFFF',
131
+ margin: 10,
117
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" />`);
118
137
  ```
119
138
 
120
- ### QR Code with Logo and Watermark
139
+ ### Advanced QR Code with Logo
121
140
 
122
141
  ```javascript
123
- const BarcodeGenerator = require('isahaq-barcode');
124
-
125
142
  const qrCode = BarcodeGenerator.modernQr({
126
143
  data: 'https://example.com',
127
144
  size: 300,
128
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
129
157
  foregroundColor: [0, 0, 0],
130
158
  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
159
+
160
+ // Error correction (H recommended for logos)
161
+ errorCorrectionLevel: 'H',
137
162
  });
138
163
 
139
164
  // Save to file
140
- await qrCode.saveToFile('qr-code-with-logo.png');
165
+ await qrCode.saveToFile('qr-code.png');
141
166
 
142
167
  // Get as data URI
143
168
  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
169
  ```
174
170
 
175
- ### QR Code Builder (Advanced)
171
+ ### QR Code Builder Pattern
176
172
 
177
173
  ```javascript
178
174
  const { QrCodeBuilder } = require('isahaq-barcode');
@@ -190,83 +186,115 @@ const qrCode = QrCodeBuilder.create()
190
186
  .format('png')
191
187
  .build();
192
188
 
193
- // Save to file
194
189
  await qrCode.saveToFile('qr-code.png');
190
+ ```
195
191
 
196
- // Get data URI
197
- const dataUri = await qrCode.getDataUri();
198
- console.log(`<img src="${dataUri}" alt="QR Code">`);
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
+ });
199
211
  ```
200
212
 
201
- ## ๐ŸŽฏ Express.js Integration
213
+ ### Data Validation
202
214
 
203
- ### Basic Express.js Usage
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
204
232
 
205
233
  ```javascript
206
- const express = require('express')
207
- const BarcodeGenerator = require('isahaq-barcode')
234
+ const express = require('express');
235
+ const BarcodeGenerator = require('isahaq-barcode');
208
236
 
209
- const app = express()
237
+ const app = express();
210
238
 
211
- // Generate barcode endpoint
239
+ // Barcode endpoint
212
240
  app.get('/barcode/:data', (req, res) => {
213
- const { data } = req.params
214
- const { type = 'code128', format = 'png' } = req.query
241
+ const { data } = req.params;
242
+ const { type = 'code128', format = 'png' } = req.query;
215
243
 
216
244
  try {
217
- let result
245
+ let result, contentType;
246
+
218
247
  switch (format) {
219
248
  case 'png':
220
- result = BarcodeGenerator.png(data, type)
221
- res.set('Content-Type', 'image/png')
222
- break
249
+ result = BarcodeGenerator.png(data, type);
250
+ contentType = 'image/png';
251
+ break;
223
252
  case 'svg':
224
- result = BarcodeGenerator.svg(data, type)
225
- res.set('Content-Type', 'image/svg+xml')
226
- break
253
+ result = BarcodeGenerator.svg(data, type);
254
+ contentType = 'image/svg+xml';
255
+ break;
227
256
  case 'html':
228
- result = BarcodeGenerator.html(data, type)
229
- res.set('Content-Type', 'text/html')
230
- break
257
+ result = BarcodeGenerator.html(data, type);
258
+ contentType = 'text/html';
259
+ break;
231
260
  default:
232
- throw new Error(`Unsupported format: ${format}`)
261
+ return res.status(400).json({ error: 'Invalid format' });
233
262
  }
234
263
 
235
- res.send(result)
264
+ res.set('Content-Type', contentType);
265
+ res.send(result);
236
266
  } catch (error) {
237
- res.status(400).json({ error: error.message })
267
+ res.status(400).json({ error: error.message });
238
268
  }
239
- })
269
+ });
240
270
 
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
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;
245
275
 
246
276
  try {
247
- const qrOptions = {
277
+ const qrCode = BarcodeGenerator.modernQr({
248
278
  data: decodeURIComponent(data),
249
279
  size: parseInt(size),
250
280
  logoPath: logo,
251
- label: label
252
- }
253
-
254
- const qrCode = BarcodeGenerator.modernQr(qrOptions)
255
- const result = await qrCode.generate()
281
+ label: label,
282
+ });
256
283
 
257
- res.set('Content-Type', 'image/png')
258
- res.send(result)
284
+ const result = await qrCode.generate();
285
+ res.set('Content-Type', 'image/png');
286
+ res.send(result);
259
287
  } catch (error) {
260
- res.status(400).json({ error: error.message })
288
+ res.status(400).json({ error: error.message });
261
289
  }
262
- })
290
+ });
263
291
 
264
292
  app.listen(3000, () => {
265
- console.log('Server running on port 3000')
266
- })
293
+ console.log('๐Ÿš€ Barcode server running on port 3000');
294
+ });
267
295
  ```
268
296
 
269
- ### Express.js Middleware
297
+ ### Middleware Pattern
270
298
 
271
299
  ```javascript
272
300
  const express = require('express');
@@ -294,16 +322,16 @@ app.use('/api/barcode', (req, res, next) => {
294
322
  throw new Error(`Unsupported format: ${format}`);
295
323
  }
296
324
  } catch (error) {
297
- throw new Error(`Barcode generation failed: ${error.message}`);
325
+ throw new Error(`Generation failed: ${error.message}`);
298
326
  }
299
327
  };
300
328
  next();
301
329
  });
302
330
 
303
- // Use the middleware
331
+ // Route using middleware
304
332
  app.get('/api/barcode/:data', (req, res) => {
305
333
  const { data } = req.params;
306
- const { type, format, width, height } = req.query;
334
+ const { type, format = 'png', width, height } = req.query;
307
335
 
308
336
  const options = {};
309
337
  if (width) options.width = parseInt(width);
@@ -311,240 +339,258 @@ app.get('/api/barcode/:data', (req, res) => {
311
339
 
312
340
  try {
313
341
  const result = req.generateBarcode(data, type, format, options);
314
- res.set('Content-Type', getMimeType(format));
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');
315
349
  res.send(result);
316
350
  } catch (error) {
317
351
  res.status(400).json({ error: error.message });
318
352
  }
319
353
  });
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
354
  ```
330
355
 
331
- ## ๐Ÿ–ฅ๏ธ CLI Usage
332
-
333
- ### Install CLI globally
356
+ ---
334
357
 
335
- ```bash
336
- npm install -g isahaq-barcode
337
- ```
358
+ ## ๐Ÿ–ฅ๏ธ CLI Usage
338
359
 
339
- ### Generate Barcode
360
+ ### Generate Barcodes
340
361
 
341
362
  ```bash
342
- # Generate PNG barcode
363
+ # Basic PNG barcode
343
364
  barcode-generate barcode -d "1234567890" -t code128 -f png -o barcode.png
344
365
 
345
- # Generate SVG barcode
346
- barcode-generate barcode -d "1234567890" -t ean13 -f svg -o barcode.svg
366
+ # SVG with custom dimensions
367
+ barcode-generate barcode -d "1234567890" -t ean13 -f svg -w 3 -h 150 -o barcode.svg
347
368
 
348
- # Generate with custom options
349
- barcode-generate barcode -d "1234567890" -t code128 -f png -w 3 -h 150 --foreground "#FF0000" --background "#FFFFFF"
369
+ # Custom colors
370
+ barcode-generate barcode -d "1234567890" -t code128 \
371
+ --foreground "#FF0000" --background "#FFFFFF" -o red-barcode.png
350
372
  ```
351
373
 
352
- ### Generate QR Code
374
+ ### Generate QR Codes
353
375
 
354
376
  ```bash
355
- # Generate QR code
356
- barcode-generate qr -d "https://example.com" -s 300 -f png -o qr.png
377
+ # Basic QR code
378
+ barcode-generate qr -d "https://example.com" -s 300 -o qr.png
357
379
 
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
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
360
383
 
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
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
363
387
  ```
364
388
 
365
- ### Batch Generation
389
+ ### Batch Operations
366
390
 
367
391
  ```bash
368
- # Create batch file (batch.json)
369
- echo '[
392
+ # Create batch configuration file
393
+ cat > batch.json << EOF
394
+ [
370
395
  {"data": "1234567890", "type": "code128", "format": "png"},
371
396
  {"data": "9876543210", "type": "code39", "format": "svg"},
372
397
  {"data": "https://example.com", "type": "qrcode", "format": "png"}
373
- ]' > batch.json
398
+ ]
399
+ EOF
374
400
 
375
401
  # Generate batch
376
402
  barcode-generate batch -i batch.json -o ./output
377
403
  ```
378
404
 
379
- ### List Supported Types and Formats
405
+ ### Utility Commands
380
406
 
381
407
  ```bash
382
- # List barcode types
408
+ # List supported barcode types
383
409
  barcode-generate types
384
410
 
385
411
  # List output formats
386
412
  barcode-generate formats
387
413
 
388
- # Validate data
414
+ # Validate data for specific type
389
415
  barcode-generate validate -d "1234567890" -t code128
390
416
  ```
391
417
 
392
- ## ๐Ÿ“Š Advanced Features
418
+ ---
393
419
 
394
- ### Batch Generation
420
+ ## ๐Ÿ“š API Reference
421
+
422
+ ### BarcodeGenerator (Static Methods)
423
+
424
+ #### Generation Methods
395
425
 
396
426
  ```javascript
397
- const BarcodeGenerator = require('isahaq-barcode');
427
+ BarcodeGenerator.png(data, type, options?)
428
+ // Returns: Buffer
398
429
 
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
- ];
430
+ BarcodeGenerator.svg(data, type, options?)
431
+ // Returns: String
404
432
 
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
- });
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
413
441
  ```
414
442
 
415
- ### Validation
443
+ #### Utility Methods
416
444
 
417
445
  ```javascript
418
- const BarcodeGenerator = require('isahaq-barcode');
446
+ BarcodeGenerator.validate(data, type);
447
+ // Returns: { valid: boolean, error?: string, length?: number, charset?: string }
419
448
 
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
- }
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>
429
460
  ```
430
461
 
431
- ### Custom Renderer Options
462
+ ### Options Object
432
463
 
433
464
  ```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,
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
448
484
  marginBottom: 10,
449
485
  marginLeft: 10,
450
- marginRight: 10,
451
- };
452
-
453
- const barcode = BarcodeGenerator.png('1234567890', 'code128', options);
486
+ marginRight: 10
487
+ }
454
488
  ```
455
489
 
456
- ### Available Watermark Positions
490
+ ### QrCodeBuilder Methods
457
491
 
458
492
  ```javascript
459
- const BarcodeGenerator = require('isahaq-barcode');
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
+ ```
460
513
 
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']
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');
464
526
  ```
465
527
 
528
+ ---
529
+
466
530
  ## ๐Ÿงช Testing
467
531
 
468
532
  ```bash
469
- # Run tests
533
+ # Run all tests
470
534
  npm test
471
535
 
472
- # Run tests with coverage
536
+ # Run with coverage report
473
537
  npm run test:coverage
474
538
 
475
- # Run tests in watch mode
539
+ # Watch mode for development
476
540
  npm run test:watch
477
541
  ```
478
542
 
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
543
+ ---
517
544
 
518
545
  ## ๐Ÿค Contributing
519
546
 
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
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
+ ---
525
562
 
526
563
  ## ๐Ÿ“„ License
527
564
 
528
565
  This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
529
566
 
567
+ ---
568
+
530
569
  ## ๐Ÿ™ Acknowledgments
531
570
 
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
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
+ ---
536
579
 
537
580
  ## ๐Ÿ“ž Support
538
581
 
539
- If you have any questions or need help, please:
582
+ Need help? Here's how to get support:
540
583
 
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)
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)
544
587
 
545
588
  ---
546
589
 
590
+ <div align="center">
591
+
547
592
  **Made with โค๏ธ by [Isahaq](https://github.com/isahaq1)**
548
- # npm-barcodegeneratop
549
-
550
-
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>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isahaq-barcode",
3
- "version": "1.1.0",
3
+ "version": "1.2.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
  "bin": {