qrcode

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
Name Type Attributes Default Description
output string <optional>
'buffer' The output type: 'buffer' or 'dataurl'.
width number <optional>
2 The width of a single bar.
height number <optional>
100 The height of the bars.
displayValue boolean <optional>
true Whether to display the text below the barcode.
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
Name Type Attributes Default Description
output string <optional>
'buffer' The output type: 'buffer' or 'dataurl'.
errorCorrectionLevel string <optional>
'medium' 'low', 'medium', 'quartile', 'high'.
margin number <optional>
4 The width of the quiet zone border.
width number <optional>
200 The width of the image in pixels.
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)>