Skip to content

Commit

Permalink
📦 Release v3.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lindell committed May 26, 2017
1 parent bf4a4af commit 08b588a
Show file tree
Hide file tree
Showing 47 changed files with 3,019 additions and 2,352 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ Download or get the CDN link to the script:

| Name | Supported barcodes | Size (gzip) | CDN / Download |
|------|--------------------|:-----------:|---------------:|
| *All* | *All the barcodes!* | *8.8 kB* | *[JsBarcode.all.min.js][1]* |
| CODE128 | CODE128 (auto and force mode) | 5.9 kB | [JsBarcode.code128.min.js][2] |
| CODE39 | CODE39 | 4.8 kB | [JsBarcode.code39.min.js][3] |
| EAN / UPC | EAN-13, EAN-8, EAN-5, EAN-2, UPC (A) | 5.6 kB | [JsBarcode.ean-upc.min.js][4] |
| ITF-14 | ITF-14 | 4.6 kB | [JsBarcode.itf-14.min.js][5] |
| ITF | ITF | 4.6 kB | [JsBarcode.itf.min.js][6] |
| MSI | MSI, MSI10, MSI11, MSI1010, MSI1110 | 4.8 kB | [JsBarcode.msi.min.js][7] |
| Pharmacode | Pharmacode | 4.5 kB | [JsBarcode.pharmacode.min.js][8] |
| Codabar | Codabar | 4.6 kB | [JsBarcode.codabar.min.js][9] |
| *All* | *All the barcodes!* | *9.6 kB* | *[JsBarcode.all.min.js][1]* |
| CODE128 | CODE128 (auto and force mode) | 6 kB | [JsBarcode.code128.min.js][2] |
| CODE39 | CODE39 | 5 kB | [JsBarcode.code39.min.js][3] |
| EAN / UPC | EAN-13, EAN-8, EAN-5, EAN-2, UPC (A) | 6.2 kB | [JsBarcode.ean-upc.min.js][4] |
| ITF-14 | ITF-14 | 4.8 kB | [JsBarcode.itf-14.min.js][5] |
| ITF | ITF | 4.7 kB | [JsBarcode.itf.min.js][6] |
| MSI | MSI, MSI10, MSI11, MSI1010, MSI1110 | 4.9 kB | [JsBarcode.msi.min.js][7] |
| Pharmacode | Pharmacode | 4.6 kB | [JsBarcode.pharmacode.min.js][8] |
| Codabar | Codabar | 4.8 kB | [JsBarcode.codabar.min.js][9] |

### 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 @@ -156,7 +156,7 @@ API.prototype.options = function (options) {

// Will create a blank space (usually in between barcodes)
API.prototype.blank = function (size) {
var zeroes = "0".repeat(size);
var zeroes = new Array(size + 1).join("0");
this._encodings.push({ data: zeroes });
return this;
};
Expand Down
175 changes: 92 additions & 83 deletions bin/barcodes/CODE128/CODE128.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

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

var _Barcode3 = _interopRequireDefault(_Barcode2);
Expand All @@ -27,114 +29,121 @@ var CODE128 = function (_Barcode) {
_classCallCheck(this, CODE128);

// Get array of ascii codes from data
var _this = _possibleConstructorReturn(this, _Barcode.call(this, data.substring(1), options));
var _this = _possibleConstructorReturn(this, (CODE128.__proto__ || Object.getPrototypeOf(CODE128)).call(this, data.substring(1), options));

_this.bytes = data.split('').map(function (char) {
return char.charCodeAt(0);
});
return _this;
}

