UNPKG

jspos

Version:

JavaScript ISO8583 ,JavaScript version of JPOS

72 lines (54 loc) 4.92 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); 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; }; }(); var _Interpreter2 = require('./Interpreter'); var _Interpreter3 = _interopRequireDefault(_Interpreter2); var _ISOUtil = require('./ISOUtil'); var _ISOUtil2 = _interopRequireDefault(_ISOUtil); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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; } 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; } /** * @author Sean sean.snow@live.com * @date 2015/12/24 */ var BCDInterpreter = function (_Interpreter) { _inherits(BCDInterpreter, _Interpreter); function BCDInterpreter(leftPadded, fPadded) { _classCallCheck(this, BCDInterpreter); var _this = _possibleConstructorReturn(this, (BCDInterpreter.__proto__ || Object.getPrototypeOf(BCDInterpreter)).call(this, leftPadded, fPadded)); _this.leftPadded = leftPadded; _this.fPadded = fPadded; return _this; } _createClass(BCDInterpreter, [{ key: 'interpret', value: function interpret(data, byte, offset) { _ISOUtil2.default.str2bcd(data, this.leftPadded, byte, offset); var paddedSize = data.length >> 1; if (this.fPadded && data.length % 2 === 1) { if (this.leftPadded) { byte[offset] |= 0xF0; } else { byte[offset + paddedSize] |= 0x0F; } } } }, { key: 'uninterpret', value: function uninterpret(rawData, offset, length) { return _ISOUtil2.default.bcd2str(rawData, offset, length, this.leftPadded); } }, { key: 'getPackedLength', value: function getPackedLength(nDataUnits) { return Math.floor((nDataUnits + 1) / 2); } }]); return BCDInterpreter; }(_Interpreter3.default); BCDInterpreter.LEFT_PADDED = new BCDInterpreter(true, false); BCDInterpreter.RIGHT_PADDED = new BCDInterpreter(false, false); exports.default = BCDInterpreter;