New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nuintun/qrcode

Package Overview
Dependencies
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nuintun/qrcode - npm Package Compare versions

Comparing version 0.5.3 to 0.6.0

250

es5/qrcode/encoder/QRCode.js

@@ -133,106 +133,21 @@ "use strict";

};
/**
* @public
* @method make
*/
QRCode.prototype.make = function () {
var _a, _b;
var buffer;
var rsBlocks;
var maxDataCount;
var dataList = this.dataList;
var errorCorrectLevel = this.errorCorrectLevel;
if (this.autoVersion) {
for (this.version = 1; this.version <= 40; this.version++) {
_a = QRCode.prepareData(this.version, errorCorrectLevel, dataList), buffer = _a[0], rsBlocks = _a[1], maxDataCount = _a[2];
if (buffer.getLengthInBits() <= maxDataCount)
break;
}
}
else {
_b = QRCode.prepareData(this.version, errorCorrectLevel, dataList), buffer = _b[0], rsBlocks = _b[1], maxDataCount = _b[2];
}
// calc module count
this.moduleCount = this.version * 4 + 17;
// create data
var data = QRCode.createData(buffer, rsBlocks, maxDataCount);
this.makeImpl(false, data, this.getBestMaskPattern(data));
};
QRCode.prototype.getBestMaskPattern = function (data) {
var lowest = 0;
var pattern = 0;
for (var i = 0; i < 8; i++) {
this.makeImpl(true, data, i);
var score = QRUtil.getPenaltyScore(this);
if (i === 0 || lowest > score) {
pattern = i;
lowest = score;
}
}
return pattern;
};
QRCode.prototype.makeImpl = function (test, data, maskPattern) {
// initialize modules
this.modules = [];
for (var row = 0; row < this.moduleCount; row++) {
this.modules[row] = [];
for (var col = 0; col < this.moduleCount; col++) {
this.modules[row][col] = null;
}
}
// setup finder pattern
this.setupFinderPattern(0, 0);
this.setupFinderPattern(this.moduleCount - 7, 0);
this.setupFinderPattern(0, this.moduleCount - 7);
// setup format info
this.setupFormatInfo();
// setup timing pattern
this.setupTimingPattern();
// setup version info
this.setupVersionInfo(test, maskPattern);
// setup alignment pattern
if (this.version >= 7) {
this.setupAlignmentPattern(test);
}
this.mapData(data, maskPattern);
};
QRCode.prototype.mapData = function (data, maskPattern) {
var inc = -1;
var bitIndex = 7;
var byteIndex = 0;
var row = this.moduleCount - 1;
var maskFunc = QRUtil.getMaskFunc(maskPattern);
for (var col = this.moduleCount - 1; col > 0; col -= 2) {
if (col === 6) {
col--;
}
while (true) {
for (var c = 0; c < 2; c++) {
if (this.modules[row][col - c] === null) {
var dark = false;
if (byteIndex < data.length) {
dark = ((data[byteIndex] >>> bitIndex) & 1) === 1;
}
var mask = maskFunc(row, col - c);
if (mask) {
dark = !dark;
}
this.modules[row][col - c] = dark;
if (--bitIndex === -1) {
byteIndex++;
bitIndex = 7;
}
}
QRCode.prototype.setupFinderPattern = function (row, col) {
for (var r = -1; r <= 7; r++) {
for (var c = -1; c <= 7; c++) {
if (row + r <= -1 || this.moduleCount <= row + r || col + c <= -1 || this.moduleCount <= col + c) {
continue;
}
row += inc;
if (row < 0 || this.moduleCount <= row) {
row -= inc;
inc = -inc;
break;
if ((0 <= r && r <= 6 && (c === 0 || c === 6)) ||
(0 <= c && c <= 6 && (r === 0 || r === 6)) ||
(2 <= r && r <= 4 && 2 <= c && c <= 4)) {
this.modules[row + r][col + c] = true;
}
else {
this.modules[row + r][col + c] = false;
}
}
}
};
QRCode.prototype.setupFormatInfo = function () {
var pos = QRUtil.getPatternPosition(this.version);
QRCode.prototype.setupAlignmentPattern = function () {
var pos = QRUtil.getAlignmentPattern(this.version);
var length = pos.length;

@@ -259,19 +174,2 @@ for (var i = 0; i < length; i++) {

};
QRCode.prototype.setupFinderPattern = function (row, col) {
for (var r = -1; r <= 7; r++) {
for (var c = -1; c <= 7; c++) {
if (row + r <= -1 || this.moduleCount <= row + r || col + c <= -1 || this.moduleCount <= col + c) {
continue;
}
if ((0 <= r && r <= 6 && (c === 0 || c === 6)) ||
(0 <= c && c <= 6 && (r === 0 || r === 6)) ||
(2 <= r && r <= 4 && 2 <= c && c <= 4)) {
this.modules[row + r][col + c] = true;
}
else {
this.modules[row + r][col + c] = false;
}
}
}
};
QRCode.prototype.setupTimingPattern = function () {

@@ -290,11 +188,3 @@ for (var i = 8; i < this.moduleCount - 8; i++) {

};
QRCode.prototype.setupAlignmentPattern = function (test) {
var bits = QRUtil.getBCHVersion(this.version);
for (var i = 0; i < 18; i++) {
var mod = !test && ((bits >> i) & 1) === 1;
this.modules[(i / 3) >>> 0][(i % 3) + this.moduleCount - 8 - 3] = mod;
this.modules[(i % 3) + this.moduleCount - 8 - 3][(i / 3) >>> 0] = mod;
}
};
QRCode.prototype.setupVersionInfo = function (test, maskPattern) {
QRCode.prototype.setupFormatInfo = function (test, maskPattern) {
var data = (this.errorCorrectLevel << 3) | maskPattern;

@@ -328,2 +218,10 @@ var bits = QRUtil.getBCHVersionInfo(data);

};
QRCode.prototype.setupVersionInfo = function (test) {
var bits = QRUtil.getBCHVersion(this.version);
for (var i = 0; i < 18; i++) {
var mod = !test && ((bits >> i) & 1) === 1;
this.modules[(i / 3) >>> 0][(i % 3) + this.moduleCount - 8 - 3] = mod;
this.modules[(i % 3) + this.moduleCount - 8 - 3][(i / 3) >>> 0] = mod;
}
};
QRCode.prepareData = function (version, errorCorrectLevel, dataList) {

@@ -422,4 +320,106 @@ var dLength = dataList.length;

};
QRCode.prototype.mapData = function (data, maskPattern) {
var inc = -1;
var bitIndex = 7;
var byteIndex = 0;
var row = this.moduleCount - 1;
var maskFunc = QRUtil.getMaskFunc(maskPattern);
for (var col = this.moduleCount - 1; col > 0; col -= 2) {
if (col === 6) {
col--;
}
while (true) {
for (var c = 0; c < 2; c++) {
if (this.modules[row][col - c] === null) {
var dark = false;
if (byteIndex < data.length) {
dark = ((data[byteIndex] >>> bitIndex) & 1) === 1;
}
var mask = maskFunc(row, col - c);
if (mask) {
dark = !dark;
}
this.modules[row][col - c] = dark;
if (--bitIndex === -1) {
byteIndex++;
bitIndex = 7;
}
}
}
row += inc;
if (row < 0 || this.moduleCount <= row) {
row -= inc;
inc = -inc;
break;
}
}
}
};
QRCode.prototype.makeImpl = function (test, data, maskPattern) {
// initialize modules
this.modules = [];
for (var row = 0; row < this.moduleCount; row++) {
this.modules[row] = [];
for (var col = 0; col < this.moduleCount; col++) {
this.modules[row][col] = null;
}
}
// setup finder pattern
this.setupFinderPattern(0, 0);
this.setupFinderPattern(this.moduleCount - 7, 0);
this.setupFinderPattern(0, this.moduleCount - 7);
// setup alignment pattern
this.setupAlignmentPattern();
// setup timing pattern
this.setupTimingPattern();
// setup format info
this.setupFormatInfo(test, maskPattern);
// setup version info
if (this.version >= 7) {
this.setupVersionInfo(test);
}
this.mapData(data, maskPattern);
};
QRCode.prototype.getBestMaskPattern = function (data) {
var minimum = 0;
var pattern = 0;
for (var i = 0; i < 8; i++) {
this.makeImpl(true, data, i);
var score = QRUtil.getPenaltyScore(this);
if (i === 0 || minimum > score) {
pattern = i;
minimum = score;
}
}
return pattern;
};
/**
* @public
* @method make
*/
QRCode.prototype.make = function () {
var _a, _b;
var buffer;
var rsBlocks;
var maxDataCount;
var dataList = this.dataList;
var errorCorrectLevel = this.errorCorrectLevel;
if (this.autoVersion) {
for (this.version = 1; this.version <= 40; this.version++) {
_a = QRCode.prepareData(this.version, errorCorrectLevel, dataList), buffer = _a[0], rsBlocks = _a[1], maxDataCount = _a[2];
if (buffer.getLengthInBits() <= maxDataCount)
break;
}
}
else {
_b = QRCode.prepareData(this.version, errorCorrectLevel, dataList), buffer = _b[0], rsBlocks = _b[1], maxDataCount = _b[2];
}
// calc module count
this.moduleCount = this.version * 4 + 17;
// create data
var data = QRCode.createData(buffer, rsBlocks, maxDataCount);
this.makeImpl(false, data, this.getBestMaskPattern(data));
};
/**
* @public
* @method toDataURL

@@ -426,0 +426,0 @@ * @param {number} moduleSize

@@ -11,3 +11,3 @@ "use strict";

var MaskPattern_1 = require("./MaskPattern");
var PATTERN_POSITION_TABLE = [
var ALIGNMENT_PATTERN_TABLE = [
[],

@@ -57,6 +57,6 @@ [6, 18],

exports.G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0);
function getPatternPosition(version) {
return PATTERN_POSITION_TABLE[version - 1];
function getAlignmentPattern(version) {
return ALIGNMENT_PATTERN_TABLE[version - 1];
}
exports.getPatternPosition = getPatternPosition;
exports.getAlignmentPattern = getAlignmentPattern;
function getErrorCorrectPolynomial(errorCorrectLength) {

@@ -63,0 +63,0 @@ var e = new Polynomial_1.default([1]);

@@ -131,106 +131,21 @@ /**

};
/**
* @public
* @method make
*/
QRCode.prototype.make = function () {
var _a, _b;
var buffer;
var rsBlocks;
var maxDataCount;
var dataList = this.dataList;
var errorCorrectLevel = this.errorCorrectLevel;
if (this.autoVersion) {
for (this.version = 1; this.version <= 40; this.version++) {
_a = QRCode.prepareData(this.version, errorCorrectLevel, dataList), buffer = _a[0], rsBlocks = _a[1], maxDataCount = _a[2];
if (buffer.getLengthInBits() <= maxDataCount)
break;
}
}
else {
_b = QRCode.prepareData(this.version, errorCorrectLevel, dataList), buffer = _b[0], rsBlocks = _b[1], maxDataCount = _b[2];
}
// calc module count
this.moduleCount = this.version * 4 + 17;
// create data
var data = QRCode.createData(buffer, rsBlocks, maxDataCount);
this.makeImpl(false, data, this.getBestMaskPattern(data));
};
QRCode.prototype.getBestMaskPattern = function (data) {
var lowest = 0;
var pattern = 0;
for (var i = 0; i < 8; i++) {
this.makeImpl(true, data, i);
var score = QRUtil.getPenaltyScore(this);
if (i === 0 || lowest > score) {
pattern = i;
lowest = score;
}
}
return pattern;
};
QRCode.prototype.makeImpl = function (test, data, maskPattern) {
// initialize modules
this.modules = [];
for (var row = 0; row < this.moduleCount; row++) {
this.modules[row] = [];
for (var col = 0; col < this.moduleCount; col++) {
this.modules[row][col] = null;
}
}
// setup finder pattern
this.setupFinderPattern(0, 0);
this.setupFinderPattern(this.moduleCount - 7, 0);
this.setupFinderPattern(0, this.moduleCount - 7);
// setup format info
this.setupFormatInfo();
// setup timing pattern
this.setupTimingPattern();
// setup version info
this.setupVersionInfo(test, maskPattern);
// setup alignment pattern
if (this.version >= 7) {
this.setupAlignmentPattern(test);
}
this.mapData(data, maskPattern);
};
QRCode.prototype.mapData = function (data, maskPattern) {
var inc = -1;
var bitIndex = 7;
var byteIndex = 0;
var row = this.moduleCount - 1;
var maskFunc = QRUtil.getMaskFunc(maskPattern);
for (var col = this.moduleCount - 1; col > 0; col -= 2) {
if (col === 6) {
col--;
}
while (true) {
for (var c = 0; c < 2; c++) {
if (this.modules[row][col - c] === null) {
var dark = false;
if (byteIndex < data.length) {
dark = ((data[byteIndex] >>> bitIndex) & 1) === 1;
}
var mask = maskFunc(row, col - c);
if (mask) {
dark = !dark;
}
this.modules[row][col - c] = dark;
if (--bitIndex === -1) {
byteIndex++;
bitIndex = 7;
}
}
QRCode.prototype.setupFinderPattern = function (row, col) {
for (var r = -1; r <= 7; r++) {
for (var c = -1; c <= 7; c++) {
if (row + r <= -1 || this.moduleCount <= row + r || col + c <= -1 || this.moduleCount <= col + c) {
continue;
}
row += inc;
if (row < 0 || this.moduleCount <= row) {
row -= inc;
inc = -inc;
break;
if ((0 <= r && r <= 6 && (c === 0 || c === 6)) ||
(0 <= c && c <= 6 && (r === 0 || r === 6)) ||
(2 <= r && r <= 4 && 2 <= c && c <= 4)) {
this.modules[row + r][col + c] = true;
}
else {
this.modules[row + r][col + c] = false;
}
}
}
};
QRCode.prototype.setupFormatInfo = function () {
var pos = QRUtil.getPatternPosition(this.version);
QRCode.prototype.setupAlignmentPattern = function () {
var pos = QRUtil.getAlignmentPattern(this.version);
var length = pos.length;

@@ -257,19 +172,2 @@ for (var i = 0; i < length; i++) {

};
QRCode.prototype.setupFinderPattern = function (row, col) {
for (var r = -1; r <= 7; r++) {
for (var c = -1; c <= 7; c++) {
if (row + r <= -1 || this.moduleCount <= row + r || col + c <= -1 || this.moduleCount <= col + c) {
continue;
}
if ((0 <= r && r <= 6 && (c === 0 || c === 6)) ||
(0 <= c && c <= 6 && (r === 0 || r === 6)) ||
(2 <= r && r <= 4 && 2 <= c && c <= 4)) {
this.modules[row + r][col + c] = true;
}
else {
this.modules[row + r][col + c] = false;
}
}
}
};
QRCode.prototype.setupTimingPattern = function () {

@@ -288,11 +186,3 @@ for (var i = 8; i < this.moduleCount - 8; i++) {

};
QRCode.prototype.setupAlignmentPattern = function (test) {
var bits = QRUtil.getBCHVersion(this.version);
for (var i = 0; i < 18; i++) {
var mod = !test && ((bits >> i) & 1) === 1;
this.modules[(i / 3) >>> 0][(i % 3) + this.moduleCount - 8 - 3] = mod;
this.modules[(i % 3) + this.moduleCount - 8 - 3][(i / 3) >>> 0] = mod;
}
};
QRCode.prototype.setupVersionInfo = function (test, maskPattern) {
QRCode.prototype.setupFormatInfo = function (test, maskPattern) {
var data = (this.errorCorrectLevel << 3) | maskPattern;

@@ -326,2 +216,10 @@ var bits = QRUtil.getBCHVersionInfo(data);

};
QRCode.prototype.setupVersionInfo = function (test) {
var bits = QRUtil.getBCHVersion(this.version);
for (var i = 0; i < 18; i++) {
var mod = !test && ((bits >> i) & 1) === 1;
this.modules[(i / 3) >>> 0][(i % 3) + this.moduleCount - 8 - 3] = mod;
this.modules[(i % 3) + this.moduleCount - 8 - 3][(i / 3) >>> 0] = mod;
}
};
QRCode.prepareData = function (version, errorCorrectLevel, dataList) {

@@ -420,4 +318,106 @@ var dLength = dataList.length;

};
QRCode.prototype.mapData = function (data, maskPattern) {
var inc = -1;
var bitIndex = 7;
var byteIndex = 0;
var row = this.moduleCount - 1;
var maskFunc = QRUtil.getMaskFunc(maskPattern);
for (var col = this.moduleCount - 1; col > 0; col -= 2) {
if (col === 6) {
col--;
}
while (true) {
for (var c = 0; c < 2; c++) {
if (this.modules[row][col - c] === null) {
var dark = false;
if (byteIndex < data.length) {
dark = ((data[byteIndex] >>> bitIndex) & 1) === 1;
}
var mask = maskFunc(row, col - c);
if (mask) {
dark = !dark;
}
this.modules[row][col - c] = dark;
if (--bitIndex === -1) {
byteIndex++;
bitIndex = 7;
}
}
}
row += inc;
if (row < 0 || this.moduleCount <= row) {
row -= inc;
inc = -inc;
break;
}
}
}
};
QRCode.prototype.makeImpl = function (test, data, maskPattern) {
// initialize modules
this.modules = [];
for (var row = 0; row < this.moduleCount; row++) {
this.modules[row] = [];
for (var col = 0; col < this.moduleCount; col++) {
this.modules[row][col] = null;
}
}
// setup finder pattern
this.setupFinderPattern(0, 0);
this.setupFinderPattern(this.moduleCount - 7, 0);
this.setupFinderPattern(0, this.moduleCount - 7);
// setup alignment pattern
this.setupAlignmentPattern();
// setup timing pattern
this.setupTimingPattern();
// setup format info
this.setupFormatInfo(test, maskPattern);
// setup version info
if (this.version >= 7) {
this.setupVersionInfo(test);
}
this.mapData(data, maskPattern);
};
QRCode.prototype.getBestMaskPattern = function (data) {
var minimum = 0;
var pattern = 0;
for (var i = 0; i < 8; i++) {
this.makeImpl(true, data, i);
var score = QRUtil.getPenaltyScore(this);
if (i === 0 || minimum > score) {
pattern = i;
minimum = score;
}
}
return pattern;
};
/**
* @public
* @method make
*/
QRCode.prototype.make = function () {
var _a, _b;
var buffer;
var rsBlocks;
var maxDataCount;
var dataList = this.dataList;
var errorCorrectLevel = this.errorCorrectLevel;
if (this.autoVersion) {
for (this.version = 1; this.version <= 40; this.version++) {
_a = QRCode.prepareData(this.version, errorCorrectLevel, dataList), buffer = _a[0], rsBlocks = _a[1], maxDataCount = _a[2];
if (buffer.getLengthInBits() <= maxDataCount)
break;
}
}
else {
_b = QRCode.prepareData(this.version, errorCorrectLevel, dataList), buffer = _b[0], rsBlocks = _b[1], maxDataCount = _b[2];
}
// calc module count
this.moduleCount = this.version * 4 + 17;
// create data
var data = QRCode.createData(buffer, rsBlocks, maxDataCount);
this.makeImpl(false, data, this.getBestMaskPattern(data));
};
/**
* @public
* @method toDataURL

@@ -424,0 +424,0 @@ * @param {number} moduleSize

@@ -9,3 +9,3 @@ /**

import MaskPattern from './MaskPattern';
var PATTERN_POSITION_TABLE = [
var ALIGNMENT_PATTERN_TABLE = [
[],

@@ -55,4 +55,4 @@ [6, 18],

export var G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0);
export function getPatternPosition(version) {
return PATTERN_POSITION_TABLE[version - 1];
export function getAlignmentPattern(version) {
return ALIGNMENT_PATTERN_TABLE[version - 1];
}

@@ -59,0 +59,0 @@ export function getErrorCorrectPolynomial(errorCorrectLength) {

{
"name": "@nuintun/qrcode",
"version": "0.5.3",
"version": "0.6.0",
"description": "QRCode encode and decode library.",

@@ -5,0 +5,0 @@ "main": "es5/index.js",

@@ -71,14 +71,6 @@ /**

isDark(row: number, col: number): boolean;
/**
* @public
* @method make
*/
make(): void;
private getBestMaskPattern;
private makeImpl;
private mapData;
private setupFormatInfo;
private setupFinderPattern;
private setupAlignmentPattern;
private setupTimingPattern;
private setupAlignmentPattern;
private setupFormatInfo;
private setupVersionInfo;

@@ -88,4 +80,12 @@ private static prepareData;

private static createData;
private mapData;
private makeImpl;
private getBestMaskPattern;
/**
* @public
* @method make
*/
make(): void;
/**
* @public
* @method toDataURL

@@ -92,0 +92,0 @@ * @param {number} moduleSize

@@ -12,3 +12,3 @@ /**

export declare const G18: number;
export declare function getPatternPosition(version: number): number[];
export declare function getAlignmentPattern(version: number): number[];
export declare function getErrorCorrectPolynomial(errorCorrectLength: number): Polynomial;

@@ -15,0 +15,0 @@ export declare function getMaskFunc(maskPattern: number): maskFunc;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc