Provides functions to generate QR codes and 1D barcodes.
- Description:
- Provides functions to generate QR codes and 1D barcodes.
Members
(static, constant) BUFFER
- Description:
- Constant for Buffer output type. This constant can be used to specify that the output should be a Buffer.
Constant for Buffer output type.
This constant can be used to specify that the output should be a Buffer.
(static, constant) DATA_URL
- Description:
- Constant for Data URL output type. This constant can be used to specify that the output should be a Data URL.
Constant for Data URL output type.
This constant can be used to specify that the output should be a Data URL.
Methods
(static) barcode(format, text, optionsopt) → {Promise.<(Buffer|string)>}
- Description:
- Generates a 1D barcode from the provided text. This function uses the 'jsbarcode' library to create 1D barcodes.
Examples
const barcode = await barcode('CODE128', '123456789012', { output: barcode.DATA_URL });
console.log(barcode); // Outputs a Data URL of the barcode image
const barcodeBuffer = await barcode('CODE128', '123456789012', { output: barcode.BUFFER });
console.log(barcodeBuffer); // Outputs a Buffer of the barcode image
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
format |
string | The barcode format (e.g., 'CODE128', 'EAN13', 'UPC'). | ||||||||||||||||||||||||||
text |
string | The text or data to encode. | ||||||||||||||||||||||||||
options |
object |
<optional> |
Optional settings.
Properties
|
Throws:
-
If the input text is not a string or if the output type is invalid.
- Type
- Error
Returns:
A promise that resolves with the barcode data.
- Type
- Promise.<(Buffer|string)>
(static) qrcode(text, optionsopt) → {Promise.<(Buffer|string)>}
- Description:
- Generates a QR code from the provided text. This function uses the 'qrcode' library to create QR codes, allowing for various output formats. It supports both Buffer and Data URL outputs, making it flexible for different use cases.
Examples
const qrCode = await qrcode('Hello, world!', { output: qrcode.DATA_URL });
console.log(qrCode); // Outputs a Data URL of the QR code image
const qrCodeBuffer = await qrcode('Hello, world!', { output: qrcode.BUFFER });
console.log(qrCodeBuffer); // Outputs a Buffer of the QR code image
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
text |
string | The text or data to encode. | ||||||||||||||||||||||||||
options |
object |
<optional> |
Optional settings.
Properties
|
Throws:
-
If the input text is not a string or if the output type is invalid.
- Type
- Error
Returns:
A promise that resolves with the QR code data.
- Type
- Promise.<(Buffer|string)>