index.js 3.4 KB

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