all files / datamatrix/ gs1-datamatrix.js

100% Statements 48/48
92.31% Branches 24/26
100% Functions 13/13
100% Lines 45/45
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  1× 1× 1× 1× 1× 1×   1× 1× 1× 1×     1×   1× 1× 1× 1× 1× 25×   1× 24× 24× 24× 6×   18×   1× 18× 18× 5×   13× 13× 13× 13× 13× 52× 52× 52× 52× 52× 13×     13×   1× 15×   1× 6×   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", "./datamatrix-util", "../gs1/gs1-parser"], function (require, exports, datamatrix_util_1, gs1_parser_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var FNC1_PLACEHOLDER = String.fromCharCode(359);
    var Gs1DataMatrix = (function (_super) {
        __extends(Gs1DataMatrix, _super);
        function Gs1DataMatrix() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        Gs1DataMatrix.prototype.validateGs1 = function (char) {
            var result = gs1_parser_1.parseGs1(char);
            this.gs1Result = result;
            if (!result.ok) {
                return this.message(result.error);
            }
            return undefined;
        };
        Gs1DataMatrix.prototype.buildGs1Data = function () {
            var success = this.gs1Result;
            if (!success.separatingFnc1After.length) {
                return FNC1_PLACEHOLDER + success.encodingData;
            }
            var separators = success.separatingFnc1After;
            var data = FNC1_PLACEHOLDER;
            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 && index !== success.elements.length - 1) {
                    data += FNC1_PLACEHOLDER;
                }
            }
            return data;
        };
        Gs1DataMatrix.prototype.getHumanReadableText = function () {
            return this.gs1Result.humanReadableText;
        };
        Gs1DataMatrix.prototype.message = function (key) {
            return this.locale ? (this.locale.getConstant(key) || key) : key;
        };
        return Gs1DataMatrix;
    }(datamatrix_util_1.DataMatrix));
    exports.Gs1DataMatrix = Gs1DataMatrix;
});