all files / barcode/one-dimension/ code39.js

100% Statements 59/59
90% Branches 18/20
100% Functions 17/17
100% Lines 56/56
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 81 82 83 84 85          80×   78×             78×   78× 78×   78× 78× 565× 565×   78× 78×   78×     77×     78× 78× 78× 78× 868× 868×   78×   78×     78× 78× 78× 78× 78×   78× 78× 78×        
/* 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", "../one-dimension"], function (require, exports, one_dimension_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Code39 = (function (_super) {
        __extends(Code39, _super);
        function Code39() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        Code39.prototype.getCodeValue = function () {
            var codes = ['111221211', '211211112', '112211112',
                '212211111', '111221112', '211221111', '112221111', '111211212',
                '211211211', '112211211', '211112112', '112112112', '212112111', '111122112', '211122111', '112122111',
                '111112212', '211112211', '112112211', '111122211', '211111122', '112111122', '212111121', '111121122',
                '211121121', '112121121', '111111222', '211111221', '112111221', '111121221', '221111112', '122111112',
                '222111111', '121121112', '221121111', '122121111', '121111212', '221111211', '122111211', '121121211',
                '121212111', '121211121', '121112121', '111212121'];
            return codes;
        };
        Code39.prototype.getCharacter = function () {
            var characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%';
            return characters;
        };
        Code39.prototype.checkSum = function (char, characters) {
            var checksum = 0;
            for (var i = 0; i < char.length; i++) {
                var codeNumber = characters.indexOf(char[parseInt(i.toString(), 10)]);
                checksum += codeNumber;
            }
            checksum = checksum % 43;
            return checksum;
        };
        Code39.prototype.validateInput = function (char) {
            if (char.search(/^[0-9A-Z\-\.\ \$\/\+\%]+$/) === -1) {
                return 'Supports A-Z, 0-9, and symbols ( - . $ / + % SPACE).';
            }
            else {
                return undefined;
            }
        };
        Code39.prototype.getPatternCollection = function (givenChar, characters) {
            var codeNumber;
            var code = [];
            var codes = this.getCodeValue();
            for (var i = 0; i < givenChar.length; i++) {
                codeNumber = characters.indexOf(givenChar.charAt(i));
                code.push(codes[parseInt(codeNumber.toString(), 10)]);
            }
            return code;
        };
        Code39.prototype.appendStartStopCharacters = function (char) {
            return '*' + char + '*';
        };
        Code39.prototype.drawCode39Extension = function (canvas, encodedCharacter) {
            this.draw(canvas, encodedCharacter);
        };
        Code39.prototype.draw = function (canvas, encodedCharacter) {
            var givenCharacter = encodedCharacter ? encodedCharacter : this.value;
            var characters = this.getCharacter();
            Eif (this.enableCheckSum) {
                var checkSum = this.checkSum(givenCharacter, characters);
                givenCharacter += checkSum;
            }
            givenCharacter = this.appendStartStopCharacters(givenCharacter);
            var code = this.getPatternCollection(givenCharacter, characters);
            this.calculateBarCodeAttributes(code, canvas);
        };
        return Code39;
    }(one_dimension_1.OneDimension));
    exports.Code39 = Code39;
});