Skip to content

Commit

Permalink
Release v3.5.0-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
lindell committed Sep 24, 2016
1 parent d9bd2a2 commit 44d05c7
Show file tree
Hide file tree
Showing 38 changed files with 1,057 additions and 739 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ Download or get the CDN link to the script:

| Name | Supported barcodes | Size (gzip) | CDN / Download |
|------|--------------------|:-----------:|---------------:|
| *All* | *All the barcodes!* | *7.9 kB* | *[JsBarcode.all.min.js][1]* |
| CODE128 | CODE128 (auto and force mode) | 5.3 kB | [JsBarcode.code128.min.js][2] |
| *All* | *All the barcodes!* | *8.1 kB* | *[JsBarcode.all.min.js][1]* |
| CODE128 | CODE128 (auto and force mode) | 5.4 kB | [JsBarcode.code128.min.js][2] |
| CODE39 | CODE39 | 4.6 kB | [JsBarcode.code39.min.js][3] |
| EAN / UPC | EAN-13, EAN-8, EAN-5, EAN-2, UPC (A) | 5.1 kB | [JsBarcode.ean-upc.min.js][4] |
| ITF-14 | ITF-14 | 4.3 kB | [JsBarcode.itf-14.min.js][5] |
| EAN / UPC | EAN-13, EAN-8, EAN-5, EAN-2, UPC (A) | 5.2 kB | [JsBarcode.ean-upc.min.js][4] |
| ITF-14 | ITF-14 | 4.4 kB | [JsBarcode.itf-14.min.js][5] |
| ITF | ITF | 4.3 kB | [JsBarcode.itf.min.js][6] |
| MSI | MSI, MSI10, MSI11, MSI1010, MSI1110 | 4.5 kB | [JsBarcode.msi.min.js][7] |
| Pharmacode | Pharmacode | 4.1 kB | [JsBarcode.pharmacode.min.js][8] |
| MSI | MSI, MSI10, MSI11, MSI1010, MSI1110 | 4.6 kB | [JsBarcode.msi.min.js][7] |
| Pharmacode | Pharmacode | 4.2 kB | [JsBarcode.pharmacode.min.js][8] |

### Step 2:
Include the script in your code:
Expand Down
2 changes: 1 addition & 1 deletion bin/JsBarcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var _ErrorHandler2 = _interopRequireDefault(_ErrorHandler);

var _exceptions = require('./exceptions/exceptions.js');

var _defaults = require('./defaults/defaults.js');
var _defaults = require('./options/defaults.js');

var _defaults2 = _interopRequireDefault(_defaults);

Expand Down
17 changes: 17 additions & 0 deletions bin/barcodes/Barcode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Barcode = function Barcode(data, options) {
_classCallCheck(this, Barcode);

this.data = data;
this.text = options.text || data;
this.options = options;
};

exports.default = Barcode;
37 changes: 24 additions & 13 deletions bin/barcodes/CODE128/CODE128.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,38 @@ Object.defineProperty(exports, "__esModule", {
value: true
});

var _Barcode2 = require("../Barcode.js");

var _Barcode3 = _interopRequireDefault(_Barcode2);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

