@qr-styled/node 1.0.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/LICENSE +21 -0
- package/README.md +691 -0
- package/dist/cli/index.d.ts +29 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +126 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/QRGenerator.d.ts +53 -0
- package/dist/lib/QRGenerator.d.ts.map +1 -0
- package/dist/lib/QRGenerator.js +150 -0
- package/dist/lib/QRGenerator.js.map +1 -0
- package/dist/lib/QRGenerator.new-features.test.d.ts +2 -0
- package/dist/lib/QRGenerator.new-features.test.d.ts.map +1 -0
- package/dist/lib/QRGenerator.new-features.test.js +235 -0
- package/dist/lib/QRGenerator.new-features.test.js.map +1 -0
- package/dist/lib/QRGenerator.test.d.ts +2 -0
- package/dist/lib/QRGenerator.test.d.ts.map +1 -0
- package/dist/lib/QRGenerator.test.js +39 -0
- package/dist/lib/QRGenerator.test.js.map +1 -0
- package/dist/lib/renderers/BackgroundRenderer.d.ts +23 -0
- package/dist/lib/renderers/BackgroundRenderer.d.ts.map +1 -0
- package/dist/lib/renderers/BackgroundRenderer.js +48 -0
- package/dist/lib/renderers/BackgroundRenderer.js.map +1 -0
- package/dist/lib/renderers/GradientRenderer.d.ts +19 -0
- package/dist/lib/renderers/GradientRenderer.d.ts.map +1 -0
- package/dist/lib/renderers/GradientRenderer.js +44 -0
- package/dist/lib/renderers/GradientRenderer.js.map +1 -0
- package/dist/lib/renderers/LogoRenderer.d.ts +23 -0
- package/dist/lib/renderers/LogoRenderer.d.ts.map +1 -0
- package/dist/lib/renderers/LogoRenderer.js +72 -0
- package/dist/lib/renderers/LogoRenderer.js.map +1 -0
- package/dist/lib/renderers/ModuleRenderer.d.ts +45 -0
- package/dist/lib/renderers/ModuleRenderer.d.ts.map +1 -0
- package/dist/lib/renderers/ModuleRenderer.js +162 -0
- package/dist/lib/renderers/ModuleRenderer.js.map +1 -0
- package/dist/lib/renderers/SVGRenderer.d.ts +23 -0
- package/dist/lib/renderers/SVGRenderer.d.ts.map +1 -0
- package/dist/lib/renderers/SVGRenderer.js +74 -0
- package/dist/lib/renderers/SVGRenderer.js.map +1 -0
- package/dist/lib/utils/formatters.d.ts +26 -0
- package/dist/lib/utils/formatters.d.ts.map +1 -0
- package/dist/lib/utils/formatters.js +107 -0
- package/dist/lib/utils/formatters.js.map +1 -0
- package/dist/lib/utils/formatters.test.d.ts +2 -0
- package/dist/lib/utils/formatters.test.d.ts.map +1 -0
- package/dist/lib/utils/formatters.test.js +190 -0
- package/dist/lib/utils/formatters.test.js.map +1 -0
- package/dist/lib/utils/types.d.ts +120 -0
- package/dist/lib/utils/types.d.ts.map +1 -0
- package/dist/lib/utils/types.js +35 -0
- package/dist/lib/utils/types.js.map +1 -0
- package/dist/lib/utils/validators.d.ts +11 -0
- package/dist/lib/utils/validators.d.ts.map +1 -0
- package/dist/lib/utils/validators.js +127 -0
- package/dist/lib/utils/validators.js.map +1 -0
- package/dist/lib/utils/validators.test.d.ts +2 -0
- package/dist/lib/utils/validators.test.d.ts.map +1 -0
- package/dist/lib/utils/validators.test.js +62 -0
- package/dist/lib/utils/validators.test.js.map +1 -0
- package/package.json +87 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Luis Manuel Yerena Sosa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,691 @@
|
|
|
1
|
+
# ๐จ @qr-styled/node
|
|
2
|
+
|
|
3
|
+
**Professional QR Code Generator for Node.js**
|
|
4
|
+
|
|
5
|
+
A powerful Node.js/TypeScript library for generating QR codes with advanced styling options including gradients, rounded modules, and logo support.
|
|
6
|
+
|
|
7
|
+
> ๐ก **Looking for browser support?** Check out [@qr-styled/browser](https://github.com/Luisma92/qr-styled-browser) for frontend/React/Vue applications.
|
|
8
|
+
|
|
9
|
+
[](https://opensource.org/licenses/MIT)
|
|
10
|
+
[](https://nodejs.org)
|
|
11
|
+
[](https://www.typescriptlang.org/)
|
|
12
|
+
|
|
13
|
+
## โจ Features
|
|
14
|
+
|
|
15
|
+
- ๐จ **Customizable Styles**: Solid colors or multi-color gradients
|
|
16
|
+
- ๐ท **Rounded Modules**: Smooth, modern edges with radius control
|
|
17
|
+
- ๐ผ๏ธ **Logo Support**: Add logos with circular or square backgrounds
|
|
18
|
+
- ๏ฟฝ **Specialized QR Types**: vCard, WiFi, Email, SMS, Geo location
|
|
19
|
+
- ๐ **SVG Export**: Vector format for perfect scalability
|
|
20
|
+
- ๐๏ธ **Eye Customization**: Custom colors and shapes for finder patterns
|
|
21
|
+
- ๐ **Proper Margins**: Standard QR quiet zone support
|
|
22
|
+
- ๐ฆ **Multiple Output Formats**: PNG, JPEG, SVG, Buffer, Data URL, or Canvas
|
|
23
|
+
- ๐ ๏ธ **CLI & API**: Use from command line or programmatically
|
|
24
|
+
- โ
**Built-in Validation**: Options validated automatically
|
|
25
|
+
- ๐ฏ **Full TypeScript Support**: Complete type definitions included
|
|
26
|
+
- ๐ง **Modular Architecture**: Clean, maintainable code
|
|
27
|
+
|
|
28
|
+
## ๏ฟฝ๏ธ Visual Examples
|
|
29
|
+
|
|
30
|
+
### Advanced Features
|
|
31
|
+
|
|
32
|
+
<table>
|
|
33
|
+
<tr>
|
|
34
|
+
<td align="center" valign="top">
|
|
35
|
+
<img src="docs/images/vcard-contact.png" width="180" alt="vCard Contact QR"/>
|
|
36
|
+
<br/>
|
|
37
|
+
<b>vCard Contact</b>
|
|
38
|
+
<br/>
|
|
39
|
+
<sub>Purple gradient with custom eyes</sub>
|
|
40
|
+
</td>
|
|
41
|
+
<td align="center" valign="top">
|
|
42
|
+
<img src="docs/images/wifi-network.png" width="180" alt="WiFi Network QR"/>
|
|
43
|
+
<br/>
|
|
44
|
+
<b>WiFi Network</b>
|
|
45
|
+
<br/>
|
|
46
|
+
<sub>Green gradient with rounded modules</sub>
|
|
47
|
+
</td>
|
|
48
|
+
<td align="center" valign="top">
|
|
49
|
+
<img src="docs/images/email-contact.png" width="180" alt="Email Contact QR"/>
|
|
50
|
+
<br/>
|
|
51
|
+
<b>Email Contact</b>
|
|
52
|
+
<br/>
|
|
53
|
+
<sub>Pink gradient with eye customization</sub>
|
|
54
|
+
</td>
|
|
55
|
+
<td align="center" valign="top">
|
|
56
|
+
<img src="docs/images/custom-eyes.png" width="180" alt="Custom Eyes QR"/>
|
|
57
|
+
<br/>
|
|
58
|
+
<b>Custom Eyes</b>
|
|
59
|
+
<br/>
|
|
60
|
+
<sub>Red eye accents (square modules)</sub>
|
|
61
|
+
</td>
|
|
62
|
+
</tr>
|
|
63
|
+
</table>
|
|
64
|
+
|
|
65
|
+
### Basic Styles
|
|
66
|
+
|
|
67
|
+
<table>
|
|
68
|
+
<tr>
|
|
69
|
+
<td align="center" valign="top">
|
|
70
|
+
<img src="docs/images/basic-classic.png" width="150" alt="Classic Black & White QR"/>
|
|
71
|
+
<br/>
|
|
72
|
+
<b>Classic</b>
|
|
73
|
+
<br/>
|
|
74
|
+
<sub>Traditional black & white</sub>
|
|
75
|
+
</td>
|
|
76
|
+
<td align="center" valign="top">
|
|
77
|
+
<img src="docs/images/basic-blue.png" width="150" alt="Professional Blue QR"/>
|
|
78
|
+
<br/>
|
|
79
|
+
<b>Professional</b>
|
|
80
|
+
<br/>
|
|
81
|
+
<sub>Blue rounded design</sub>
|
|
82
|
+
</td>
|
|
83
|
+
<td align="center" valign="top">
|
|
84
|
+
<img src="docs/images/basic-green.png" width="150" alt="Eco Green QR"/>
|
|
85
|
+
<br/>
|
|
86
|
+
<b>Eco</b>
|
|
87
|
+
<br/>
|
|
88
|
+
<sub>Green with custom eyes</sub>
|
|
89
|
+
</td>
|
|
90
|
+
<td align="center" valign="top">
|
|
91
|
+
<img src="docs/images/basic-red.png" width="150" alt="Alert Red QR"/>
|
|
92
|
+
<br/>
|
|
93
|
+
<b>Alert</b>
|
|
94
|
+
<br/>
|
|
95
|
+
<sub>Red attention-grabbing</sub>
|
|
96
|
+
</td>
|
|
97
|
+
<td align="center" valign="top">
|
|
98
|
+
<img src="docs/images/basic-purple.png" width="150" alt="Creative Purple QR"/>
|
|
99
|
+
<br/>
|
|
100
|
+
<b>Creative</b>
|
|
101
|
+
<br/>
|
|
102
|
+
<sub>Purple artistic</sub>
|
|
103
|
+
</td>
|
|
104
|
+
</tr>
|
|
105
|
+
</table>
|
|
106
|
+
|
|
107
|
+
### With Logos
|
|
108
|
+
|
|
109
|
+
<table>
|
|
110
|
+
<tr>
|
|
111
|
+
<td align="center" valign="top">
|
|
112
|
+
<img src="docs/images/logo-corporate.png" width="160" alt="Corporate QR with Logo"/>
|
|
113
|
+
<br/>
|
|
114
|
+
<b>Corporate</b>
|
|
115
|
+
<br/>
|
|
116
|
+
<sub>Circle logo, professional blue</sub>
|
|
117
|
+
</td>
|
|
118
|
+
<td align="center" valign="top">
|
|
119
|
+
<img src="docs/images/logo-eco.png" width="160" alt="Eco Brand QR with Logo"/>
|
|
120
|
+
<br/>
|
|
121
|
+
<b>Eco Brand</b>
|
|
122
|
+
<br/>
|
|
123
|
+
<sub>Square logo, green gradient</sub>
|
|
124
|
+
</td>
|
|
125
|
+
<td align="center" valign="top">
|
|
126
|
+
<img src="docs/images/logo-tech.png" width="160" alt="Tech Startup QR with Logo"/>
|
|
127
|
+
<br/>
|
|
128
|
+
<b>Tech Startup</b>
|
|
129
|
+
<br/>
|
|
130
|
+
<sub>Circle logo, purple gradient</sub>
|
|
131
|
+
</td>
|
|
132
|
+
<td align="center" valign="top">
|
|
133
|
+
<img src="docs/images/logo-restaurant.png" width="160" alt="Restaurant QR with Logo"/>
|
|
134
|
+
<br/>
|
|
135
|
+
<b>Restaurant</b>
|
|
136
|
+
<br/>
|
|
137
|
+
<sub>Square logo, red gradient</sub>
|
|
138
|
+
</td>
|
|
139
|
+
</tr>
|
|
140
|
+
</table>
|
|
141
|
+
|
|
142
|
+
> ๐ก **Tip**: All examples shown above were generated with this library! Check the [`examples/`](examples/) directory for source code.
|
|
143
|
+
|
|
144
|
+
## ๏ฟฝ๐ฆ Installation
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
npm install @qr-styled/node
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Or for global CLI usage:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
npm install -g @qr-styled/node
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## ๐ Quick Start
|
|
157
|
+
|
|
158
|
+
### CLI Usage
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
# Basic QR code
|
|
162
|
+
qr-styled --url "https://github.com"
|
|
163
|
+
|
|
164
|
+
# QR with gradient
|
|
165
|
+
qr-styled --url "https://github.com" --gradient
|
|
166
|
+
|
|
167
|
+
# QR with logo
|
|
168
|
+
qr-styled --url "https://github.com" --logo ./my-logo.png --out my-qr.png
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Library Usage
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { QRGenerator, generateQRToFile } from '@qr-styled/node';
|
|
175
|
+
|
|
176
|
+
// Basic URL QR code
|
|
177
|
+
const generator = new QRGenerator({
|
|
178
|
+
url: 'https://github.com',
|
|
179
|
+
gradient: true,
|
|
180
|
+
gradientColors: '#667eea,#764ba2'
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
await generator.generateToFile('qr-output.png');
|
|
184
|
+
|
|
185
|
+
// vCard contact QR code
|
|
186
|
+
const vCardGenerator = new QRGenerator({
|
|
187
|
+
type: 'vcard',
|
|
188
|
+
data: {
|
|
189
|
+
firstName: 'John',
|
|
190
|
+
lastName: 'Doe',
|
|
191
|
+
phone: '+1234567890',
|
|
192
|
+
email: 'john@example.com',
|
|
193
|
+
organization: 'Tech Corp'
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
await vCardGenerator.generateToFile('contact-qr.png');
|
|
198
|
+
|
|
199
|
+
// WiFi QR code
|
|
200
|
+
const wifiGenerator = new QRGenerator({
|
|
201
|
+
type: 'wifi',
|
|
202
|
+
data: {
|
|
203
|
+
ssid: 'MyNetwork',
|
|
204
|
+
password: 'SecurePassword123',
|
|
205
|
+
encryption: 'WPA'
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
await wifiGenerator.generateToFile('wifi-qr.png');
|
|
210
|
+
|
|
211
|
+
// SVG export for scalability
|
|
212
|
+
const svgGenerator = new QRGenerator({
|
|
213
|
+
url: 'https://example.com',
|
|
214
|
+
foregroundColor: '#2196F3',
|
|
215
|
+
eyeColor: '#FF5722',
|
|
216
|
+
eyeRadius: 0.4
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const svg = await svgGenerator.generateToSVG();
|
|
220
|
+
await svgGenerator.generateToSVGFile('qr.svg');
|
|
221
|
+
|
|
222
|
+
// Helper function
|
|
223
|
+
await generateQRToFile(
|
|
224
|
+
{
|
|
225
|
+
url: 'https://github.com',
|
|
226
|
+
foregroundColor: '#2d3748'
|
|
227
|
+
},
|
|
228
|
+
'qr-output.png'
|
|
229
|
+
);
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## ๐ Documentation
|
|
233
|
+
|
|
234
|
+
### Configuration Options
|
|
235
|
+
|
|
236
|
+
#### Basic Options
|
|
237
|
+
|
|
238
|
+
| Option | Type | Default | Description |
|
|
239
|
+
| ----------------- | ------------ | ------------ | ------------------------------------------------------ |
|
|
240
|
+
| `url` | `string` | _optional_ | URL or text content |
|
|
241
|
+
| `type` | `QRDataType` | `'text'` | QR data type (url, text, vcard, wifi, email, sms, geo) |
|
|
242
|
+
| `data` | `object` | _optional_ | Structured data for specialized types |
|
|
243
|
+
| `size` | `number` | `600` | Canvas size in pixels |
|
|
244
|
+
| `margin` | `number` | `4` | Quiet zone margin (4 modules standard) |
|
|
245
|
+
| `padding` | `number` | `40` | Canvas padding in pixels |
|
|
246
|
+
| `foregroundColor` | `string` | `'#000000'` | QR code color (hex format) |
|
|
247
|
+
| `color` | `string` | _deprecated_ | Use `foregroundColor` instead |
|
|
248
|
+
| `rounded` | `boolean` | `true` | Use rounded module corners |
|
|
249
|
+
| `moduleRadius` | `number` | `0.35` | Corner radius (0.0 - 0.5) |
|
|
250
|
+
| `cornerRadius` | `number` | `60` | Background corner radius |
|
|
251
|
+
| `backgroundColor` | `string` | `'#ffffff'` | Background color |
|
|
252
|
+
|
|
253
|
+
#### Eye Customization
|
|
254
|
+
|
|
255
|
+
| Option | Type | Default | Description |
|
|
256
|
+
| ----------- | -------- | ------- | --------------------------------- |
|
|
257
|
+
| `eyeColor` | `string` | `''` | Custom eye (finder pattern) color |
|
|
258
|
+
| `eyeRadius` | `number` | `0` | Eye corner radius (0.0 - 0.5) |
|
|
259
|
+
|
|
260
|
+
#### Gradient Options
|
|
261
|
+
|
|
262
|
+
| Option | Type | Default | Description |
|
|
263
|
+
| ---------------- | --------- | ----------------------- | ------------------------ |
|
|
264
|
+
| `gradient` | `boolean` | `false` | Enable gradient |
|
|
265
|
+
| `gradientColors` | `string` | `'#FEDA75,#FA7E1E,...'` | Comma-separated colors |
|
|
266
|
+
| `gradientAngle` | `number` | `45` | Angle in degrees (0-360) |
|
|
267
|
+
|
|
268
|
+
#### Logo Options
|
|
269
|
+
|
|
270
|
+
| Option | Type | Default | Description |
|
|
271
|
+
| --------------------- | -------------------- | ----------- | ------------------------------ |
|
|
272
|
+
| `logo` | `string` | `''` | Logo image path or URL |
|
|
273
|
+
| `logoSize` | `number` | `120` | Logo size in pixels |
|
|
274
|
+
| `logoPadding` | `number` | `10` | Padding around logo |
|
|
275
|
+
| `logoShape` | `'circle'\|'square'` | `'circle'` | Logo background shape |
|
|
276
|
+
| `logoBackgroundColor` | `string` | `'#ffffff'` | Logo background color |
|
|
277
|
+
| `logoRadius` | `number` | `20` | Corner radius for square logos |
|
|
278
|
+
|
|
279
|
+
### Specialized QR Codes
|
|
280
|
+
|
|
281
|
+
#### vCard (Contact Card)
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
{
|
|
285
|
+
type: 'vcard',
|
|
286
|
+
data: {
|
|
287
|
+
firstName: 'John',
|
|
288
|
+
lastName: 'Doe',
|
|
289
|
+
organization: 'Tech Corp',
|
|
290
|
+
title: 'CEO',
|
|
291
|
+
phone: '+1234567890',
|
|
292
|
+
email: 'john@example.com',
|
|
293
|
+
url: 'https://example.com',
|
|
294
|
+
address: '123 Main St',
|
|
295
|
+
city: 'New York',
|
|
296
|
+
state: 'NY',
|
|
297
|
+
zip: '10001',
|
|
298
|
+
country: 'USA'
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
#### WiFi Network
|
|
304
|
+
|
|
305
|
+
```typescript
|
|
306
|
+
{
|
|
307
|
+
type: 'wifi',
|
|
308
|
+
data: {
|
|
309
|
+
ssid: 'MyNetwork',
|
|
310
|
+
password: 'SecurePassword123',
|
|
311
|
+
encryption: 'WPA', // 'WPA' | 'WEP' | 'nopass'
|
|
312
|
+
hidden: false // optional
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
#### Email
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
{
|
|
321
|
+
type: 'email',
|
|
322
|
+
data: {
|
|
323
|
+
email: 'contact@example.com',
|
|
324
|
+
subject: 'Hello', // optional
|
|
325
|
+
body: 'Message text' // optional
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
#### SMS
|
|
331
|
+
|
|
332
|
+
```typescript
|
|
333
|
+
{
|
|
334
|
+
type: 'sms',
|
|
335
|
+
data: {
|
|
336
|
+
phone: '+1234567890',
|
|
337
|
+
message: 'Hello!' // optional
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
#### Geo Location
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
{
|
|
346
|
+
type: 'geo',
|
|
347
|
+
data: {
|
|
348
|
+
latitude: 40.7128,
|
|
349
|
+
longitude: -74.0060
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
| `logoRadius` | `number` | `20` | Corner radius (for square) |
|
|
355
|
+
|
|
356
|
+
### API Reference
|
|
357
|
+
|
|
358
|
+
#### `QRGenerator`
|
|
359
|
+
|
|
360
|
+
Main class for generating QR codes.
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
import { QRGenerator } from '@qr-styled/node';
|
|
364
|
+
|
|
365
|
+
const generator = new QRGenerator(options);
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
##### Methods
|
|
369
|
+
|
|
370
|
+
###### `generate()`
|
|
371
|
+
|
|
372
|
+
Generates QR code and returns the canvas.
|
|
373
|
+
|
|
374
|
+
```typescript
|
|
375
|
+
const canvas = await generator.generate();
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
###### `generateToFile(outputPath)`
|
|
379
|
+
|
|
380
|
+
Generates and saves QR code to file.
|
|
381
|
+
|
|
382
|
+
```typescript
|
|
383
|
+
await generator.generateToFile('output.png');
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
###### `generateToBuffer(format)`
|
|
387
|
+
|
|
388
|
+
Generates and returns a Buffer (useful for APIs/servers).
|
|
389
|
+
|
|
390
|
+
```typescript
|
|
391
|
+
const buffer = await generator.generateToBuffer('png');
|
|
392
|
+
// In Express: res.type('png').send(buffer)
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
###### `generateToDataURL(format)`
|
|
396
|
+
|
|
397
|
+
Generates and returns a Data URL (useful for HTML).
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
const dataURL = await generator.generateToDataURL('png');
|
|
401
|
+
// In HTML: <img src="${dataURL}" />
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
###### `updateOptions(options)`
|
|
405
|
+
|
|
406
|
+
Updates generator options.
|
|
407
|
+
|
|
408
|
+
```typescript
|
|
409
|
+
generator.updateOptions({ gradient: true });
|
|
410
|
+
await generator.generateToFile('updated.png');
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
#### Helper Functions
|
|
414
|
+
|
|
415
|
+
##### `generateQR(options)`
|
|
416
|
+
|
|
417
|
+
Quickly generate a QR code and return the canvas.
|
|
418
|
+
|
|
419
|
+
```typescript
|
|
420
|
+
import { generateQR } from '@qr-styled/node';
|
|
421
|
+
|
|
422
|
+
const canvas = await generateQR({ url: 'https://example.com' });
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
##### `generateQRToFile(options, outputPath)`
|
|
426
|
+
|
|
427
|
+
Generate and save a QR code to file.
|
|
428
|
+
|
|
429
|
+
```typescript
|
|
430
|
+
import { generateQRToFile } from '@qr-styled/node';
|
|
431
|
+
|
|
432
|
+
await generateQRToFile(
|
|
433
|
+
{ url: 'https://example.com', gradient: true },
|
|
434
|
+
'output.png'
|
|
435
|
+
);
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
## ๐ป Usage Examples
|
|
439
|
+
|
|
440
|
+
### Example 1: Instagram Gradient QR
|
|
441
|
+
|
|
442
|
+
```typescript
|
|
443
|
+
const generator = new QRGenerator({
|
|
444
|
+
url: 'https://instagram.com/your-profile',
|
|
445
|
+
gradient: true,
|
|
446
|
+
gradientColors: '#FEDA75,#FA7E1E,#D62976,#962FBF,#4F5BD5',
|
|
447
|
+
gradientAngle: 45,
|
|
448
|
+
rounded: true
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
await generator.generateToFile('instagram-qr.png');
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
### Example 2: Corporate QR with Logo
|
|
455
|
+
|
|
456
|
+
```typescript
|
|
457
|
+
const generator = new QRGenerator({
|
|
458
|
+
url: 'https://your-company.com',
|
|
459
|
+
foregroundColor: '#1a365d',
|
|
460
|
+
logo: './company-logo.png',
|
|
461
|
+
logoShape: 'square',
|
|
462
|
+
logoRadius: 15,
|
|
463
|
+
backgroundColor: '#f7fafc'
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
await generator.generateToFile('company-qr.png');
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
### Example 3: QR for HTTP API
|
|
470
|
+
|
|
471
|
+
```typescript
|
|
472
|
+
import express from 'express';
|
|
473
|
+
import { QRGenerator } from '@qr-styled/node';
|
|
474
|
+
|
|
475
|
+
const app = express();
|
|
476
|
+
|
|
477
|
+
app.get('/qr', async (req, res) => {
|
|
478
|
+
const generator = new QRGenerator({
|
|
479
|
+
url: req.query.url,
|
|
480
|
+
gradient: true,
|
|
481
|
+
gradientColors: '#667eea,#764ba2'
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
const buffer = await generator.generateToBuffer('png');
|
|
485
|
+
res.type('png').send(buffer);
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
app.listen(3000);
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
### Example 4: Dynamic QR in Frontend
|
|
492
|
+
|
|
493
|
+
```typescript
|
|
494
|
+
// In your Node.js server
|
|
495
|
+
app.get('/api/qr-data', async (req, res) => {
|
|
496
|
+
const generator = new QRGenerator({
|
|
497
|
+
url: 'https://example.com',
|
|
498
|
+
gradient: true
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
const dataURL = await generator.generateToDataURL('png');
|
|
502
|
+
res.json({ qrCode: dataURL });
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
// In your frontend (React, Vue, etc.)
|
|
506
|
+
fetch('/api/qr-data')
|
|
507
|
+
.then(res => res.json())
|
|
508
|
+
.then(data => {
|
|
509
|
+
document.getElementById('qr').src = data.qrCode;
|
|
510
|
+
});
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
## ๐ง CLI
|
|
514
|
+
|
|
515
|
+
### Global Installation
|
|
516
|
+
|
|
517
|
+
```bash
|
|
518
|
+
npm install -g @qr-styled/node
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
### Available Commands
|
|
522
|
+
|
|
523
|
+
```bash
|
|
524
|
+
# Available commands
|
|
525
|
+
qr-styled [options]
|
|
526
|
+
qrgen [options] # Short alias
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
### CLI Examples
|
|
530
|
+
|
|
531
|
+
```bash
|
|
532
|
+
# Basic QR
|
|
533
|
+
qr-styled --url "https://github.com"
|
|
534
|
+
|
|
535
|
+
# Custom filename
|
|
536
|
+
qr-styled --url "https://github.com" --out my-code.png
|
|
537
|
+
|
|
538
|
+
# QR with gradient
|
|
539
|
+
qr-styled --url "https://github.com" --gradient --gradientColors "#ff6b6b,#ee5a6f"
|
|
540
|
+
|
|
541
|
+
# QR with logo
|
|
542
|
+
qr-styled --url "https://github.com" --logo ./logo.png --logoShape square
|
|
543
|
+
|
|
544
|
+
# QR with all options
|
|
545
|
+
qr-styled \
|
|
546
|
+
--url "https://github.com" \
|
|
547
|
+
--size 800 \
|
|
548
|
+
--gradient \
|
|
549
|
+
--gradientColors "#667eea,#764ba2" \
|
|
550
|
+
--gradientAngle 90 \
|
|
551
|
+
--logo ./logo.png \
|
|
552
|
+
--logoShape circle \
|
|
553
|
+
--out custom-qr.png
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
### Help
|
|
557
|
+
|
|
558
|
+
```bash
|
|
559
|
+
qr-styled --help
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
## ๐๏ธ Architecture
|
|
563
|
+
|
|
564
|
+
```
|
|
565
|
+
src/
|
|
566
|
+
โโโ index.ts # Main entry point
|
|
567
|
+
โโโ lib/
|
|
568
|
+
โ โโโ QRGenerator.ts # Main class
|
|
569
|
+
โ โโโ renderers/ # Rendering modules
|
|
570
|
+
โ โ โโโ BackgroundRenderer.ts
|
|
571
|
+
โ โ โโโ GradientRenderer.ts
|
|
572
|
+
โ โ โโโ ModuleRenderer.ts
|
|
573
|
+
โ โ โโโ LogoRenderer.ts
|
|
574
|
+
โ โโโ utils/ # Utilities
|
|
575
|
+
โ โโโ types.ts
|
|
576
|
+
โ โโโ validators.ts
|
|
577
|
+
โโโ cli/
|
|
578
|
+
โโโ index.ts # Command line interface
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
### Design Principles
|
|
582
|
+
|
|
583
|
+
- **Separation of Concerns**: Each renderer handles a specific function
|
|
584
|
+
- **Composition over Inheritance**: Renderers are composed in QRGenerator
|
|
585
|
+
- **Input Validation**: All options validated before processing
|
|
586
|
+
- **Flexible API**: Supports multiple output formats
|
|
587
|
+
- **Clean Code**: Complete TypeScript types and documentation
|
|
588
|
+
|
|
589
|
+
## ๐งช Included Examples
|
|
590
|
+
|
|
591
|
+
The project includes complete examples you can run:
|
|
592
|
+
|
|
593
|
+
```bash
|
|
594
|
+
# Basic examples
|
|
595
|
+
npm run example:basic
|
|
596
|
+
|
|
597
|
+
# Programmatic usage examples
|
|
598
|
+
npm run example:programmatic
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
Examples will generate files in `examples/output/` for you to review.
|
|
602
|
+
|
|
603
|
+
## ๐ค Framework Integration
|
|
604
|
+
|
|
605
|
+
### Express.js
|
|
606
|
+
|
|
607
|
+
```typescript
|
|
608
|
+
app.get('/qr/:text', async (req, res) => {
|
|
609
|
+
const generator = new QRGenerator({ url: req.params.text });
|
|
610
|
+
const buffer = await generator.generateToBuffer();
|
|
611
|
+
res.type('png').send(buffer);
|
|
612
|
+
});
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
### Next.js (API Route)
|
|
616
|
+
|
|
617
|
+
```typescript
|
|
618
|
+
// pages/api/qr.ts
|
|
619
|
+
import { QRGenerator } from '@qr-styled/node';
|
|
620
|
+
|
|
621
|
+
export default async function handler(req, res) {
|
|
622
|
+
const { url } = req.query;
|
|
623
|
+
const generator = new QRGenerator({ url });
|
|
624
|
+
const buffer = await generator.generateToBuffer();
|
|
625
|
+
|
|
626
|
+
res.setHeader('Content-Type', 'image/png');
|
|
627
|
+
res.send(buffer);
|
|
628
|
+
}
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
### Fastify
|
|
632
|
+
|
|
633
|
+
```typescript
|
|
634
|
+
fastify.get('/qr', async (request, reply) => {
|
|
635
|
+
const generator = new QRGenerator({ url: request.query.url });
|
|
636
|
+
const buffer = await generator.generateToBuffer();
|
|
637
|
+
|
|
638
|
+
reply.type('image/png').send(buffer);
|
|
639
|
+
});
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
## ๐ ๏ธ Development
|
|
643
|
+
|
|
644
|
+
### Build
|
|
645
|
+
|
|
646
|
+
```bash
|
|
647
|
+
npm run build
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
### Development Mode
|
|
651
|
+
|
|
652
|
+
```bash
|
|
653
|
+
npm run dev -- --url "https://example.com"
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
### Run Examples
|
|
657
|
+
|
|
658
|
+
```bash
|
|
659
|
+
npm run example:basic
|
|
660
|
+
npm run example:programmatic
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
## ๐ License
|
|
664
|
+
|
|
665
|
+
MIT ยฉ Luis Manuel Yerena Sosa
|
|
666
|
+
|
|
667
|
+
## ๐ Contributing
|
|
668
|
+
|
|
669
|
+
Contributions are welcome! Please:
|
|
670
|
+
|
|
671
|
+
1. Fork the project
|
|
672
|
+
2. Create a feature branch (`git checkout -b feature/AmazingFeature`)
|
|
673
|
+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
|
|
674
|
+
4. Push to the branch (`git push origin feature/AmazingFeature`)
|
|
675
|
+
5. Open a Pull Request
|
|
676
|
+
|
|
677
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for more details.
|
|
678
|
+
|
|
679
|
+
## ๐ Report Issues
|
|
680
|
+
|
|
681
|
+
If you find a bug or have a suggestion, please [open an issue](https://github.com/Luisma92/@qr-styled/node/issues).
|
|
682
|
+
|
|
683
|
+
## ๐ Resources
|
|
684
|
+
|
|
685
|
+
- [QRCode Documentation](https://github.com/soldair/node-qrcode)
|
|
686
|
+
- [Canvas API](https://github.com/Automattic/node-canvas)
|
|
687
|
+
- [QR Code Specification](https://www.qrcode.com/en/about/)
|
|
688
|
+
|
|
689
|
+
---
|
|
690
|
+
|
|
691
|
+
**โญ If you find this project useful, consider giving it a star on GitHub!**
|