pure-svg-code
Generate qrcode and barcode
Feature
- SVG: can be used in any client support render svg like browser & 小程序 & Node.js;
- Small: write in pure javascript, no dependency;
- Typescript: support Typescript;
Install
Install from npm:
npm i pure-svg-code
Import it:
// import bothconst barcodeqrcodesvg2url = ; // import as you needconst barcode = ;const qrcode = ;const svg2url = ;
File size:
- qrcode: minified 17Kb, Gzip 5.7Kb
- barcode: minified 19Kb, Gzip 6.2Kb
qrcode
const svgString =
Output svg content:
...
List of options:
content
- QR Code content, requiredpadding
- white space padding,4
modules by default,0
for no borderwidth
- QR Code width in pixelsheight
- QR Code height in pixelscolor
- color of modules, color name or hex string, e.g.#000000
background
- color of background, color name or hex string, e.g.white
ecl
- error correction level:L
,M
,H
,Q
barcode
Set it up and specify your type and options. The following 3 are the only required ones.
var svgString = ;
Output svg content:
...
Support types:
- codabar
- code11 (code 11)
- code39 (code 39)
- code93 (code 93)
- code128 (code 128)
- ean8 (ean 8)
- ean13 (ean 13)
- std25 (standard 2 of 5 - industrial 2 of 5)
- int25 (interleaved 2 of 5)
Support options:
barHeight
height of svg (default: 30);width
width of svg (default: 100);bgColor
background color css like (default: 'transparent');color
barcode color (default: '#000000');showHRI
: should show text under bar;
<img/>
tag
Use it with const qrcodesvg2url = ;const svgString = ;const url = ; // set img element's src to urlimgElesrc = url;
This way can be used for browser & 小程序 or any client can render svg.
Use it in Node.js server
const qrcode = ; app