// This is the master class, it does require the start code to be
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // This is the master class, it does require the start code to be
// included in the string
var CODE128 = function () {
function CODE128(string) {

var CODE128 = function (_Barcode) {
_inherits(CODE128, _Barcode);

function CODE128(data, options) {
_classCallCheck(this, CODE128);

// Fill the bytes variable with the ascii codes of string
this.bytes = [];
for (var i = 0; i < string.length; ++i) {
this.bytes.push(string.charCodeAt(i));
}
var _this = _possibleConstructorReturn(this, _Barcode.call(this, data.substring(1), options));

// First element should be startcode, remove that
this.string = string.substring(1);
_this.bytes = [];
for (var i = 0; i < data.length; ++i) {
_this.bytes.push(data.charCodeAt(i));
}

// Data for each character, the last characters will not be encoded but are used for error correction
// Numbers encode to (n + 1000) -> binary; 740 -> (740 + 1000).toString(2) -> "11011001100"
this.encodings = [// + 1000
_this.encodings = [// + 1000
740, 644, 638, 176, 164, 100, 224, 220, 124, 608, 604, 572, 436, 244, 230, 484, 260, 254, 650, 628, 614, 764, 652, 902, 868, 836, 830, 892, 844, 842, 752, 734, 590, 304, 112, 94, 416, 128, 122, 672, 576, 570, 464, 422, 134, 496, 478, 142, 910, 678, 582, 768, 762, 774, 880, 862, 814, 896, 890, 818, 914, 602, 930, 328, 292, 200, 158, 68, 62, 424, 412, 232, 218, 76, 74, 554, 616, 978, 556, 146, 340, 212, 182, 508, 268, 266, 956, 940, 938, 758, 782, 974, 400, 310, 118, 512, 506, 960, 954, 502, 518, 886, 966, /* Start codes */668, 680, 692, 5379];
return _this;
}

// The public encoding function
Expand All @@ -46,7 +57,7 @@ var CODE128 = function () {
}

return {
text: this.string.replace(/[^\x20-\x7E]/g, ""),
text: this.text.replace(/[^\x20-\x7E]/g, ""),
data:
// Add the start bits
this.getEncoding(startIndex) +
Expand All @@ -68,7 +79,7 @@ var CODE128 = function () {

CODE128.prototype.valid = function valid() {
// ASCII value ranges 0-127, 200-211
return this.string.search(/^[\x00-\x7F\xC8-\xD3]+$/) !== -1;
return this.data.search(/^[\x00-\x7F\xC8-\xD3]+$/) !== -1;
};

CODE128.prototype.nextA = function nextA(bytes, depth) {
Expand Down Expand Up @@ -215,6 +226,6 @@ var CODE128 = function () {
};

return CODE128;
}();
}(_Barcode3.default);

exports.default = CODE128;
6 changes: 3 additions & 3 deletions bin/barcodes/CODE128/CODE128A.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
var CODE128A = function (_CODE) {
_inherits(CODE128A, _CODE);

function CODE128A(string) {
function CODE128A(string, options) {
_classCallCheck(this, CODE128A);

return _possibleConstructorReturn(this, _CODE.call(this, String.fromCharCode(208) + string));
return _possibleConstructorReturn(this, _CODE.call(this, String.fromCharCode(208) + string, options));
}

CODE128A.prototype.valid = function valid() {
return this.string.search(/^[\x00-\x5F\xC8-\xCF]+$/) !== -1;
return this.data.search(/^[\x00-\x5F\xC8-\xCF]+$/) !== -1;
};

return CODE128A;
Expand Down
6 changes: 3 additions & 3 deletions bin/barcodes/CODE128/CODE128B.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
var CODE128B = function (_CODE) {
_inherits(CODE128B, _CODE);

function CODE128B(string) {
function CODE128B(string, options) {
_classCallCheck(this, CODE128B);

return _possibleConstructorReturn(this, _CODE.call(this, String.fromCharCode(209) + string));
return _possibleConstructorReturn(this, _CODE.call(this, String.fromCharCode(209) + string, options));
}

CODE128B.prototype.valid = function valid() {
return this.string.search(/^[\x20-\x7F\xC8-\xCF]+$/) !== -1;
return this.data.search(/^[\x20-\x7F\xC8-\xCF]+$/) !== -1;
};

return CODE128B;
Expand Down
6 changes: 3 additions & 3 deletions bin/barcodes/CODE128/CODE128C.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
var CODE128C = function (_CODE) {
_inherits(CODE128C, _CODE);

function CODE128C(string) {
function CODE128C(string, options) {
_classCallCheck(this, CODE128C);

return _possibleConstructorReturn(this, _CODE.call(this, String.fromCharCode(210) + string));
return _possibleConstructorReturn(this, _CODE.call(this, String.fromCharCode(210) + string, options));
}

CODE128C.prototype.valid = function valid() {
return this.string.search(/^(\xCF*[0-9]{2}\xCF*)+$/) !== -1;
return this.data.search(/^(\xCF*[0-9]{2}\xCF*)+$/) !== -1;
};

return CODE128C;
Expand Down
8 changes: 4 additions & 4 deletions bin/barcodes/CODE128/CODE128_AUTO.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
var CODE128AUTO = function (_CODE) {
_inherits(CODE128AUTO, _CODE);

function CODE128AUTO(string) {
function CODE128AUTO(data, options) {
_classCallCheck(this, CODE128AUTO);

// ASCII value ranges 0-127, 200-211
if (string.search(/^[\x00-\x7F\xC8-\xD3]+$/) !== -1) {
var _this = _possibleConstructorReturn(this, _CODE.call(this, autoSelectModes(string)));
if (data.search(/^[\x00-\x7F\xC8-\xD3]+$/) !== -1) {
var _this = _possibleConstructorReturn(this, _CODE.call(this, autoSelectModes(data), options));
} else {
var _this = _possibleConstructorReturn(this, _CODE.call(this, string));
var _this = _possibleConstructorReturn(this, _CODE.call(this, data, options));
}
return _possibleConstructorReturn(_this);
}
Expand Down
118 changes: 62 additions & 56 deletions bin/barcodes/CODE39/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,91 +3,97 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.CODE39 = undefined;

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

// Encoding documentation:
// https://en.wikipedia.org/wiki/Code_39#Encoding

var CODE39 = function () {
function CODE39(string, options) {
_classCallCheck(this, CODE39);
var _Barcode2 = require("../Barcode.js");

this.string = string.toUpperCase();
var _Barcode3 = _interopRequireDefault(_Barcode2);

// Enable mod43 checksum?
this.mod43Enabled = options.mod43 || false;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// All characters. The position in the array is the (checksum) value
this.characters = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "-", ".", " ", "$", "/", "+", "%", "*"];
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

// The decimal representation of the characters, is converted to the
// corresponding binary with the getEncoding function
this.encodings = [20957, 29783, 23639, 30485, 20951, 29813, 23669, 20855, 29789, 23645, 29975, 23831, 30533, 22295, 30149, 24005, 21623, 29981, 23837, 22301, 30023, 23879, 30545, 22343, 30161, 24017, 21959, 30065, 23921, 22385, 29015, 18263, 29141, 17879, 29045, 18293, 17783, 29021, 18269, 17477, 17489, 17681, 20753, 35770];
}
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

// Get the binary representation of a character by converting the encodings
// from decimal to binary
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
// https://en.wikipedia.org/wiki/Code_39#Encoding

var CODE39 = function (_Barcode) {
_inherits(CODE39, _Barcode);

CODE39.prototype.getEncoding = function getEncoding(character) {
return this.getBinary(this.characterValue(character));
};
function CODE39(data, options) {
_classCallCheck(this, CODE39);

CODE39.prototype.getBinary = function getBinary(characterValue) {
return this.encodings[characterValue].toString(2);
};
data = data.toUpperCase();

CODE39.prototype.getCharacter = function getCharacter(characterValue) {
return this.characters[characterValue];
};
// Calculate mod43 checksum if enabled
if (options.mod43) {
data += getCharacter(mod43checksum(data));
}

CODE39.prototype.characterValue = function characterValue(character) {
return this.characters.indexOf(character);
};
return _possibleConstructorReturn(this, _Barcode.call(this, data, options));
}

CODE39.prototype.encode = function encode() {
var string = this.string;

// First character is always a *
var result = this.getEncoding("*");
var result = getEncoding("*");

// Take every character and add the binary representation to the result
for (var i = 0; i < this.string.length; i++) {
result += this.getEncoding(this.string[i]) + "0";
}

// Calculate mod43 checksum if enabled
if (this.mod43Enabled) {
var checksum = this.mod43checksum();
result += this.getBinary(checksum) + "0";
string += this.getCharacter(checksum);
for (var i = 0; i < this.data.length; i++) {
result += getEncoding(this.data[i]) + "0";
}

// Last character is always a *
result += this.getEncoding("*");
result += getEncoding("*");

return {
data: result,
text: string
text: this.text
};
};

CODE39.prototype.valid = function valid() {
return this.string.search(/^[0-9A-Z\-\.\ \$\/\+\%]+$/) !== -1;
return this.data.search(/^[0-9A-Z\-\.\ \$\/\+\%]+$/) !== -1;
};

CODE39.prototype.mod43checksum = function mod43checksum() {
var checksum = 0;
for (var i = 0; i < this.string.length; i++) {
checksum += this.characterValue(this.string[i]);
}
return CODE39;
}(_Barcode3.default);

checksum = checksum % 43;
return checksum;
};
// All characters. The position in the array is the (checksum) value

return CODE39;
}();

var characters = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "-", ".", " ", "$", "/", "+", "%", "*"];

// The decimal representation of the characters, is converted to the
// corresponding binary with the getEncoding function
var encodings = [20957, 29783, 23639, 30485, 20951, 29813, 23669, 20855, 29789, 23645, 29975, 23831, 30533, 22295, 30149, 24005, 21623, 29981, 23837, 22301, 30023, 23879, 30545, 22343, 30161, 24017, 21959, 30065, 23921, 22385, 29015, 18263, 29141, 17879, 29045, 18293, 17783, 29021, 18269, 17477, 17489, 17681, 20753, 35770];

// Get the binary representation of a character by converting the encodings
// from decimal to binary
function getEncoding(character) {
return getBinary(characterValue(character));
}

function getBinary(characterValue) {
return encodings[characterValue].toString(2);
}

function getCharacter(characterValue) {
return characters[characterValue];
}

function characterValue(character) {
return characters.indexOf(character);
}

function mod43checksum(data) {
var checksum = 0;
for (var i = 0; i < data.length; i++) {
checksum += characterValue(data[i]);
}

checksum = checksum % 43;
return checksum;
}

exports.CODE39 = CODE39;

0 comments on commit 44d05c7

Please sign in to comment.