all files / barcode/one-dimension/ gs1-code128.js

100% Statements 63/63
94.12% Branches 32/34
100% Functions 13/13
100% Lines 60/60
11 statements, 6 functions, 9 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80  1× 1× 1× 1× 1× 1×   1× 1× 1× 1×     1×   1× 1× 1× 1× 1× 25×   1× 23× 23× 23× 9×   14× 1×   13×   1× 14× 14× 1×   13× 13× 13× 13× 13× 13× 13× 12×   13× 13× 13× 13×   1× 14× 11×   3× 3× 3× 3× 3× 9× 9× 9× 9× 9× 3×     3×   1× 10×   1×   1×    
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "./code128", "../../gs1/gs1-parser"], function (require, exports, code128_1, gs1_parser_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var FNC1 = String.fromCharCode(207);
    var GS1Code128 = (function (_super) {
        __extends(GS1Code128, _super);
        function GS1Code128() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        GS1Code128.prototype.validateInput = function (char) {
            var result = gs1_parser_1.parseGs1(char);
            this.gs1Result = result;
            if (!result.ok) {
                return this.message(result.error);
            }
            if (result.encodingData.length > 48) {
                return this.message('GS1DataTooLong');
            }
            return undefined;
        };
        GS1Code128.prototype.draw = function (canvas) {
            var result = this.gs1Result && this.gs1Result.ok ? this.gs1Result : gs1_parser_1.parseGs1(this.value);
            if (!result.ok) {
                return;
            }
            var success = result;
            var originalValue = this.value;
            var originalText = this.displayText.text;
            var originalCheckSum = this.enableCheckSum;
            this.value = FNC1 + this.insertSeparatingFnc1(success);
            this.enableCheckSum = true;
            if (!originalText) {
                this.displayText.text = success.humanReadableText;
            }
            this.code128(canvas);
            this.value = originalValue;
            this.displayText.text = originalText;
            this.enableCheckSum = originalCheckSum;
        };
        GS1Code128.prototype.insertSeparatingFnc1 = function (success) {
            if (!success.separatingFnc1After.length) {
                return success.encodingData;
            }
            var separators = success.separatingFnc1After;
            var data = '';
            var offset = 0;
            var index;
            for (index = 0; index < success.elements.length; index++) {
                var element = success.elements[parseInt(index.toString(), 10)];
                var length_1 = element.ai.length + element.value.length;
                data += success.encodingData.substring(offset, offset + length_1);
                offset += length_1;
                if (separators.indexOf(index) !== -1) {
                    data += FNC1;
                }
            }
            return data;
        };
        GS1Code128.prototype.message = function (key) {
            return this.locale ? (this.locale.getConstant(key) || key) : key;
        };
        return GS1Code128;
    }(code128_1.Code128));
    exports.GS1Code128 = GS1Code128;
});