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

99.34% Statements 299/301
91.49% Branches 43/47
100% Functions 18/18
99.33% Lines 296/298
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348                      15×           15× 546×   15× 15×     15× 10×             25× 25×   25× 1225× 25×     25×   38×     27× 27×   27× 1323× 27× 27×       18×       25× 1225× 25×           33× 1617×   33×                
/* 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", "./code93"], function (require, exports, code93_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Code93Extension = (function (_super) {
        __extends(Code93Extension, _super);
        function Code93Extension() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.barcodeSymbols = [];
            return _this;
        }
        Code93Extension.prototype.validateInput = function (text) {
            var valueCheck = this.getValue(text);
            Eif (valueCheck) {
                return undefined;
            }
            else {
                return 'Supports 128 characters of ASCII.';
            }
        };
        Code93Extension.prototype.getValue = function (text) {
            for (var i = 0; i < text.length; i++) {
                Iif (text.charCodeAt(i) > 127) {
                    return false;
                }
            }
            return true;
        };
        Code93Extension.prototype.getBars = function () {
            this.barcodeSymbols[0] = { value: '', checkDigit: 0, bars: '111213' };
            this.barcodeSymbols[1] = { value: '1', checkDigit: 1, bars: '111213' };
            this.barcodeSymbols[2] = { value: '2', checkDigit: 2, bars: '111312 ' };
            this.barcodeSymbols[3] = { value: '3', checkDigit: 3, bars: '111411 ' };
            this.barcodeSymbols[4] = { value: '4', checkDigit: 4, bars: '121113' };
            this.barcodeSymbols[5] = { value: '5', checkDigit: 5, bars: '121212' };
            this.barcodeSymbols[6] = { value: '6', checkDigit: 6, bars: '121311' };
            this.barcodeSymbols[7] = { value: '7', checkDigit: 7, bars: '111114' };
            this.barcodeSymbols[8] = { value: '8', checkDigit: 8, bars: '131211' };
            this.barcodeSymbols[9] = { value: '9', checkDigit: 9, bars: '141111' };
            this.barcodeSymbols[10] = { value: 'A', checkDigit: 10, bars: '211113' };
            this.barcodeSymbols[11] = { value: 'B', checkDigit: 11, bars: '211212' };
            this.barcodeSymbols[12] = { value: 'C', checkDigit: 12, bars: '211311' };
            this.barcodeSymbols[13] = { value: 'D', checkDigit: 13, bars: '221112' };
            this.barcodeSymbols[14] = { value: 'E', checkDigit: 14, bars: '221211 ' };
            this.barcodeSymbols[15] = { value: 'F', checkDigit: 15, bars: '231111' };
            this.barcodeSymbols[16] = { value: 'G', checkDigit: 16, bars: '112113' };
            this.barcodeSymbols[17] = { value: 'H', checkDigit: 17, bars: '112212' };
            this.barcodeSymbols[18] = { value: 'I', checkDigit: 18, bars: '112311' };
            this.barcodeSymbols[19] = { value: 'J', checkDigit: 19, bars: '122112' };
            this.barcodeSymbols[20] = { value: 'K', checkDigit: 20, bars: '132111 ' };
            this.barcodeSymbols[21] = { value: 'L', checkDigit: 21, bars: '111123' };
            this.barcodeSymbols[22] = { value: 'M', checkDigit: 22, bars: '111222' };
            this.barcodeSymbols[23] = { value: 'N', checkDigit: 23, bars: '111321' };
            this.barcodeSymbols[24] = { value: 'O', checkDigit: 24, bars: '121122 ' };
            this.barcodeSymbols[25] = { value: 'P', checkDigit: 25, bars: '131121 ' };
            this.barcodeSymbols[26] = { value: 'Q', checkDigit: 26, bars: '212112 ' };
            this.barcodeSymbols[27] = { value: 'R', checkDigit: 27, bars: ' 212211 ' };
            this.barcodeSymbols[28] = { value: 'S', checkDigit: 28, bars: '211122' };
            this.barcodeSymbols[29] = { value: 'T', checkDigit: 29, bars: '211221' };
            this.barcodeSymbols[30] = { value: 'U', checkDigit: 30, bars: '221121' };
            this.barcodeSymbols[31] = { value: 'V', checkDigit: 31, bars: '222111' };
            this.barcodeSymbols[32] = { value: 'W', checkDigit: 32, bars: '112122' };
            this.barcodeSymbols[33] = { value: 'X', checkDigit: 33, bars: '112221' };
            this.barcodeSymbols[34] = { value: 'Y', checkDigit: 34, bars: '122121' };
            this.barcodeSymbols[35] = { value: 'Z', checkDigit: 35, bars: ' 123111' };
            this.barcodeSymbols[36] = { value: '-', checkDigit: 36, bars: '121131' };
            this.barcodeSymbols[37] = { value: '.', checkDigit: 37, bars: '311112' };
            this.barcodeSymbols[38] = { value: ' ', checkDigit: 38, bars: '311211' };
            this.barcodeSymbols[39] = { value: '$', checkDigit: 39, bars: '321111' };
            this.barcodeSymbols[40] = { value: '/', checkDigit: 40, bars: '112131' };
            this.barcodeSymbols[41] = { value: '+', checkDigit: 41, bars: '113121' };
            this.barcodeSymbols[42] = { value: '%', checkDigit: 42, bars: '211131' };
            this.barcodeSymbols[43] = { value: '*', checkDigit: 42, bars: '111141' };
            this.barcodeSymbols[44] = { value: 'ÿ', checkDigit: 47, bars: '1111411' };
            this.barcodeSymbols[45] = { value: 'û', checkDigit: 43, bars: '121220' };
            this.barcodeSymbols[46] = { value: 'ü', checkDigit: 44, bars: '312111 ' };
            this.barcodeSymbols[47] = { value: 'ý', checkDigit: 45, bars: '311121' };
            this.barcodeSymbols[48] = { value: 'þ', checkDigit: 46, bars: '122211' };
        };
        Code93Extension.prototype.GetExtendedText = function (string) {
            var code = this.value;
            var extcodes;
            this.extendedText = '';
            for (var i = 0; i < code.length; i++) {
                for (var j = string.length - 1; j > 0; j--) {
                    if (string[parseInt(j.toString(), 10)] && string[parseInt(j.toString(), 10)].value
                        && string[parseInt(j.toString(), 10)].character === code[parseInt(i.toString(), 10)]) {
                        extcodes = string[parseInt(j.toString(), 10)];
                        break;
                    }
                }
                if (extcodes.keyword && extcodes.value) {
                    this.extendedText += extcodes.keyword + extcodes.value;
                }
                else Eif (extcodes.value && extcodes.value) {
                    this.extendedText += extcodes.value;
                }
            }
        };
        Code93Extension.prototype.drawCode93 = function (canvas) {
            this.getBars();
            var temp = [];
            var string = this.getArrayValue();
            this.GetExtendedText(string);
            var checkDigit = this.CalculateCheckDigit();
            for (var i = 0; i < checkDigit.length; i++) {
                this.extendedText += checkDigit[parseInt(i.toString(), 10)];
            }
            temp[0] = '*' + this.extendedText + 'ÿ';
            var encodingValue = [];
            encodingValue = this.encoding(temp);
            this.calculateBarCodeAttributes(encodingValue, canvas);
        };
        Code93Extension.prototype.GetCheckSumSymbols = function () {
            var text = this.extendedText;
            var dataToEncode = text;
            var charArray = [];
            var checkValue = 0;
            var length = dataToEncode.length;
            var numi;
            for (var i = 0; i < length; i++) {
                var num4 = (length - i) % 20;
                if (num4 === 0) {
                    num4 = 20;
                }
                for (var j = 0; j < this.barcodeSymbols.length; j++) {
                    if (dataToEncode[parseInt(i.toString(), 10)] === this.barcodeSymbols[parseInt(j.toString(), 10)].value) {
                        numi = this.barcodeSymbols[parseInt(j.toString(), 10)].checkDigit;
                    }
                }
                checkValue += numi * num4;
            }
            checkValue = checkValue % 0x2f;
            var char1 = '';
            for (var k = 0; k < this.barcodeSymbols.length; k++) {
                if (checkValue === this.barcodeSymbols[parseInt(k.toString(), 10)].checkDigit) {
                    char1 = this.barcodeSymbols[parseInt(k.toString(), 10)].value;
                    break;
                }
            }
            var data = this.extendedText;
            data = data + char1;
            charArray[0] = char1;
            text = data;
            checkValue = 0;
            dataToEncode = text;
            length = dataToEncode.length;
            for (var i = 0; i < length; i++) {
                var num4 = (length - i) % 15;
                if (num4 === 0) {
                    num4 = 15;
                }
                for (var m = 0; m < this.barcodeSymbols.length; m++) {
                    if (dataToEncode[parseInt(i.toString(), 10)] === this.barcodeSymbols[parseInt(m.toString(), 10)].value) {
                        var tempi = this.barcodeSymbols[parseInt(m.toString(), 10)].checkDigit;
                        checkValue += tempi * num4;
                    }
                }
            }
            checkValue = checkValue % 0x2f;
            text = text + checkValue;
            var char2 = ' ';
            for (var i = 0; i < this.barcodeSymbols.length; i++) {
                if (checkValue === this.barcodeSymbols[parseInt(i.toString(), 10)].checkDigit) {
                    char2 = this.barcodeSymbols[parseInt(i.toString(), 10)].value;
                    break;
                }
            }
            data = data + char2;
            charArray[1] = char2;
            return charArray;
        };
        Code93Extension.prototype.CalculateCheckDigit = function () {
            var code = this.extendedText;
            var checkValue = 0;
            for (var i = 0; i < code.length; i++) {
                for (var j = 0; j < this.barcodeSymbols.length; j++) {
                    if (code[parseInt(i.toString(), 10)] === this.barcodeSymbols[parseInt(j.toString(), 10)].value) {
                        checkValue += this.barcodeSymbols[j].checkDigit;
                    }
                }
            }
            var ch = this.GetCheckSumSymbols();
            return ch;
        };
        Code93Extension.prototype.getArrayValue = function () {
            var arrayValue = [];
            arrayValue[0] = { character: '\0', keyword: 'ü', value: 'U' };
            arrayValue[1] = { character: '\x0001', keyword: 'û', value: 'A' };
            arrayValue[2] = { character: '\x0002', keyword: 'x00fb', value: 'B' };
            arrayValue[3] = { character: '\x0003', keyword: 'û', value: 'C' };
            arrayValue[4] = { character: '\x0004', keyword: 'û', value: 'D' };
            arrayValue[5] = { character: '\x0005', keyword: 'û', value: 'E' };
            arrayValue[6] = { character: '\x0006', keyword: 'û', value: 'F' };
            arrayValue[7] = { character: '\a', keyword: 'û', value: 'G' };
            arrayValue[8] = { character: '\b', keyword: 'û', value: 'H' };
            arrayValue[9] = { character: '\t', keyword: 'û', value: 'I' };
            arrayValue[10] = { character: '\n', keyword: 'û', value: 'J' };
            arrayValue[12] = { character: '\v', keyword: 'û', value: 'K' };
            arrayValue[13] = { character: '\f', keyword: 'û', value: 'L' };
            arrayValue[14] = { character: '\r', keyword: 'û', value: 'M' };
            arrayValue[15] = { character: '\x000e', keyword: 'û', value: 'N' };
            arrayValue[16] = { character: '\x000f', keyword: 'û', value: 'O' };
            arrayValue[17] = { character: '\x0010', keyword: 'û', value: 'P' };
            arrayValue[18] = { character: '\x0011', keyword: 'û', value: 'Q' };
            arrayValue[19] = { character: '\x0012', keyword: 'û', value: 'R' };
            arrayValue[20] = { character: '\x0013', keyword: 'û', value: 'S' };
            arrayValue[21] = { character: '\x0014', keyword: 'û', value: 'T' };
            arrayValue[22] = { character: '\x0015', keyword: 'û', value: 'U' };
            arrayValue[23] = { character: '\x0016', keyword: 'û', value: 'V' };
            arrayValue[24] = { character: '\x0017', keyword: 'û', value: 'W' };
            arrayValue[25] = { character: '\x0018', keyword: 'û', value: 'X' };
            arrayValue[26] = { character: '\x0019', keyword: 'û', value: 'Y' };
            arrayValue[27] = { character: '\x001a', keyword: 'û', value: 'Z' };
            arrayValue[28] = { character: '\x001b', keyword: 'ü', value: 'A' };
            arrayValue[29] = { character: '\x001c', keyword: 'ü', value: 'B' };
            arrayValue[30] = { character: '\x001d', keyword: 'ü', value: 'C' };
            arrayValue[31] = { character: '\x001e', keyword: 'ü', value: 'D' };
            arrayValue[32] = { character: '\x001f', keyword: 'ü', value: 'E' };
            arrayValue[33] = { character: ' ', keyword: ' ' };
            arrayValue[34] = { character: '!', keyword: 'ý', value: 'A' };
            arrayValue[35] = { character: '"', keyword: 'ý', value: 'B' };
            arrayValue[36] = { character: '#', keyword: 'ý', value: 'C' };
            arrayValue[37] = { character: '$', keyword: 'ý', value: 'D' };
            arrayValue[38] = { character: '%', keyword: 'ý', value: 'E' };
            arrayValue[39] = { character: '&', keyword: 'ý', value: 'F' };
            arrayValue[40] = { character: '\'', keyword: 'ý', value: 'G' };
            arrayValue[41] = { character: '(', keyword: 'ý', value: 'H' };
            arrayValue[42] = { character: ')', keyword: 'ý', value: 'I' };
            arrayValue[43] = { character: '*', keyword: 'ý', value: 'J' };
            arrayValue[44] = { character: '+', keyword: 'ý', value: 'K' };
            arrayValue[45] = { character: ',', keyword: 'ý', value: 'L' };
            arrayValue[46] = { character: '-', keyword: 'ý', value: 'M' };
            arrayValue[47] = { character: '.', keyword: 'ý', value: 'N' };
            arrayValue[48] = { character: '/', keyword: 'ý', value: 'O' };
            arrayValue[49] = { character: '0', value: '0' };
            arrayValue[50] = { character: '1', value: '1' };
            arrayValue[51] = { character: '2', value: '2' };
            arrayValue[52] = { character: '3', value: '3' };
            arrayValue[53] = { character: '4', value: '4' };
            arrayValue[54] = { character: '5', value: '5' };
            arrayValue[55] = { character: '6', value: '6' };
            arrayValue[56] = { character: '7', value: '7' };
            arrayValue[57] = { character: '8', value: '8' };
            arrayValue[58] = { character: '9', value: '9' };
            arrayValue[59] = { character: ':', keyword: 'ý', value: 'Z' };
            arrayValue[60] = { character: ';', keyword: 'ü', value: 'F' };
            arrayValue[61] = { character: '<', keyword: 'ü', value: 'G' };
            arrayValue[62] = { character: '=', keyword: 'ü', value: 'H' };
            arrayValue[63] = { character: '>', keyword: 'ü', value: 'I' };
            arrayValue[64] = { character: '?', keyword: 'ü', value: 'J' };
            arrayValue[65] = { character: '@', keyword: 'ü', value: 'V' };
            arrayValue[66] = { character: 'A', value: 'A' };
            arrayValue[67] = { character: 'B', value: 'B' };
            arrayValue[68] = { character: 'C', value: 'C' };
            arrayValue[69] = { character: 'D', value: 'D' };
            arrayValue[70] = { character: 'E', value: 'E' };
            arrayValue[71] = { character: 'F', value: 'F' };
            arrayValue[72] = { character: 'G', value: 'G' };
            arrayValue[73] = { character: 'H', value: 'H' };
            arrayValue[74] = { character: 'I', value: 'I' };
            arrayValue[75] = { character: 'J', value: 'J' };
            arrayValue[76] = { character: 'K', value: 'K' };
            arrayValue[77] = { character: 'L', value: 'L' };
            arrayValue[78] = { character: 'M', value: 'M' };
            arrayValue[79] = { character: 'N', value: 'N' };
            arrayValue[80] = { character: 'O', value: 'O' };
            arrayValue[81] = { character: 'P', value: 'P' };
            arrayValue[82] = { character: 'Q', value: 'Q' };
            arrayValue[83] = { character: 'R', value: 'R' };
            arrayValue[84] = { character: 'S', value: 'S' };
            arrayValue[85] = { character: 'T', value: 'T' };
            arrayValue[86] = { character: 'U', value: 'U' };
            arrayValue[87] = { character: 'V', value: 'V' };
            arrayValue[88] = { character: 'W', value: 'W' };
            arrayValue[88] = { character: 'X', value: 'X' };
            arrayValue[89] = { character: 'Y', value: 'Y' };
            arrayValue[90] = { character: 'Z', value: 'Z' };
            arrayValue[91] = { character: '[', keyword: 'ü', value: 'K' };
            arrayValue[92] = { character: '\\', keyword: 'ü', value: 'L' };
            arrayValue[93] = { character: ']', keyword: 'ü', value: 'M' };
            arrayValue[94] = { character: '^', keyword: 'ü', value: 'N' };
            arrayValue[95] = { character: '_', keyword: 'ü', value: 'O' };
            arrayValue[96] = { character: '`', keyword: 'ü', value: 'W' };
            arrayValue[97] = { character: 'a', keyword: 'þ', value: 'A' };
            arrayValue[98] = { character: 'b', keyword: 'þ', value: 'B' };
            arrayValue[99] = { character: 'c', keyword: 'þ', value: 'C' };
            arrayValue[100] = { character: 'd', keyword: 'þ', value: 'D' };
            arrayValue[101] = { character: 'e', keyword: 'þ', value: 'E' };
            arrayValue[102] = { character: 'f', keyword: 'þ', value: 'F' };
            arrayValue[103] = { character: 'g', keyword: 'þ', value: 'G' };
            arrayValue[104] = { character: 'h', keyword: 'þ', value: 'H' };
            arrayValue[105] = { character: 'i', keyword: 'þ', value: 'I' };
            arrayValue[106] = { character: 'j', keyword: 'þ', value: 'J' };
            arrayValue[107] = { character: 'k', keyword: 'þ', value: 'K' };
            arrayValue[108] = { character: 'l', keyword: 'þ', value: 'L' };
            arrayValue[109] = { character: 'm', keyword: 'þ', value: 'M' };
            arrayValue[110] = { character: 'n', keyword: 'þ', value: 'N' };
            arrayValue[111] = { character: 'o', keyword: 'þ', value: 'O' };
            arrayValue[112] = { character: 'p', keyword: 'þ', value: 'P' };
            arrayValue[113] = { character: 'q', keyword: 'þ', value: 'Q' };
            arrayValue[114] = { character: 'r', keyword: 'þ', value: 'R' };
            arrayValue[115] = { character: 's', keyword: 'þ', value: 'S' };
            arrayValue[116] = { character: 't', keyword: 'þ', value: 'T' };
            arrayValue[117] = { character: 'u', keyword: 'þ', value: 'U' };
            arrayValue[118] = { character: 'v', keyword: 'þ', value: 'V' };
            arrayValue[119] = { character: 'w', keyword: 'þ', value: 'W' };
            arrayValue[120] = { character: 'x', keyword: 'þ', value: 'X' };
            arrayValue[121] = { character: 'y', keyword: 'þ', value: 'Y' };
            arrayValue[122] = { character: 'z', keyword: 'þ', value: 'Z' };
            arrayValue[123] = { character: '{', keyword: 'ü', value: 'P' };
            arrayValue[124] = { character: '|', keyword: 'ü', value: 'Q' };
            arrayValue[125] = { character: '}', keyword: 'ü', value: 'R' };
            arrayValue[126] = { character: '~', keyword: 'ü', value: 'S' };
            return arrayValue;
        };
        Code93Extension.prototype.encoding = function (string) {
            var temp = [];
            for (var j = 0; j < string.length; j++) {
                for (var k = 0; k < string[parseInt(j.toString(), 10)].length; k++) {
                    for (var i = 0; i < this.barcodeSymbols.length; i++) {
                        if (string[parseInt(j.toString(), 10)][parseInt(k.toString(), 10)] ===
                            this.barcodeSymbols[parseInt(i.toString(), 10)].value) {
                            temp[parseInt(k.toString(), 10)] = this.barcodeSymbols[parseInt(i.toString(), 10)].bars;
                        }
                    }
                }
            }
            return temp;
        };
        return Code93Extension;
    }(code93_1.Code93));
    exports.Code93Extension = Code93Extension;
});