Skip to content

Commit

Permalink
Release v3.3.20
Browse files Browse the repository at this point in the history
  • Loading branch information
lindell committed Aug 6, 2016
1 parent d777d8d commit 3bc7ae1
Show file tree
Hide file tree
Showing 17 changed files with 396 additions and 133 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ Download or get the CDN link to the script:

| Name | Supported barcodes | Size (gzip) | CDN / Download |
|------|--------------------|:-----------:|---------------:|
| *All* | *All the barcodes!* | *7.3 kB* | *[JsBarcode.all.min.js][1]* |
| CODE128 | CODE128 (auto and force mode) | 5 kB | [JsBarcode.code128.min.js][2] |
| CODE39 | CODE39 | 4 kB | [JsBarcode.code39.min.js][3] |
| EAN / UPC | EAN-13, EAN-8, EAN-5, EAN-2, UPC (A) | 4.6 kB | [JsBarcode.ean-upc.min.js][4] |
| ITF-14 | ITF-14 | 3.8 kB | [JsBarcode.itf-14.min.js][5] |
| ITF | ITF | 3.7 kB | [JsBarcode.itf.min.js][6] |
| MSI | MSI, MSI10, MSI11, MSI1010, MSI1110 | 4.1 kB | [JsBarcode.msi.min.js][7] |
| Pharmacode | Pharmacode | 3.6 kB | [JsBarcode.pharmacode.min.js][8] |
| *All* | *All the barcodes!* | *7.7 kB* | *[JsBarcode.all.min.js][1]* |
| CODE128 | CODE128 (auto and force mode) | 5.3 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] |
| 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] |

### Step 2:
Include the script in your code:
Expand Down
39 changes: 23 additions & 16 deletions bin/JsBarcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ var _getRenderProperties = require('./help/getRenderProperties.js');

var _getRenderProperties2 = _interopRequireDefault(_getRenderProperties);

var _ErrorHandler = require('./exceptions/ErrorHandler.js');

var _ErrorHandler2 = _interopRequireDefault(_ErrorHandler);

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

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

var _defaults2 = _interopRequireDefault(_defaults);
Expand All @@ -38,6 +44,9 @@ var API = function API() {};
// Default values


// Exceptions


