qr 0.2.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,30 +1,79 @@
1
1
  {
2
- "name": "qr",
3
- "description": "A small library to generate QR codes with libqrencode.",
4
- "version": "0.2.3",
5
- "author": {
6
- "name": "Brian Celenza",
7
- "email": "bcelenza@gmail.com"
2
+ "name": "qr",
3
+ "version": "0.4.0",
4
+ "description": "Minimal 0-dep QR code generator & reader. Supports ascii, term, gif and svg formats",
5
+ "files": [
6
+ "esm",
7
+ "index.js",
8
+ "index.d.ts",
9
+ "index.d.ts.map",
10
+ "index.ts",
11
+ "decode.js",
12
+ "decode.d.ts",
13
+ "decode.d.ts.map",
14
+ "decode.ts",
15
+ "dom.js",
16
+ "dom.d.ts",
17
+ "dom.d.ts.map",
18
+ "dom.ts",
19
+ "LICENSE",
20
+ "LICENSE-MIT"
21
+ ],
22
+ "main": "index.js",
23
+ "module": "index.js",
24
+ "types": "index.d.ts",
25
+ "sideEffects": false,
26
+ "devDependencies": {
27
+ "@paulmillr/jsbt": "0.3.3",
28
+ "jpeg-js": "0.4.4",
29
+ "micro-bmark": "0.4.0",
30
+ "micro-should": "0.5.1",
31
+ "omggif": "1.0.10",
32
+ "prettier": "3.5.2",
33
+ "typescript": "5.8.2"
34
+ },
35
+ "author": "Paul Miller (https://paulmillr.com)",
36
+ "license": "(MIT OR Apache-2.0)",
37
+ "homepage": "https://github.com/paulmillr/qr",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/paulmillr/qr.git"
41
+ },
42
+ "scripts": {
43
+ "build": "tsc && tsc -p tsconfig.cjs.json",
44
+ "build:release": "npx jsbt esbuild test/build",
45
+ "lint": "prettier --check src",
46
+ "format": "prettier --write src",
47
+ "test": "node test/index.js",
48
+ "test:bun": "bun test/index.js",
49
+ "test:deno": "deno --allow-env --allow-read test/index.js"
50
+ },
51
+ "exports": {
52
+ ".": {
53
+ "import": "./esm/index.js",
54
+ "require": "./index.js"
8
55
  },
9
- "homepage": "https://github.com/bcelenza/node-qr",
10
- "keywords": ["qr", "qrcode", "qrencode", "qrencoder"],
11
- "main": "./qr.js",
12
- "dependencies": {
13
- "vows": ">= 0.5.8",
14
- "benchmark": ""
56
+ "./decode.js": {
57
+ "import": "./esm/decode.js",
58
+ "require": "./decode.js"
15
59
  },
16
- "engines": {
17
- "node": ">= 0.8.0"
18
- },
19
- "repository": {
20
- "type": "git",
21
- "url": "git://github.com/bcelenza/node-qr.git"
22
- },
23
- "license": {
24
- "type": "MIT",
25
- "url": "http://www.opensource.org/licenses/mit-license.php"
26
- },
27
- "scripts": {
28
- "test": "vows --spec test/*.js"
60
+ "./dom.js": {
61
+ "import": "./esm/dom.js",
62
+ "require": "./dom.js"
29
63
  }
64
+ },
65
+ "keywords": [
66
+ "qr",
67
+ "code",
68
+ "qr code",
69
+ "qr pattern",
70
+ "qr generator",
71
+ "qr reader",
72
+ "ascii",
73
+ "gif",
74
+ "svg",
75
+ "camera",
76
+ "file"
77
+ ],
78
+ "funding": "https://paulmillr.com/funding/"
30
79
  }
package/.npmignore DELETED
@@ -1 +0,0 @@
1
- node_modules
package/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - "0.11"
4
- - "0.10"
5
- - "0.8"
6
- - "0.6"
7
- before_install:
8
- - sudo apt-get update -qq
9
- - sudo apt-get install -qq qrencode
package/benchmark.js DELETED
@@ -1,15 +0,0 @@
1
- var Encoder = require('./qr').Encoder,
2
- Benchmark = require('benchmark');
3
- var encoder = new Encoder;
4
- var suite = new Benchmark.Suite
5
-
6
- suite.add('Encoder#encode()', function(){
7
- encoder.encode('node-qr');
8
- })
9
- .on('cycle', function(event, bench){
10
- console.log(String(bench));
11
- })
12
- .on('complete', function(){
13
- console.log('Fastest is ' + this.filter('fastest').pluck('name'));
14
- })
15
- .run({ 'async': true });
package/lib/encoder.js DELETED
@@ -1,142 +0,0 @@
1
- var util = require('util'),
2
- events = require('events'),
3
- child_process = require('child_process');
4
-
5
- var Encoder = exports.Encoder = function(){
6
- events.EventEmitter.call(this);
7
-
8
-
9
- }
10
- util.inherits(Encoder, events.EventEmitter);
11
-
12
- Encoder.prototype.default_options = {
13
- foreground_color: '#000000', // change foreground color in qrencode v3.4.0+
14
- background_color: '#FFFFFF', // change background color in qrencode v3.4.0+
15
- dot_size: 3, // default 3x3px per dot
16
- margin: 4, // default 4 dots for the margin
17
- level: 'L', // valid args (lowest to highest): L, M, Q, H
18
- case_sensitive: true, // case sensitive,
19
- version: 1, // default version 1,
20
- type : null // Default to null type, removing this flag qrencode < v3.4.0
21
- };
22
-
23
- Encoder.prototype.types = ['PNG','EPS','SVG','ANSI','ANSI256','ASCII','ASCIIi','UTF8','ANSIUTF8', null];
24
-
25
- /**
26
- * Converts a string value to QR Code PNG data, and optionally saves to a file
27
- *
28
- * @param String value The value to be encoded
29
- * @param String path Where to save the PNG file (optional)
30
- * @param Object options A hash of options (optional)
31
- * @return void
32
- */
33
- Encoder.prototype.encode = function(value, path, options)
34
- {
35
- // preserve scope in callbacks with self
36
- var self = this,
37
- cmd_options, qrencode_args, stdout, stderr, qrencode, exitcode;
38
-
39
- try {
40
- // check for undefined value
41
- if(value == undefined) {
42
- throw new Error('No value specified for encode method');
43
- }
44
-
45
- // create new buffer for value
46
- value = new Buffer(value);
47
-
48
- // if options are given, override defaults
49
- cmd_options = {};
50
- if(options == null) options = {};
51
- for(var key in this.default_options) {
52
- cmd_options[key] = (options[key] == undefined) ?
53
- this.default_options[key]
54
- : options[key];
55
- }
56
-
57
- // start with base set of args that we'll always pass
58
- qrencode_args = [
59
- '-s', cmd_options.dot_size,
60
- '-m', cmd_options.margin,
61
- '-l', cmd_options.level,
62
- '-v', cmd_options.version
63
- ];
64
-
65
- // only set foreground and background colors if they differ from
66
- // defaults to maintain compatibility with qrencode pre-v3.4.0
67
- if(cmd_options.foreground_color !== self.default_options.foreground_color
68
- || cmd_options.background_color !== self.default_options.background_color) {
69
-
70
- // remove # symbol from color codes because qrencoder does not like it
71
- cmd_options.foreground_color = cmd_options.foreground_color.replace('#', '');
72
- cmd_options.background_color = cmd_options.background_color.replace('#', '');
73
-
74
- qrencode_args.push(
75
- '--foreground=' + cmd_options.foreground_color,
76
- '--background=' + cmd_options.background_color
77
- );
78
- }
79
-
80
- // Only include the type flag if it has been passed to
81
- // maintain compatibility with qrencode pre-v3.4.0
82
- if(cmd_options.type !== null){
83
- if(self.types.indexOf(cmd_options.type.toUpperCase()) === -1){
84
- throw new Error('type must be one of ', self.types.toString());
85
- }
86
- qrencode_args.push('-t' + cmd_options.type);
87
- }
88
-
89
- // if case-sensitivity is disabled, add flag
90
- if(!cmd_options.case_sensitive) qrencode_args.push('-i');
91
-
92
- // if we have a path, write to the path
93
- // otherwise, it will write to stdout
94
- qrencode_args.push('-o');
95
- if(path != null) {
96
- qrencode_args.push(path);
97
- } else {
98
- qrencode_args.push('-');
99
- }
100
-
101
- // add the value to be encoded
102
- qrencode_args.push(value);
103
-
104
- // create stdout data container
105
- var stdout, stderr;
106
-
107
- // spawn the child process
108
- qrencode = child_process.spawn(
109
- 'qrencode',
110
- qrencode_args
111
- );
112
-
113
- // add event listener for stdout data and populate stdout var
114
- // in the event no path was given
115
- qrencode.stdout.on('data', function(data) {
116
- stdout = data;
117
- });
118
-
119
- // add event listener for stderr
120
- qrencode.stderr.on('data', function(data) {
121
- stderr = data;
122
- });
123
-
124
- // add listener for process exit and save exit code
125
- qrencode.on('exit', function(code) {
126
- exitcode = code;
127
- });
128
-
129
- // add listener for filehandle close and emit end or error event
130
- // depending on exit code
131
- qrencode.on('close', function() {
132
- if(exitcode !== 0) {
133
- self.emit('error', new Error(stderr));
134
- } else {
135
- self.emit('end', stdout);
136
- }
137
- });
138
-
139
- } catch(err) {
140
- this.emit('error', err);
141
- }
142
- }
package/qr.js DELETED
@@ -1 +0,0 @@
1
- exports.Encoder = require('./lib/encoder').Encoder;
package/test/encoder.js DELETED
@@ -1,176 +0,0 @@
1
- var vows = require('vows'),
2
- events = require('events'),
3
- assert = require('assert'),
4
- fs = require('fs'),
5
- util = require('util'),
6
- child_process = require('child_process'),
7
- qr = require('../qr');
8
-
9
- var Encoder = qr.Encoder;
10
- var test_file_name = './test.png';
11
-
12
- vows.describe('Encoder').addBatch({
13
- 'The libqrencode library': {
14
- topic: function() {
15
- var which = child_process.spawn('which', ['qrencode']);
16
- which.on('exit', this.callback);
17
- },
18
- 'is installed and available via $PATH': function(exit_code, process) {
19
- assert.equal(exit_code, null, 'libqrencode does not appear to have been installed properly');
20
- }
21
- }
22
- }).addBatch({
23
- 'The encoder': {
24
- topic: new(Encoder),
25
- 'is an event emitter': function(encoder) {
26
- assert.ok((encoder instanceof events.EventEmitter));
27
- },
28
- 'has some default options': function(encoder) {
29
- assert.ok(encoder.default_options);
30
- },
31
- 'has an encode method': function(encoder) {
32
- assert.ok((typeof encoder.encode == "function"));
33
- }
34
- }
35
- }).addBatch({
36
- 'The encode method': {
37
- 'with a provided value': {
38
- 'and a path': {
39
- topic: function() {
40
- var encoder = new Encoder;
41
- encoder.on('end', this.callback);
42
- encoder.encode('test', test_file_name);
43
- },
44
- 'emits an \'end\' event': function(result, encoder) {
45
- return true;
46
- },
47
- 'creates a PNG file at provided path': function(result, encoder) {
48
- var stats = fs.statSync(test_file_name);
49
- assert.notEqual(stats.size, 0, 'Zero file size');
50
- fs.unlinkSync(test_file_name);
51
- }
52
- },
53
- 'and no path': {
54
- topic: function() {
55
- var encoder = new Encoder;
56
- encoder.on('end', this.callback);
57
- encoder.encode('test');
58
- },
59
- 'emits an \'end\' event': function(result, encoder) {
60
- return true;
61
- },
62
- 'provides PNG data with event': function(result, encoder) {
63
- assert.ok((result instanceof Buffer));
64
- assert.notEqual(result.length, 0, 'Zero buffer length');
65
- }
66
- },
67
- 'and a custom size option': {
68
- topic: function() {
69
- var encoder = new Encoder;
70
- encoder.on('end', this.callback);
71
- // set custom dot size of 10px
72
- encoder.encode('test', null, { dot_size: 10 });
73
- },
74
- 'provides PNG data with a custom size': function(result, encoder) {
75
- assert.ok((result instanceof Buffer));
76
- assert.notEqual(result.length, 0, 'Zero buffer length for custom size');
77
- }
78
- },
79
- 'and a custom margin option': {
80
- topic: function() {
81
- var encoder = new Encoder;
82
- encoder.on('end', this.callback);
83
- // set custom margin size of 5 dots
84
- encoder.encode('test', null, { margin: 5 });
85
- },
86
- 'provides PNG data with a custom margin': function(result, encoder) {
87
- assert.ok((result instanceof Buffer));
88
- assert.notEqual(result.length, 0, 'Zero buffer length for custom margin');
89
- }
90
- },
91
- 'and a custom level option': {
92
- topic: function() {
93
- var encoder = new Encoder;
94
- encoder.on('end', this.callback);
95
- // set a custom level option of 'H'
96
- encoder.encode('test', null, { level: 'H' });
97
- },
98
- 'provides PNG data with a custom level': function(result, encoder) {
99
- assert.ok((result instanceof Buffer));
100
- assert.notEqual(result.length, 0, 'Zero buffer length for custom level');
101
- }
102
- },
103
- 'and a custom version option': {
104
- topic: function() {
105
- var encoder = new Encoder;
106
- encoder.on('end', this.callback);
107
- // set a custom version
108
- encoder.encode('test', null, { version: 10 });
109
- },
110
- 'provides PNG data with a different version': function(result, encoder) {
111
- assert.ok((result instanceof Buffer));
112
- assert.notEqual(result.length, 0, 'Zero buffer length for custom version');
113
- }
114
- },
115
- 'and a custom type option': {
116
- topic: function() {
117
- var encoder = new Encoder;
118
- encoder.on('end', this.callback);
119
- // set a custom output
120
- encoder.encode('test', null, { type: 'SVG' });
121
- },
122
- 'provides SVG data' : function(result, encoder) {
123
- assert.ok((result instanceof Buffer));
124
- assert.notEqual(result.length, 0, 'Zero buffer length for custom type');
125
- }
126
- },
127
- 'and an invalid type option': {
128
- topic: function() {
129
- var encoder = new Encoder;
130
- encoder.on('error', this.callback);
131
- // set an incorrect type option
132
- encoder.encode('test', null, { type: 'SPVG' });
133
- },
134
- 'emits an \'error\' event with Error object' : function(result, encoder) {
135
- assert.ok((result instanceof Error), 'Unexpected result emitted with error event');
136
- assert.notEqual(result.message, "");
137
- }
138
- },
139
- 'and an invalid option': {
140
- topic: function() {
141
- var encoder = new Encoder;
142
- encoder.on('error', this.callback);
143
- // set bad option
144
- encoder.encode('test', null, { version: 1000 });
145
- },
146
- 'emits an \'error\' event with Error object': function(result, encoder) {
147
- assert.ok((result instanceof Error), 'Unexpcted result emitted with error event');
148
- assert.notEqual(result.message, "");
149
- }
150
- },
151
- 'and a bad path': {
152
- topic: function() {
153
- var encoder = new Encoder;
154
- encoder.on('error', this.callback);
155
- // set a bad path
156
- encoder.encode('test', 'C:/notwindows/');
157
- },
158
- 'emits an \'error\' event with Error object': function(result, encoder) {
159
- assert.ok((result instanceof Error), 'Unexpcted result emitted with error event');
160
- assert.notEqual(result.message, "");
161
- }
162
- }
163
- },
164
- 'without a provided value': {
165
- topic: function() {
166
- var encoder = new Encoder;
167
- encoder.on('error', this.callback);
168
- encoder.encode();
169
- },
170
- 'emits an \'error\' event with an Error object': function(result, encoder) {
171
- assert.ok((result instanceof Error), 'Unexpcted result emitted with error event');
172
- assert.equal(result.message, "No value specified for encode method");
173
- }
174
- }
175
- }
176
- }).export(module);
package/test/qr.js DELETED
@@ -1,16 +0,0 @@
1
- var vows = require('vows'),
2
- assert = require('assert'),
3
- util = require('util'),
4
- qr = require('../qr');
5
-
6
- vows.describe('QR').addBatch({
7
- 'The QR module': {
8
- topic: qr,
9
- 'exists': function(qr) {
10
- assert.notEqual(qr, undefined, 'QR module is undefined');
11
- },
12
- 'has an encoder object': function(qr) {
13
- assert.notEqual(qr.Encoder, undefined, 'QR Encoder undefined');
14
- }
15
- }
16
- }).export(module);