forked from soldair/node-qrcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
371 lines (351 loc) · 10.9 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
// Type definitions for qrcode 1.4
// Project: https://github.com/soldair/node-qrcode
// Definitions by: York Yao <https://github.com/plantain-00>
// Michael Nahkies <https://github.com/mnahkies>
// Rémi Sormain <https://github.com/Marchelune>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
/// <reference types="node" />
import * as stream from 'stream';
export type QRCodeErrorCorrectionLevel = 'low' | 'medium' | 'quartile' | 'high' | 'L' | 'M' | 'Q' | 'H';
export interface QRCodeOptions {
/**
* QR Code version. If not specified the more suitable value will be calculated.
*/
version?: number | undefined;
/**
* Error correction level.
* Possible values are low, medium, quartile, high or L, M, Q, H.
* Default: M
*/
errorCorrectionLevel?: QRCodeErrorCorrectionLevel | undefined;
/**
* Helper function used internally to convert a kanji to its Shift JIS value.
* Provide this function if you need support for Kanji mode.
*/
toSJISFunc?: ((codePoint: string) => number) | undefined;
}
export interface QRCodeToDataURLOptions extends QRCodeRenderersOptions {
/**
* Data URI format.
* Default: image/png
*/
type?: 'image/png' | 'image/jpeg' | 'image/webp' | undefined;
rendererOpts?: {
/**
* A Number between 0 and 1 indicating image quality if the requested type is image/jpeg or image/webp.
* Default: 0.92
*/
quality?: number | undefined;
} | undefined;
}
export interface QRCodeToStringOptions extends QRCodeRenderersOptions {
/**
* Output format.
* Default: utf8
*/
// type?: 'utf8' | 'svg' | 'terminal' | undefined;
// MODIFICATION: add propps-svg
type?: 'utf8' | 'svg' | 'terminal' | 'propps-svg' | undefined;
}
export interface QRCodeToFileOptions extends QRCodeRenderersOptions {
/**
* Output format.
* Default: png
*/
type?: 'png' | 'svg' | 'utf8' | undefined;
rendererOpts?: {
/**
* Compression level for deflate.
* Default: 9
*/
deflateLevel?: number | undefined;
/**
* Compression strategy for deflate.
* Default: 3
*/
deflateStrategy?: number | undefined;
} | undefined;
}
export interface QRCodeToFileStreamOptions extends QRCodeRenderersOptions {
/**
* Output format. Only png supported for file stream
*/
type?: 'png' | undefined;
rendererOpts?: {
/**
* Compression level for deflate.
* Default: 9
*/
deflateLevel?: number | undefined;
/**
* Compression strategy for deflate.
* Default: 3
*/
deflateStrategy?: number | undefined;
} | undefined;
}
export interface QRCodeToBufferOptions extends QRCodeRenderersOptions {
/**
* Output format. Only png supported for Buffer.
*/
type?: 'png' | undefined;
rendererOpts?: {
/**
* Compression level for deflate.
* Default: 9
*/
deflateLevel?: number | undefined;
/**
* Compression strategy for deflate.
* Default: 3
*/
deflateStrategy?: number | undefined;
} | undefined;
}
export interface QRCodeRenderersOptions extends QRCodeOptions {
/**
* Define how much wide the quiet zone should be.
* Default: 4
*/
margin?: number | undefined;
/**
* Scale factor. A value of 1 means 1px per modules (black dots).
* Default: 4
*/
scale?: number | undefined;
/**
* Forces a specific width for the output image.
* If width is too small to contain the qr symbol, this option will be ignored.
* Takes precedence over scale.
*/
width?: number | undefined;
color?: {
/**
* Color of dark module. Value must be in hex format (RGBA).
* Note: dark color should always be darker than color.light.
* Default: #000000ff
*/
dark?: string | undefined;
/**
* Color of light module. Value must be in hex format (RGBA).
* Default: #ffffffff
*/
light?: string | undefined;
} | undefined;
}
export interface QRCodeSegment {
data: string | Buffer | Uint8ClampedArray;
mode: 'alphanumeric' | 'numeric' | 'kanji' | 'byte';
}
export interface QRCode {
/**
* Bitmatrix class with modules data
*/
modules: any;
/**
* Calculated QR Code version
*/
version: number;
/**
* Error Correction Level
*/
errorCorrectionLevel: number;
/**
* Calculated Mask pattern
*/
maskPattern: any;
/**
* Generated segments
*/
segments: QRCodeSegment[];
}
/**
* Creates QR Code symbol and returns a qrcode object.
*/
export function create(text: string | QRCodeSegment[], options: QRCodeOptions): QRCode;
/**
* Draws qr code symbol to canvas.
*/
export function toCanvas(
canvasElement: HTMLCanvasElement,
text: string | QRCodeSegment[],
callback: (error: Error) => void,
): void;
/**
* Draws qr code symbol to canvas.
*/
export function toCanvas(
canvasElement: HTMLCanvasElement,
text: string | QRCodeSegment[],
options?: QRCodeRenderersOptions,
): Promise<any>;
/**
* Draws qr code symbol to canvas.
*/
export function toCanvas(
canvasElement: HTMLCanvasElement,
text: string | QRCodeSegment[],
options: QRCodeRenderersOptions,
callback: (error: Error) => void,
): void;
/**
* Draws qr code symbol to canvas.
*/
export function toCanvas(
text: string | QRCodeSegment[],
callback: (error: Error, canvas: HTMLCanvasElement) => void,
): void;
/**
* Draws qr code symbol to canvas.
*/
export function toCanvas(text: string | QRCodeSegment[], options?: QRCodeRenderersOptions): Promise<any>;
/**
* Draws qr code symbol to canvas.
*/
export function toCanvas(
text: string | QRCodeSegment[],
options: QRCodeRenderersOptions,
callback: (error: Error, canvas: HTMLCanvasElement) => void,
): void;
/**
* Draws qr code symbol to node canvas.
*/
export function toCanvas(canvas: any, text: string | QRCodeSegment[], callback: (error: Error) => void): void;
/**
* Draws qr code symbol to node canvas.
*/
export function toCanvas(canvas: any, text: string | QRCodeSegment[], options?: QRCodeRenderersOptions): Promise<any>;
/**
* Draws qr code symbol to node canvas.
*/
export function toCanvas(
canvas: any,
text: string | QRCodeSegment[],
options: QRCodeRenderersOptions,
callback: (error: Error) => void,
): void;
/**
* Returns a Data URI containing a representation of the QR Code image.
*/
export function toDataURL(
canvasElement: HTMLCanvasElement,
text: string | QRCodeSegment[],
callback: (error: Error, url: string) => void,
): void;
/**
* Returns a Data URI containing a representation of the QR Code image.
*/
export function toDataURL(
canvasElement: HTMLCanvasElement,
text: string | QRCodeSegment[],
options?: QRCodeToDataURLOptions,
): Promise<string>;
/**
* Returns a Data URI containing a representation of the QR Code image.
*/
export function toDataURL(
canvasElement: HTMLCanvasElement,
text: string | QRCodeSegment[],
options: QRCodeToDataURLOptions,
callback: (error: Error, url: string) => void,
): void;
/**
* Returns a Data URI containing a representation of the QR Code image.
*/
export function toDataURL(text: string | QRCodeSegment[], callback: (error: Error, url: string) => void): void;
/**
* Returns a Data URI containing a representation of the QR Code image.
*/
export function toDataURL(text: string | QRCodeSegment[], options?: QRCodeToDataURLOptions): Promise<string>;
/**
* Returns a Data URI containing a representation of the QR Code image.
*/
export function toDataURL(
text: string | QRCodeSegment[],
options: QRCodeToDataURLOptions,
callback: (error: Error, url: string) => void,
): void;
/**
* Returns a string representation of the QR Code.
* If choosen output format is svg it will returns a string containing xml code.
*/
export function toString(text: string | QRCodeSegment[], callback: (error: Error, string: string) => void): void;
/**
* Returns a string representation of the QR Code.
* If choosen output format is svg it will returns a string containing xml code.
*/
export function toString(text: string | QRCodeSegment[], options?: QRCodeToStringOptions): Promise<string>;
/**
* Returns a string representation of the QR Code.
* If choosen output format is svg it will returns a string containing xml code.
*/
export function toString(
text: string | QRCodeSegment[],
options: QRCodeToStringOptions,
callback: (error: Error, string: string) => void,
): void;
/**
* Saves QR Code to image file.
* If options.type is not specified, the format will be guessed from file extension.
* Recognized extensions are png, svg, txt.
*/
export function toFile(path: string, text: string | QRCodeSegment[], callback: (error: Error) => void): void;
/**
* Saves QR Code to image file.
* If options.type is not specified, the format will be guessed from file extension.
* Recognized extensions are png, svg, txt.
*/
export function toFile(path: string, text: string | QRCodeSegment[], options?: QRCodeToFileOptions): Promise<any>;
/**
* Saves QR Code to image file.
* If options.type is not specified, the format will be guessed from file extension.
* Recognized extensions are png, svg, txt.
*/
export function toFile(
path: string,
text: string | QRCodeSegment[],
options: QRCodeToFileOptions,
callback: (error: Error) => void,
): void;
/**
* Writes QR Code image to stream. Only works with png format for now.
*/
export function toFileStream(
stream: stream.Writable,
text: string | QRCodeSegment[],
callback: (error: Error) => void,
): void;
/**
* Writes QR Code image to stream. Only works with png format for now.
*/
export function toFileStream(
stream: stream.Writable,
text: string | QRCodeSegment[],
options?: QRCodeToFileStreamOptions,
): Promise<any>;
/**
* Writes QR Code image to stream. Only works with png format for now.
*/
export function toFileStream(
stream: stream.Writable,
text: string | QRCodeSegment[],
options: QRCodeToFileStreamOptions,
callback: (error: Error) => void,
): void;
/**
* Returns a Buffer containing a representation of the QR Code image. Only works with png format.
*/
export function toBuffer(text: string | QRCodeSegment[], callback: (error: Error, buffer: Buffer) => void): void;
/**
* Returns a Buffer containing a representation of the QR Code image. Only works with png format.
*/
export function toBuffer(text: string | QRCodeSegment[], options?: QRCodeToBufferOptions): Promise<Buffer>;
/**
* Returns a Buffer containing a representation of the QR Code image. Only works with png format.
*/
export function toBuffer(
text: string | QRCodeSegment[],
options: QRCodeToBufferOptions,
callback: (error: Error, buffer: Buffer) => void,
): void;