// Help functions
var JsBarcode = function JsBarcode(element, text, options) {
var api = new API();
Expand All @@ -50,6 +59,7 @@ var JsBarcode = function JsBarcode(element, text, options) {
api._renderProperties = (0, _getRenderProperties2.default)(element);
api._encodings = [];
api._options = _defaults2.default;
api._errorHandler = new _ErrorHandler2.default(api);

// If text is set, use the simple syntax (render the barcode directly)
if (typeof text !== "undefined") {
Expand All @@ -59,9 +69,7 @@ var JsBarcode = function JsBarcode(element, text, options) {
options.format = autoSelectBarcode();
}

api.options(options);
api[options.format](text, options);
api.render();
api.options(options)[options.format](text, options).render();
}

return api;
Expand All @@ -81,12 +89,15 @@ for (var name in _barcodes2.default) {
}
function registerBarcode(barcodes, name) {
API.prototype[name] = API.prototype[name.toUpperCase()] = API.prototype[name.toLowerCase()] = function (text, options) {
var newOptions = (0, _merge2.default)(this._options, options);
var Encoder = barcodes[name];
var encoded = encode(text, Encoder, newOptions);
this._encodings.push(encoded);

return this;
var api = this;
return api._errorHandler.wrapBarcodeCall(function () {
var newOptions = (0, _merge2.default)(api._options, options);
var Encoder = barcodes[name];
var encoded = encode(text, Encoder, newOptions);
api._encodings.push(encoded);

return api;
});
};
}

Expand All @@ -100,11 +111,7 @@ function encode(text, Encoder, options) {
// If the input is not valid for the encoder, throw error.
// If the valid callback option is set, call it instead of throwing error
if (!encoder.valid()) {
if (options.valid === _defaults2.default.valid) {
throw new Error('"' + text + '" is not a valid input.');
} else {
options.valid(false);
}
throw new _exceptions.InvalidInputException(encoder.constructor.name, text);
}

// Make a request for the binary data (and other infromation) that should be rendered
Expand Down Expand Up @@ -182,11 +189,11 @@ API.prototype.render = function () {
render(this._renderProperties, this._encodings, this._options);
}

this._options.valid(true);

return this;
};

API.prototype._defaults = _defaults2.default;

// Prepares the encodings and calls the renderer
function render(renderProperties, encodings, options) {
encodings = (0, _linearizeEncodings2.default)(encodings);
Expand Down
1 change: 0 additions & 1 deletion bin/barcodes/CODE128/CODE128.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons

// This is the master class, it does require the start code to be
// included in the string

var CODE128 = function () {
function CODE128(string) {
_classCallCheck(this, CODE128);
Expand Down
48 changes: 48 additions & 0 deletions bin/exceptions/ErrorHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"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"); } }

/*eslint no-console: 0 */

var ErrorHandler = function () {
function ErrorHandler(api) {
_classCallCheck(this, ErrorHandler);

this.api = api;
}

ErrorHandler.prototype.handleCatch = function handleCatch(e) {
// If babel supported extending of Error in a correct way instanceof would be used here
if (e.name === "InvalidInputException") {
if (this.api._options.valid !== this.api._defaults.valid) {
this.api._options.valid(false);
} else {
throw e.message;
}
} else {
throw e;
}

this.api.render = function () {};
};

ErrorHandler.prototype.wrapBarcodeCall = function wrapBarcodeCall(func) {
try {
var result = func.apply(undefined, arguments);
this.api._options.valid(true);
return result;
} catch (e) {
this.handleCatch(e);

return this.api;
}
};

return ErrorHandler;
}();

exports.default = ErrorHandler;
67 changes: 67 additions & 0 deletions bin/exceptions/exceptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'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"); } }

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; }

var InvalidInputException = function (_Error) {
_inherits(InvalidInputException, _Error);

function InvalidInputException(symbology, input) {
_classCallCheck(this, InvalidInputException);

var _this = _possibleConstructorReturn(this, _Error.call(this));

_this.name = "InvalidInputException";

_this.symbology = symbology;
_this.input = input;

_this.message = '"' + _this.input + '" is not a valid input for ' + _this.symbology;
return _this;
}

return InvalidInputException;
}(Error);

var InvalidElementException = function (_Error2) {
_inherits(InvalidElementException, _Error2);

function InvalidElementException() {
_classCallCheck(this, InvalidElementException);

var _this2 = _possibleConstructorReturn(this, _Error2.call(this));

_this2.name = "InvalidElementException";
_this2.message = "Not supported type to render on";
return _this2;
}

return InvalidElementException;
}(Error);

var NoElementException = function (_Error3) {
_inherits(NoElementException, _Error3);

function NoElementException() {
_classCallCheck(this, NoElementException);

var _this3 = _possibleConstructorReturn(this, _Error3.call(this));

_this3.name = "NoElementException";
_this3.message = "No element to render on.";
return _this3;
}

return NoElementException;
}(Error);

exports.InvalidInputException = InvalidInputException;
exports.InvalidElementException = InvalidElementException;
exports.NoElementException = NoElementException;
14 changes: 7 additions & 7 deletions bin/help/getRenderProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var _getOptionsFromElement2 = _interopRequireDefault(_getOptionsFromElement);

var _renderers = require("../renderers");

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

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

// Takes an element and returns an object with information about how
Expand All @@ -23,10 +25,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
// options (optional): Options that can be defined in the element
// }

/* global HTMLImageElement */
/* global HTMLCanvasElement */
/* global SVGElement */

function getRenderProperties(element) {
// If the element is a string, query select call again
if (typeof element === "string") {
Expand Down Expand Up @@ -67,14 +65,16 @@ function getRenderProperties(element) {
renderer: (0, _renderers.getRendererClass)("canvas")
};
} else {
throw new Error("Not supported type to render on.");
throw new _exceptions.InvalidElementException();
}
}
} /* global HTMLImageElement */
/* global HTMLCanvasElement */
/* global SVGElement */

function querySelectedRenderProperties(string) {
var selector = document.querySelectorAll(string);
if (selector.length === 0) {
throw new Error("No element found");
throw new _exceptions.NoElementException();
} else {
var returnArray = [];
for (var i = 0; i < selector.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "JsBarcode",
"main": "dist/JsBarcode.all.min.js",
"version": "3.3.18",
"version": "3.3.20",
"homepage": "https://github.com/lindell/JsBarcode",
"authors": [
"Johan Lindell <johan@lindell.me>"
Expand Down
Loading

0 comments on commit 3bc7ae1

Please sign in to comment.