Research
Security News
Malicious npm Package Typosquats react-login-page to Deploy Keylogger
Socket researchers unpack a typosquatting package with malicious code that logs keystrokes and exfiltrates sensitive data to a remote server.
qrcode
Advanced tools
Package description
The qrcode npm package is a library for generating QR codes. It can be used to create QR codes in various formats such as images or canvas for web applications, and it supports a range of customization options.
Generating QR Code as Data URL
This feature allows you to generate a QR code as a data URL, which can be used directly in image tags or CSS backgrounds.
const QRCode = require('qrcode');
QRCode.toDataURL('https://www.example.com', function (err, url) {
console.log(url);
});
Generating QR Code as PNG Image File
This feature allows you to generate a QR code and save it as a PNG image file on the filesystem.
const QRCode = require('qrcode');
QRCode.toFile('path/to/output.png', 'https://www.example.com', function (err) {
if (err) throw err;
console.log('QR Code saved as image file!');
});
Generating QR Code as UTF8 String
This feature allows you to generate a QR code as a UTF8 string, which can be printed to the terminal or used in text-based formats.
const QRCode = require('qrcode');
QRCode.toString('https://www.example.com', { type: 'terminal' }, function (err, string) {
if (err) throw err;
console.log(string);
});
The qrcode-svg package generates QR codes in SVG format. It offers a different output format compared to qrcode and might be preferred when working with vector graphics.
The qr-image package is another alternative for generating QR codes. It can create QR codes in PNG, SVG, EPS, and PDF formats. It provides a different API and additional output formats compared to qrcode.
Unlike qrcode, which is focused on generating QR codes, jsQR is a library for parsing and reading QR codes. It is used to decode QR codes from images.
Readme
This is a server side QR code/2d barcode generator.
It is an extension of "QRCode for JavaScript" which Kazuhiko Arase thankfully MIT licensed.
The qrcode-draw.js
can be used directly as a client side lib if its appended too or included with lib/qrcode.js
.
To use this on the server side please require('qrcode');
=)
A simple server side test...
var QRCode = require('qrcode');
QRCode.toDataURL('i am a pony!',function(err,url){
console.log(url);
});
In your terminal if you install globally...
qrcode "hi i want a qrcode"
qrcode "i like to save qrs to file" qr.png
In client side HTML...
<!--[if ie]><script type="text/javascript" src="/vendors/excanvas/excanvas.js"></script><![endif]-->
<script src="/build/qrcode.js"></script>
<canvas id="test"></canvas>
<script>
var qrcodedraw = new QRCodeLib.QRCodeDraw();
qrcodedraw.draw(document.getElementById('test'),"this text will be in the code!", function(error,canvas){
if(error){
return console.log('Error =( ',error);
}
console.log('success!');
});
</script>
Remember to put excanvas.js
and qrcode.js
somewhere where your browser can find them.
QRCode.draw(text, [optional options], cb(error,canvas));
Returns a node canvas object see https://github.com/LearnBoost/node-canvas for all of the cool node things you can do. Look up the canvas api for the other cool things.
QRCode.toDataURL(text, [optional options], cb(error,dataURL));
Returns mime image/png data url for the 2d barcode.
QRCode.save(path, text, [optional options] , cb(error,written));
Saves png to the path specified returns bytes written.
QRCode.drawText(text, [optional options],cb)
Returns an ascii representation of the qrcode using unicode characters and ansi control codes for background control.
QRCode.drawBitArray(text, [optional options], cb(error,bits,width));
Returns an array with each value being either 0 light or 1 dark and the width of each row. This is enough info to render a qrcode any way you want. =)
errorCorrectLevel
Can be one of the values in qrcode.errorCorrectLevel
.
Can be a string. one of "minimum","medium","high","max"
.
If undefined
, defaults to H which is max error correction.
If invalid value, defaults to minimum error correction.
window.qrcodelib
qrcodelib.qrcodedraw()
Constructor
qrcode = new qrcodelib.qrcodedraw()
qrcode.draw(canvasElement,text,[optional options],cb);
For quick client side use...
node test/clientsideserver.js
open http://localhost:3031
The JavaScript is in test/clientside.html
.
This libary can encode this many bytes at each error correct level:
The default is H.
please note as pointed out by @giacecco that byte length is often greater than string length due to multibyte characters.
// so use the byte length
(new Buffer(str)).length
// instead of the string length
str.length
It can now be changed in an ugly way that wont be supported for more then another few days if you really need to. Also the default module size at qr version 40 is really too small for the camera on my Nexus 1 and to make it larger i run out of screen to show it. At 40 the barcode scanner even finds random UPC 1d barcodes in the mass of little squares. the default module size cannot be changed through the public api at this time.
npm install qrcode
To use qrcode from the command line to save qrcode images or generate ones you can view in your terminal...
npm install -g qrcode
node-canvas
is a native module and requires dev packages of cairo
and pixman
to compile.
On ubuntu you can install them with apt-get
and npm install
will work great.
sudo apt-get install libpixman-1-dev libcairo2-dev libpangocairo-1.0-0 libpango1.0-dev libgif-dev libjpeg-dev
i would like to switch to a js only image encoder to remove these deps.
These should be taken care of for you by npm but you should...
npm install canvas
If cairo
gives you trouble and you cannot install canvas
, checkout the canvas site. I know @tjholowaychuk has setup a way to download and install a version of cairo/pixman for testing.
The word "QR Code" is registered trademark of:
DENSO WAVE INCORPORATED
there was a real good discussion here about them. but in short any qrcode generator will make gs1 compatable qrcodes, but what defines a gs1 qrcode is a header with metadata that describes your gs1 information.
FAQs
Unknown package
We found that qrcode demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.
Research
Security News
Socket researchers unpack a typosquatting package with malicious code that logs keystrokes and exfiltrates sensitive data to a remote server.
Security News
The JavaScript community has launched the e18e initiative to improve ecosystem performance by cleaning up dependency trees, speeding up critical parts of the ecosystem, and documenting lighter alternatives to established tools.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.