- Notifications
You must be signed in to change notification settings - Fork0
🔒 QR & Bar Code generating & reading. Lightweight & powerful.
License
stacksjs/qrx
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A QR & Barcode Library & CLI for Node.js/Bun/Browser.
- 🤖QR Code: Customizable Generation & Reading
- 📊Barcode:
CODE128
,EAN
,EAN-13
,EAN-8
,EAN-5
,EAN-2
,UPC (A)
,CODE39
,ITF-14
,MSI
,Pharmacode
,Codabar
—Generation & Reading - 📦Lightweight: Zero dependencies
- 🚀Fast: Built with performance in mind
- 📜TypeScript: Strongly typed
- 📚Simple: Easy to use
- 📖Documentation: Well-documented
- 🛠Library & CLI: Interact in different ways
It's simple to install the library and CLI:
npm install qrxbun add qrxyarn add qrxpnpm add qrx
Check out the package.json scripts for more commands.
<divid="qr-code"></div><scripttype="text/javascript">newQRCode(document.getElementById("qr-code"),"https://stacksjs.org");</script>
If you want to customize the QR code, you can pass in an options object:
<divid="qr-code"></div><scripttype="text/javascript">constoptions={width:2,height:100,format:'auto',displayValue:true,fontOptions:'',font:'monospace',text:undefined,textAlign:'center',textPosition:'bottom',textMargin:2,fontSize:20,background:'#ffffff',lineColor:'#000000',margin:10,marginTop:undefined,marginBottom:undefined,marginLeft:undefined,marginRight:undefined,valid(){},}varqrCode=newQRCode(document.getElementById("qr-code"),options);</script>
You can also use methods to interact with the QR code:
qrCode.clear()// clear the codeqrCode.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 withNode.js & Bun.
- CODE128
- CODE128 (automatic mode switching)
- CODE128 A/B/C (force mode)
- EAN
- EAN-13
- EAN-8
- EAN-5
- EAN-2
- UPC (A)
- UPC (E)
- CODE39
- ITF
- ITF
- ITF-14
- MSI
- MSI10
- MSI11
- MSI1010
- MSI1110
- Pharmacode
- Codabar
<svgid="barcode"></svg><!-- or --><canvasid="barcode"></canvas><!-- or --><imgid="barcode"/>
barcode('#barcode','Hi!')
import{barcode}from'@stacksjs/qrx'barcode('#barcode','1234',{format:'pharmacode',lineColor:'#0aa',width:4,height:40,displayValue:false})
import{barcode}from'@stacksjs/qrx'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 anybarcode-*
ordata-*
as attributes where*
is any option.
<svgclass="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.
constdata={}barcode(data,'text',{ ...options})
data will be filled with aencodings
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'constcanvas=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'constxmlSerializer=newXMLSerializer()constdocument=newDOMImplementation().createDocument('http://www.w3.org/1999/xhtml','html',null)constsvgNode=document.createElementNS('http://www.w3.org/2000/svg','svg')Barcode(svgNode,'test',{xmlDocument:document,})constsvgText=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 |
buntest
Please see ourreleases page for more information on what has changed recently.
Please seeCONTRIBUTING 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
“Software that is free, but hopes for a postcard.” We love receiving postcards from around the world showing whereqrx
is being used! We showcase them on our website too.
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:
- JsBarcode:https://github.com/lindell/JsBarcode
- Quagga:https://github.com/ericblade/quagga2
- QRCode.js:https://github.com/davidshimjs/qrcodejs
The MIT License (MIT). Please seeLICENSE for more information.
Made with 💙
About
🔒 QR & Bar Code generating & reading. Lightweight & powerful.