all files / dotcode/ gs1-dotcode.js

100% Statements 33/33
100% Branches 12/12
100% Functions 7/7
100% Lines 33/33
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 461×   1× 1× 1× 1×   1× 28× 28× 28× 12×   16×   1× 16× 16× 13×   3× 3× 3× 3× 3× 9× 9× 9× 9× 9× 3×     3×   1× 10×   1× 12×   1×   1×    
define(["require", "exports", "../gs1/gs1-parser"], function (require, exports, gs1_parser_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var GS = '\u001D';
    var Gs1DotCode = (function () {
        function Gs1DotCode() {
        }
        Gs1DotCode.prototype.validateGs1 = function (char) {
            var result = gs1_parser_1.parseGs1(char);
            this.gs1Result = result;
            if (!result.ok) {
                return this.message(result.error);
            }
            return undefined;
        };
        Gs1DotCode.prototype.buildGs1Data = function () {
            var success = this.gs1Result;
            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 && index !== success.elements.length - 1) {
                    data += GS;
                }
            }
            return data;
        };
        Gs1DotCode.prototype.getHumanReadableText = function () {
            return this.gs1Result.humanReadableText;
        };
        Gs1DotCode.prototype.message = function (key) {
            return this.locale ? (this.locale.getConstant(key) || key) : key;
        };
        return Gs1DotCode;
    }());
    exports.Gs1DotCode = Gs1DotCode;
});