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/eslint.config.js
CHANGED
|
@@ -1,68 +1,66 @@
|
|
|
1
|
-
module.exports = [
|
|
2
|
-
{
|
|
3
|
-
files: ['**/*.js'],
|
|
4
|
-
languageOptions: {
|
|
5
|
-
ecmaVersion: 2022,
|
|
6
|
-
sourceType: 'module',
|
|
7
|
-
globals: {
|
|
8
|
-
console: 'readonly',
|
|
9
|
-
process: 'readonly',
|
|
10
|
-
Buffer: 'readonly',
|
|
11
|
-
__dirname: 'readonly',
|
|
12
|
-
__filename: 'readonly',
|
|
13
|
-
global: 'readonly',
|
|
14
|
-
module: 'readonly',
|
|
15
|
-
require: 'readonly',
|
|
16
|
-
exports: 'readonly',
|
|
17
|
-
document: 'readonly'
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
'
|
|
25
|
-
'no-
|
|
26
|
-
'no-
|
|
27
|
-
'no-
|
|
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
|
-
'no-unused-vars': 'warn',
|
|
62
|
-
'no-console': 'off',
|
|
63
|
-
'no-undef': 'error',
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
];
|
|
1
|
+
module.exports = [
|
|
2
|
+
{
|
|
3
|
+
files: ['**/*.js'],
|
|
4
|
+
languageOptions: {
|
|
5
|
+
ecmaVersion: 2022,
|
|
6
|
+
sourceType: 'module',
|
|
7
|
+
globals: {
|
|
8
|
+
console: 'readonly',
|
|
9
|
+
process: 'readonly',
|
|
10
|
+
Buffer: 'readonly',
|
|
11
|
+
__dirname: 'readonly',
|
|
12
|
+
__filename: 'readonly',
|
|
13
|
+
global: 'readonly',
|
|
14
|
+
module: 'readonly',
|
|
15
|
+
require: 'readonly',
|
|
16
|
+
exports: 'readonly',
|
|
17
|
+
document: 'readonly',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
plugins: {
|
|
21
|
+
prettier: require('eslint-plugin-prettier'),
|
|
22
|
+
},
|
|
23
|
+
rules: {
|
|
24
|
+
'prettier/prettier': 'error',
|
|
25
|
+
'no-unused-vars': 'warn',
|
|
26
|
+
'no-console': 'off',
|
|
27
|
+
'no-undef': 'error',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
files: ['tests/**/*.js', '**/*.test.js'],
|
|
32
|
+
languageOptions: {
|
|
33
|
+
ecmaVersion: 2022,
|
|
34
|
+
sourceType: 'module',
|
|
35
|
+
globals: {
|
|
36
|
+
console: 'readonly',
|
|
37
|
+
process: 'readonly',
|
|
38
|
+
Buffer: 'readonly',
|
|
39
|
+
__dirname: 'readonly',
|
|
40
|
+
__filename: 'readonly',
|
|
41
|
+
global: 'readonly',
|
|
42
|
+
module: 'readonly',
|
|
43
|
+
require: 'readonly',
|
|
44
|
+
exports: 'readonly',
|
|
45
|
+
describe: 'readonly',
|
|
46
|
+
test: 'readonly',
|
|
47
|
+
it: 'readonly',
|
|
48
|
+
expect: 'readonly',
|
|
49
|
+
beforeEach: 'readonly',
|
|
50
|
+
afterEach: 'readonly',
|
|
51
|
+
beforeAll: 'readonly',
|
|
52
|
+
afterAll: 'readonly',
|
|
53
|
+
jest: 'readonly',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
plugins: {
|
|
57
|
+
prettier: require('eslint-plugin-prettier'),
|
|
58
|
+
},
|
|
59
|
+
rules: {
|
|
60
|
+
'prettier/prettier': 'error',
|
|
61
|
+
'no-unused-vars': 'warn',
|
|
62
|
+
'no-console': 'off',
|
|
63
|
+
'no-undef': 'error',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
];
|
package/examples/basic-usage.js
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Basic usage examples for Isahaq Barcode Generator
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const BarcodeGenerator = require('../index');
|
|
6
|
-
|
|
7
|
-
async function basicExamples() {
|
|
8
|
-
console.log('🚀 Basic Barcode Generation Examples\n');
|
|
9
|
-
|
|
10
|
-
// 1. Generate PNG barcode
|
|
11
|
-
console.log('1. Generating PNG barcode...');
|
|
12
|
-
const pngBuffer = BarcodeGenerator.png('1234567890', 'code128');
|
|
13
|
-
console.log(` PNG buffer size: ${pngBuffer.length} bytes`);
|
|
14
|
-
|
|
15
|
-
// 2. Generate SVG barcode
|
|
16
|
-
console.log('2. Generating SVG barcode...');
|
|
17
|
-
const svgString = BarcodeGenerator.svg('1234567890', 'ean13');
|
|
18
|
-
console.log(` SVG length: ${svgString.length} characters`);
|
|
19
|
-
|
|
20
|
-
// 3. Generate HTML barcode
|
|
21
|
-
console.log('3. Generating HTML barcode...');
|
|
22
|
-
const htmlString = BarcodeGenerator.html('1234567890', 'code39');
|
|
23
|
-
console.log(` HTML length: ${htmlString.length} characters`);
|
|
24
|
-
|
|
25
|
-
// 4. Generate PDF barcode
|
|
26
|
-
console.log('4. Generating PDF barcode...');
|
|
27
|
-
const pdfBuffer = await BarcodeGenerator.pdf('1234567890', 'code128');
|
|
28
|
-
console.log(` PDF buffer size: ${pdfBuffer.length} bytes`);
|
|
29
|
-
|
|
30
|
-
// 5. Generate QR code
|
|
31
|
-
console.log('5. Generating QR code...');
|
|
32
|
-
const qrCode = BarcodeGenerator.modernQr({
|
|
33
|
-
data: 'https://example.com',
|
|
34
|
-
size: 300,
|
|
35
|
-
margin: 10,
|
|
36
|
-
});
|
|
37
|
-
const qrBuffer = await qrCode.generate();
|
|
38
|
-
console.log(` QR code buffer size: ${qrBuffer.length} bytes`);
|
|
39
|
-
|
|
40
|
-
// 6. Generate QR code with logo
|
|
41
|
-
console.log('6. Generating QR code with logo...');
|
|
42
|
-
const qrWithLogo = BarcodeGenerator.modernQr({
|
|
43
|
-
data: 'https://example.com',
|
|
44
|
-
size: 300,
|
|
45
|
-
logoPath: 'path/to/logo.png',
|
|
46
|
-
logoSize: 60,
|
|
47
|
-
label: 'Scan me!',
|
|
48
|
-
});
|
|
49
|
-
const qrWithLogoBuffer = await qrWithLogo.generate();
|
|
50
|
-
console.log(
|
|
51
|
-
` QR code with logo buffer size: ${qrWithLogoBuffer.length} bytes`
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
console.log('\n✅ All examples completed successfully!');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Run examples
|
|
58
|
-
basicExamples().catch(console.error);
|
|
1
|
+
/**
|
|
2
|
+
* Basic usage examples for Isahaq Barcode Generator
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const BarcodeGenerator = require('../index');
|
|
6
|
+
|
|
7
|
+
async function basicExamples() {
|
|
8
|
+
console.log('🚀 Basic Barcode Generation Examples\n');
|
|
9
|
+
|
|
10
|
+
// 1. Generate PNG barcode
|
|
11
|
+
console.log('1. Generating PNG barcode...');
|
|
12
|
+
const pngBuffer = BarcodeGenerator.png('1234567890', 'code128');
|
|
13
|
+
console.log(` PNG buffer size: ${pngBuffer.length} bytes`);
|
|
14
|
+
|
|
15
|
+
// 2. Generate SVG barcode
|
|
16
|
+
console.log('2. Generating SVG barcode...');
|
|
17
|
+
const svgString = BarcodeGenerator.svg('1234567890', 'ean13');
|
|
18
|
+
console.log(` SVG length: ${svgString.length} characters`);
|
|
19
|
+
|
|
20
|
+
// 3. Generate HTML barcode
|
|
21
|
+
console.log('3. Generating HTML barcode...');
|
|
22
|
+
const htmlString = BarcodeGenerator.html('1234567890', 'code39');
|
|
23
|
+
console.log(` HTML length: ${htmlString.length} characters`);
|
|
24
|
+
|
|
25
|
+
// 4. Generate PDF barcode
|
|
26
|
+
console.log('4. Generating PDF barcode...');
|
|
27
|
+
const pdfBuffer = await BarcodeGenerator.pdf('1234567890', 'code128');
|
|
28
|
+
console.log(` PDF buffer size: ${pdfBuffer.length} bytes`);
|
|
29
|
+
|
|
30
|
+
// 5. Generate QR code
|
|
31
|
+
console.log('5. Generating QR code...');
|
|
32
|
+
const qrCode = BarcodeGenerator.modernQr({
|
|
33
|
+
data: 'https://example.com',
|
|
34
|
+
size: 300,
|
|
35
|
+
margin: 10,
|
|
36
|
+
});
|
|
37
|
+
const qrBuffer = await qrCode.generate();
|
|
38
|
+
console.log(` QR code buffer size: ${qrBuffer.length} bytes`);
|
|
39
|
+
|
|
40
|
+
// 6. Generate QR code with logo
|
|
41
|
+
console.log('6. Generating QR code with logo...');
|
|
42
|
+
const qrWithLogo = BarcodeGenerator.modernQr({
|
|
43
|
+
data: 'https://example.com',
|
|
44
|
+
size: 300,
|
|
45
|
+
logoPath: 'path/to/logo.png',
|
|
46
|
+
logoSize: 60,
|
|
47
|
+
label: 'Scan me!',
|
|
48
|
+
});
|
|
49
|
+
const qrWithLogoBuffer = await qrWithLogo.generate();
|
|
50
|
+
console.log(
|
|
51
|
+
` QR code with logo buffer size: ${qrWithLogoBuffer.length} bytes`
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
console.log('\n✅ All examples completed successfully!');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Run examples
|
|
58
|
+
basicExamples().catch(console.error);
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"data": "1234567890",
|
|
4
|
-
"type": "code128",
|
|
5
|
-
"format": "png",
|
|
6
|
-
"options": {
|
|
7
|
-
"width": 3,
|
|
8
|
-
"height": 150,
|
|
9
|
-
"displayValue": true
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"data": "9876543210",
|
|
14
|
-
"type": "code39",
|
|
15
|
-
"format": "svg",
|
|
16
|
-
"options": {
|
|
17
|
-
"width": 2,
|
|
18
|
-
"height": 100,
|
|
19
|
-
"displayValue": false
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
"data": "1234567890123",
|
|
24
|
-
"type": "ean13",
|
|
25
|
-
"format": "png",
|
|
26
|
-
"options": {
|
|
27
|
-
"width": 2,
|
|
28
|
-
"height": 120,
|
|
29
|
-
"displayValue": true
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"data": "https://example.com",
|
|
34
|
-
"type": "qrcode",
|
|
35
|
-
"format": "png",
|
|
36
|
-
"options": {
|
|
37
|
-
"size": 300,
|
|
38
|
-
"margin": 10,
|
|
39
|
-
"logoPath": "path/to/logo.png",
|
|
40
|
-
"logoSize": 60,
|
|
41
|
-
"label": "Scan me!"
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
"data": "https://github.com",
|
|
46
|
-
"type": "qrcode",
|
|
47
|
-
"format": "png",
|
|
48
|
-
"options": {
|
|
49
|
-
"size": 400,
|
|
50
|
-
"margin": 15,
|
|
51
|
-
"watermark": "GitHub",
|
|
52
|
-
"watermarkPosition": "center",
|
|
53
|
-
"errorCorrectionLevel": "H"
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
]
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"data": "1234567890",
|
|
4
|
+
"type": "code128",
|
|
5
|
+
"format": "png",
|
|
6
|
+
"options": {
|
|
7
|
+
"width": 3,
|
|
8
|
+
"height": 150,
|
|
9
|
+
"displayValue": true
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"data": "9876543210",
|
|
14
|
+
"type": "code39",
|
|
15
|
+
"format": "svg",
|
|
16
|
+
"options": {
|
|
17
|
+
"width": 2,
|
|
18
|
+
"height": 100,
|
|
19
|
+
"displayValue": false
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"data": "1234567890123",
|
|
24
|
+
"type": "ean13",
|
|
25
|
+
"format": "png",
|
|
26
|
+
"options": {
|
|
27
|
+
"width": 2,
|
|
28
|
+
"height": 120,
|
|
29
|
+
"displayValue": true
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"data": "https://example.com",
|
|
34
|
+
"type": "qrcode",
|
|
35
|
+
"format": "png",
|
|
36
|
+
"options": {
|
|
37
|
+
"size": 300,
|
|
38
|
+
"margin": 10,
|
|
39
|
+
"logoPath": "path/to/logo.png",
|
|
40
|
+
"logoSize": 60,
|
|
41
|
+
"label": "Scan me!"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"data": "https://github.com",
|
|
46
|
+
"type": "qrcode",
|
|
47
|
+
"format": "png",
|
|
48
|
+
"options": {
|
|
49
|
+
"size": 400,
|
|
50
|
+
"margin": 15,
|
|
51
|
+
"watermark": "GitHub",
|
|
52
|
+
"watermarkPosition": "center",
|
|
53
|
+
"errorCorrectionLevel": "H"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
]
|