CODE128.prototype.valid = function valid() {
// ASCII value ranges 0-127, 200-211
return (/^[\x00-\x7F\xC8-\xD3]+$/.test(this.data)
);
};
_createClass(CODE128, [{
key: 'valid',
value: function valid() {
// ASCII value ranges 0-127, 200-211
return (/^[\x00-\x7F\xC8-\xD3]+$/.test(this.data)
);
}

// The public encoding function
// The public encoding function

}, {
key: 'encode',
value: function encode() {
var bytes = this.bytes;
// Remove the start code from the bytes and set its index
var startIndex = bytes.shift() - 105;
// Get start set by index
var startSet = _constants.SET_BY_CODE[startIndex];

CODE128.prototype.encode = function encode() {
var bytes = this.bytes;
// Remove the start code from the bytes and set its index
var startIndex = bytes.shift() - 105;
// Get start set by index
var startSet = _constants.SET_BY_CODE[startIndex];
if (startSet === undefined) {
throw new RangeError('The encoding does not start with a start character.');
}

if (startSet === undefined) {
throw new RangeError('The encoding does not start with a start character.');
// Start encode with the right type
var encodingResult = CODE128.next(bytes, 1, startSet);

return {
text: this.text === this.data ? this.text.replace(/[^\x20-\x7E]/g, '') : this.text,
data:
// Add the start bits
CODE128.getBar(startIndex) +
// Add the encoded bits
encodingResult.result +
// Add the checksum
CODE128.getBar((encodingResult.checksum + startIndex) % _constants.MODULO) +
// Add the end bits
CODE128.getBar(_constants.STOP)
};
}

// Start encode with the right type
var encodingResult = CODE128.next(bytes, 1, startSet);

return {
text: this.text === this.data ? this.text.replace(/[^\x20-\x7E]/g, '') : this.text,
data:
// Add the start bits
CODE128.getBar(startIndex) +
// Add the encoded bits
encodingResult.result +
// Add the checksum
CODE128.getBar((encodingResult.checksum + startIndex) % _constants.MODULO) +
// Add the end bits
CODE128.getBar(_constants.STOP)
};
};

// Get a bar symbol by index


CODE128.getBar = function getBar(index) {
return _constants.BARS[index] ? _constants.BARS[index].toString() : '';
};

// Correct an index by a set and shift it from the bytes array


CODE128.correctIndex = function correctIndex(bytes, set) {
if (set === _constants.SET_A) {
var charCode = bytes.shift();
return charCode < 32 ? charCode + 64 : charCode - 32;
} else if (set === _constants.SET_B) {
return bytes.shift() - 32;
} else {
return (bytes.shift() - 48) * 10 + bytes.shift() - 48;
// Get a bar symbol by index

}], [{
key: 'getBar',
value: function getBar(index) {
return _constants.BARS[index] ? _constants.BARS[index].toString() : '';
}
};

CODE128.next = function next(bytes, pos, set) {
if (!bytes.length) {
return { result: '', checksum: 0 };
// Correct an index by a set and shift it from the bytes array

}, {
key: 'correctIndex',
value: function correctIndex(bytes, set) {
if (set === _constants.SET_A) {
var charCode = bytes.shift();
return charCode < 32 ? charCode + 64 : charCode - 32;
} else if (set === _constants.SET_B) {
return bytes.shift() - 32;
} else {
return (bytes.shift() - 48) * 10 + bytes.shift() - 48;
}
}
}, {
key: 'next',
value: function next(bytes, pos, set) {
if (!bytes.length) {
return { result: '', checksum: 0 };
}

var nextCode = void 0,
index = void 0;
var nextCode = void 0,
index = void 0;

// Special characters
if (bytes[0] >= 200) {
index = bytes.shift() - 105;
var nextSet = _constants.SWAP[index];
// Special characters
if (bytes[0] >= 200) {
index = bytes.shift() - 105;
var nextSet = _constants.SWAP[index];

// Swap to other set
if (nextSet !== undefined) {
nextCode = CODE128.next(bytes, pos + 1, nextSet);
// Swap to other set
if (nextSet !== undefined) {
nextCode = CODE128.next(bytes, pos + 1, nextSet);
}
// Continue on current set but encode a special character
else {
// Shift
if ((set === _constants.SET_A || set === _constants.SET_B) && index === _constants.SHIFT) {
// Convert the next character so that is encoded correctly
bytes[0] = set === _constants.SET_A ? bytes[0] > 95 ? bytes[0] - 96 : bytes[0] : bytes[0] < 32 ? bytes[0] + 96 : bytes[0];
}
nextCode = CODE128.next(bytes, pos + 1, set);
}
}
// Continue on current set but encode a special character
// Continue encoding
else {
// Shift
if ((set === _constants.SET_A || set === _constants.SET_B) && index === _constants.SHIFT) {
// Convert the next character so that is encoded correctly
bytes[0] = set === _constants.SET_A ? bytes[0] > 95 ? bytes[0] - 96 : bytes[0] : bytes[0] < 32 ? bytes[0] + 96 : bytes[0];
}
index = CODE128.correctIndex(bytes, set);
nextCode = CODE128.next(bytes, pos + 1, set);
}
}
// Continue encoding
else {
index = CODE128.correctIndex(bytes, set);
nextCode = CODE128.next(bytes, pos + 1, set);
}

// Get the correct binary encoding and calculate the weight
var enc = CODE128.getBar(index);
var weight = index * pos;
// Get the correct binary encoding and calculate the weight
var enc = CODE128.getBar(index);
var weight = index * pos;

return {
result: enc + nextCode.result,
checksum: weight + nextCode.checksum
};
};
return {
result: enc + nextCode.result,
checksum: weight + nextCode.checksum
};
}
}]);

return CODE128;
}(_Barcode3.default);
Expand Down
13 changes: 9 additions & 4 deletions bin/barcodes/CODE128/CODE128A.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _CODE2 = require('./CODE128.js');

var _CODE3 = _interopRequireDefault(_CODE2);
Expand All @@ -24,12 +26,15 @@ var CODE128A = function (_CODE) {
function CODE128A(string, options) {
_classCallCheck(this, CODE128A);

return _possibleConstructorReturn(this, _CODE.call(this, _constants.A_START_CHAR + string, options));
return _possibleConstructorReturn(this, (CODE128A.__proto__ || Object.getPrototypeOf(CODE128A)).call(this, _constants.A_START_CHAR + string, options));
}

CODE128A.prototype.valid = function valid() {
return new RegExp('^' + _constants.A_CHARS + '+$').test(this.data);
};
_createClass(CODE128A, [{
key: 'valid',
value: function valid() {
return new RegExp('^' + _constants.A_CHARS + '+$').test(this.data);
}
}]);

return CODE128A;
}(_CODE3.default);
Expand Down
13 changes: 9 additions & 4 deletions bin/barcodes/CODE128/CODE128B.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _CODE2 = require('./CODE128.js');

var _CODE3 = _interopRequireDefault(_CODE2);
Expand All @@ -24,12 +26,15 @@ var CODE128B = function (_CODE) {
function CODE128B(string, options) {
_classCallCheck(this, CODE128B);

return _possibleConstructorReturn(this, _CODE.call(this, _constants.B_START_CHAR + string, options));
return _possibleConstructorReturn(this, (CODE128B.__proto__ || Object.getPrototypeOf(CODE128B)).call(this, _constants.B_START_CHAR + string, options));
}

CODE128B.prototype.valid = function valid() {
return new RegExp('^' + _constants.B_CHARS + '+$').test(this.data);
};
_createClass(CODE128B, [{
key: 'valid',
value: function valid() {
return new RegExp('^' + _constants.B_CHARS + '+$').test(this.data);
}
}]);

return CODE128B;
}(_CODE3.default);
Expand Down
13 changes: 9 additions & 4 deletions bin/barcodes/CODE128/CODE128C.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _CODE2 = require('./CODE128.js');

var _CODE3 = _interopRequireDefault(_CODE2);
Expand All @@ -24,12 +26,15 @@ var CODE128C = function (_CODE) {
function CODE128C(string, options) {
_classCallCheck(this, CODE128C);

return _possibleConstructorReturn(this, _CODE.call(this, _constants.C_START_CHAR + string, options));
return _possibleConstructorReturn(this, (CODE128C.__proto__ || Object.getPrototypeOf(CODE128C)).call(this, _constants.C_START_CHAR + string, options));
}

CODE128C.prototype.valid = function valid() {
return new RegExp('^' + _constants.C_CHARS + '+$').test(this.data);
};
_createClass(CODE128C, [{
key: 'valid',
value: function valid() {
return new RegExp('^' + _constants.C_CHARS + '+$').test(this.data);
}
}]);

return CODE128C;
}(_CODE3.default);
Expand Down
4 changes: 2 additions & 2 deletions bin/barcodes/CODE128/CODE128_AUTO.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ var CODE128AUTO = function (_CODE) {

// ASCII value ranges 0-127, 200-211
if (/^[\x00-\x7F\xC8-\xD3]+$/.test(data)) {
var _this = _possibleConstructorReturn(this, _CODE.call(this, (0, _auto2.default)(data), options));
var _this = _possibleConstructorReturn(this, (CODE128AUTO.__proto__ || Object.getPrototypeOf(CODE128AUTO)).call(this, (0, _auto2.default)(data), options));
} else {
var _this = _possibleConstructorReturn(this, _CODE.call(this, data, options));
var _this = _possibleConstructorReturn(this, (CODE128AUTO.__proto__ || Object.getPrototypeOf(CODE128AUTO)).call(this, data, options));
}
return _possibleConstructorReturn(_this);
}
Expand Down
Loading

0 comments on commit 08b588a

Please sign in to comment.