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 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 4× 1× 4× 1× 3× 1× 2× 2× 1× 1× 2× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 2× 2× 8× 2× 6× 2× 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", "../one-dimension"], function (require, exports, one_dimension_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Ean8 = (function (_super) { __extends(Ean8, _super); function Ean8() { return _super !== null && _super.apply(this, arguments) || this; } Ean8.prototype.validateInput = function (value) { if (value.search(/^[0-9]{8}$/) !== -1 && Number(value[7]) === this.checkSumData(value)) { return undefined; } else { return 'Accepts 8 numeric characters.'; } }; Ean8.prototype.getCodeValueRight = function (right) { var codes; if (right) { codes = { '0': '0001101', '1': '0011001', '2': '0010011', '3': '0111101', '4': '0100011', '5': '0110001', '6': '0101111', '7': '0111011', '8': '0110111', '9': '0001011' }; } else { codes = { '0': '1110010', '1': '1100110', '2': '1101100', '3': '1000010', '4': '1011100', '5': '1001110', '6': '1010000', '7': '1000100', '8': '1001000', '9': '1110100' }; } return codes; }; Ean8.prototype.checkSumData = function (value) { for (var i = 0; i < value.length; i++) { var sum1 = Number(value[1]) + Number(value[3]) + Number(value[5]); var sum2 = 3 * (Number(value[0]) + Number(value[2]) + Number(value[4]) + Number(value[6])); var checkSumValue = sum1 + sum2; var checkSumDigit = 10 - (checkSumValue % 10); return checkSumDigit === 0 ? checkSumDigit = 0 : checkSumDigit; } return 0; }; Ean8.prototype.draw = function (canvas) { var endBars = '101'; var middleBar = '01010'; var codes = this.getCodeValueRight(true); var code = []; code.push(endBars); code.push(this.leftValue(codes, true)); code.push(middleBar); codes = this.getCodeValueRight(false); code.push(this.leftValue(codes, false)); code.push(endBars); this.calculateBarCodeAttributes(code, canvas); }; Ean8.prototype.leftValue = function (codes, isLeft) { var code; for (var i = isLeft ? 0 : this.value.length - 4; i < (isLeft ? this.value.length - 4 : this.value.length); i++) { if (i === 0 || i === 4) { code = codes[this.value[parseInt(i.toString(), 10)]]; } else { code += codes[this.value[parseInt(i.toString(), 10)]]; } } return code; }; return Ean8; }(one_dimension_1.OneDimension)); exports.Ean8 = Ean8; }); |