index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. "use strict";
  2. var _createClass = function() {
  3. function defineProperties(target, props) {
  4. for (var i = 0; i < props.length; i++) {
  5. var descriptor = props[i];
  6. descriptor.enumerable = descriptor.enumerable || false;
  7. descriptor.configurable = true;
  8. if ("value" in descriptor) descriptor.writable = true;
  9. Object.defineProperty(target, descriptor.key, descriptor);
  10. }
  11. }
  12. return function(Constructor, protoProps, staticProps) {
  13. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  14. if (staticProps) defineProperties(Constructor, staticProps);
  15. return Constructor;
  16. };
  17. }();
  18. import _Barcode3 from '../Barcode.js'
  19. function _interopRequireDefault(obj) {
  20. return obj && obj.__esModule ? obj : {
  21. default: obj
  22. };
  23. }
  24. function _classCallCheck(instance, Constructor) {
  25. if (!(instance instanceof Constructor)) {
  26. throw new TypeError("Cannot call a class as a function");
  27. }
  28. }
  29. function _possibleConstructorReturn(self, call) {
  30. if (!self) {
  31. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  32. }
  33. return call && (typeof call === "object" || typeof call === "function") ? call : self;
  34. }
  35. function _inherits(subClass, superClass) {
  36. if (typeof superClass !== "function" && superClass !== null) {
  37. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  38. }
  39. subClass.prototype = Object.create(superClass && superClass.prototype, {
  40. constructor: {
  41. value: subClass,
  42. enumerable: false,
  43. writable: true,
  44. configurable: true
  45. }
  46. });
  47. if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ =
  48. superClass;
  49. } // Encoding specification:
  50. // http://www.barcodeisland.com/codabar.phtml
  51. var codabar = function(_Barcode) {
  52. _inherits(codabar, _Barcode);
  53. function codabar(data, options) {
  54. _classCallCheck(this, codabar);
  55. if (data.search(/^[0-9\-\$\:\.\+\/]+$/) === 0) {
  56. data = "A" + data + "A";
  57. }
  58. var _this = _possibleConstructorReturn(this, (codabar.__proto__ || Object.getPrototypeOf(codabar)).call(
  59. this, data.toUpperCase(), options));
  60. _this.text = _this.options.text || _this.text.replace(/[A-D]/g, '');
  61. return _this;
  62. }
  63. _createClass(codabar, [{
  64. key: "valid",
  65. value: function valid() {
  66. return this.data.search(/^[A-D][0-9\-\$\:\.\+\/]+[A-D]$/) !== -1;
  67. }
  68. }, {
  69. key: "encode",
  70. value: function encode() {
  71. var result = [];
  72. var encodings = this.getEncodings();
  73. for (var i = 0; i < this.data.length; i++) {
  74. result.push(encodings[this.data.charAt(i)]);
  75. // for all characters except the last, append a narrow-space ("0")
  76. if (i !== this.data.length - 1) {
  77. result.push("0");
  78. }
  79. }
  80. return {
  81. text: this.text,
  82. data: result.join('')
  83. };
  84. }
  85. }, {
  86. key: "getEncodings",
  87. value: function getEncodings() {
  88. return {
  89. "0": "101010011",
  90. "1": "101011001",
  91. "2": "101001011",
  92. "3": "110010101",
  93. "4": "101101001",
  94. "5": "110101001",
  95. "6": "100101011",
  96. "7": "100101101",
  97. "8": "100110101",
  98. "9": "110100101",
  99. "-": "101001101",
  100. "$": "101100101",
  101. ":": "1101011011",
  102. "/": "1101101011",
  103. ".": "1101101101",
  104. "+": "101100110011",
  105. "A": "1011001001",
  106. "B": "1001001011",
  107. "C": "1010010011",
  108. "D": "1010011001"
  109. };
  110. }
  111. }]);
  112. return codabar;
  113. }(_Barcode3);
  114. export default codabar;