Socket
Book a DemoInstallSign in
Socket

qr

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

qr - npm Package Compare versions

Comparing version

to
0.2.1

test.png

44

lib/encoder.js

@@ -13,4 +13,4 @@ var util = require('util'),

Encoder.prototype.default_options = {
foreground_color: '#000000',
background_color: '#FFFFFF',
foreground_color: '#000000', // change foreground color in qrencode v3.4.0+
background_color: '#FFFFFF', // change background color in qrencode v3.4.0+
dot_size: 3, // default 3x3px per dot

@@ -20,5 +20,8 @@ margin: 4, // default 4 dots for the margin

case_sensitive: true, // case sensitive,
version: 1 // default version 1
version: 1, // default version 1,
type : null // Default to null type, removing this flag qrencode < v3.4.0
};
Encoder.prototype.types = ['PNG','EPS','SVG','ANSI','ANSI256','ASCII','ASCIIi','UTF8','ANSIUTF8', null];
/**

@@ -56,6 +59,2 @@ * Converts a string value to QR Code PNG data, and optionally saves to a file

// remove # symbol from color codes because qrencoder does not like it
cmd_options.foreground_color = cmd_options.foreground_color.replace('#', '');
cmd_options.background_color = cmd_options.background_color.replace('#', '');
// start with base set of args that we'll always pass

@@ -66,7 +65,29 @@ qrencode_args = [

'-l', cmd_options.level,
'-v', cmd_options.version,
'-v', cmd_options.version
];
// only set foreground and background colors if they differ from
// defaults to maintain compatibility with qrencode pre-v3.4.0
if(cmd_options.foreground_color !== self.default_options.foreground_color
|| cmd_options.background_color !== self.default_options.background_color) {
// remove # symbol from color codes because qrencoder does not like it
cmd_options.foreground_color = cmd_options.foreground_color.replace('#', '');
cmd_options.background_color = cmd_options.background_color.replace('#', '');
qrencode_args.push(
'--foreground=' + cmd_options.foreground_color,
'--background=' + cmd_options.background_color
];
);
}
// Only include the type flag if it has been passed to
// maintain compatibility with qrencode pre-v3.4.0
if(cmd_options.type !== null){
if(self.types.indexOf(cmd_options.type.toUpperCase()) === -1){
throw new Error('type must be one of ', self.types.toString());
}
qrencode_args.push('-t' + cmd_options.type);
}
// if case-sensitivity is disabled, add flag

@@ -87,2 +108,5 @@ if(!cmd_options.case_sensitive) qrencode_args.push('-i');

// create stdout data container
var stdout, stderr;
// spawn the child process

@@ -89,0 +113,0 @@ qrencode = child_process.spawn(

{
"name": "qr",
"description": "A small library to generate QR codes with libqrencode.",
"version": "0.2.0",
"version": "0.2.1",
"author": {

@@ -6,0 +6,0 @@ "name": "Brian Celenza",

@@ -115,2 +115,26 @@ var vows = require('vows'),

},
'and a custom type option': {
topic: function() {
var encoder = new Encoder;
encoder.on('end', this.callback);
// set a custom output
encoder.encode('test', null, { type: 'SVG' });
},
'provides SVG data' : function(result, encoder) {
assert.ok((result instanceof Buffer));
assert.equal(result.length, 6206, 'Unexpected buffer length for custom type');
}
},
'and an invalid type option': {
topic: function() {
var encoder = new Encoder;
encoder.on('error', this.callback);
// set an incorrect type option
encoder.encode('test', null, { type: 'SPVG' });
},
'emits an \'error\' event with Error object' : function(result, encoder) {
assert.ok((result instanceof Error), 'Unexpected result emitted with error event');
assert.notEqual(result.message, "");
}
},
'and an invalid option': {

@@ -117,0 +141,0 @@ topic: function() {

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.