![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
A QR & Barcode Library for Node.js/Bun, the CLI, including all major browsers.
CODE128
, EAN
, EAN-13
, EAN-8
, EAN-5
, EAN-2
, UPC (A)
, CODE39
, ITF-14
, MSI
, Pharmacode
, Codabar
—Generation & ReadingIt's simple to install the library and CLI:
npm install qrx
bun add qrx
yarn add qrx
pnpm add qrx
Check out the package.json scripts for more commands.
<div id="qrcode"></div>
<script type="text/javascript">
new QRCode(document.getElementById("qrcode"), "https://stacksjs.org");
</script>
If you want to customize the QR code, you can pass in an options object:
<div id="qr-code"></div>
<script type="text/javascript">
var qrCode = new QRCode(document.getElementById("qr-code"), {
text: "https://stacksjs.org",
width: 128,
height: 128,
colorDark : "#000000",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.H
});
</script>
You can also use methods to interact with the QR code:
qrCode.clear() // clear the code
qrCode.makeCode('https://docs.stacksjs.org') // create another code
A lightweight Barcode library with zero dependencies. It supports multiple barcode formats and works in browsers and with Node.js & Bun.
<svg id="barcode"></svg>
<!-- or -->
<canvas id="barcode"></canvas>
<!-- or -->
<img id="barcode"/>
Barcode('#barcode', 'Hi!')
Barcode('#barcode', '1234', {
format: 'pharmacode',
lineColor: '#0aa',
width: 4,
height: 40,
displayValue: false
})
Barcode('#barcode')
.options({ font: 'OCR-B' }) // Will affect all barcodes
.EAN13('1234567890128', { fontSize: 18, textMargin: 0 })
.blank(20) // Create space between the barcodes
.EAN5('12345', { height: 85, textPosition: 'top', fontSize: 16, marginTop: 15 })
.render()
Use any barcode-*
or data-*
as attributes where *
is any option.
<svg class="barcode"
barcode-format="upc"
barcode-value="123456789012"
barcode-text-margin="0"
barcode-font-options="bold">
</svg>
And then initialize it with:
Barcode('.barcode').init()
Pass in an object which will be filled with data.
const data = {}
Barcode(data, 'text', { ...options })
data will be filled with a encodings
property which has all the needed values. See docs for examples of what data looks like.
import { Barcode } from '@stacksjs/qrx'
import { createCanvas } from 'canvas'
const canvas = createCanvas()
Barcode(canvas, 'Hello')
// As this is a node-canvas, you can configure it as you like:
// see https://github.com/Automattic/node-canvas for more information
import { DOMImplementation, XMLSerializer } from 'xmldom'
const xmlSerializer = new XMLSerializer()
const document = new DOMImplementation().createDocument('http://www.w3.org/1999/xhtml', 'html', null)
const svgNode = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
Barcode(svgNode, 'test', {
xmlDocument: document,
})
const svgText = xmlSerializer.serializeToString(svgNode)
For information about how to use the options, see the docs.
Option | Default value | Type |
---|---|---|
format | "auto" (CODE128) | String |
width | 2 | Number |
height | 100 | Number |
displayValue | true | Boolean |
text | undefined | String |
fontOptions | "" | String |
font | "monospace" | String |
textAlign | "center" | String |
textPosition | "bottom" | String |
textMargin | 2 | Number |
fontSize | 20 | Number |
background | "#ffffff" | String (CSS color) |
lineColor | "#000000" | String (CSS color) |
margin | 10 | Number |
marginTop | undefined | Number |
marginBottom | undefined | Number |
marginLeft | undefined | Number |
marginRight | undefined | Number |
valid | function(valid){} | Function |
bun test
Please see our releases page for more information on what has changed recently.
Please see CONTRIBUTING for details.
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
For casual chit-chat with others using this package:
Join the Stacks Discord Server
Stacks OSS will always stay open-sourced, and we will always love to receive postcards from wherever Stacks is used! And we also publish them on our website. Thank you, Spatie.
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States 🌎
We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.
Many thanks for the libraries that laid the groundwork:
The MIT License (MIT). Please see LICENSE for more information.
Made with 💙
FAQs
QR & Bar Code generating & reading. React components. Placeholder.
The npm package react-qrx receives a total of 3 weekly downloads. As such, react-qrx popularity was classified as not popular.
We found that react-qrx demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.