card-sharing
Version:
card sharing config generator by parsing online sources
126 lines (92 loc) • 5.42 kB
JavaScript
;
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 _core = require('../core');
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
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; }
var CCcam = function CCcam(config) {
return 'C: ' + config.host + ' ' + config.port + ' ' + config.username + ' ' + config.password;
};
var Newcam = function Newcam(config) {
return 'N: ' + config.host + ' ' + config.port + ' ' + config.username + ' ' + config.password + ' ' + config.key;
};
var PlainLines = function (_Output) {
_inherits(PlainLines, _Output);
function PlainLines() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, PlainLines);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = PlainLines.__proto__ || Object.getPrototypeOf(PlainLines)).call.apply(_ref, [this].concat(args))), _this), _this.options = {
nl: '\n'
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(PlainLines, [{
key: 'render',
value: function () {
var _ref2 = _asyncToGenerator(regeneratorRuntime.mark(function _callee(configs) {
var nl, output, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, config;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
nl = this.options.nl;
output = [];
// NOTE: performance could be increased by generating the stream instead of
// joining values on return
_iteratorNormalCompletion = true;
_didIteratorError = false;
_iteratorError = undefined;
_context.prev = 5;
for (_iterator = configs[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
config = _step.value;
output.push(config.constructor.name == 'CCcam' && CCcam(config) || config.constructor.name == 'Newcam' && Newcam(config) || '');
}
_context.next = 13;
break;
case 9:
_context.prev = 9;
_context.t0 = _context['catch'](5);
_didIteratorError = true;
_iteratorError = _context.t0;
case 13:
_context.prev = 13;
_context.prev = 14;
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
case 16:
_context.prev = 16;
if (!_didIteratorError) {
_context.next = 19;
break;
}
throw _iteratorError;
case 19:
return _context.finish(16);
case 20:
return _context.finish(13);
case 21:
return _context.abrupt('return', output.join(nl));
case 22:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[5, 9, 13, 21], [14,, 16, 20]]);
}));
function render(_x) {
return _ref2.apply(this, arguments);
}
return render;
}()
}]);
return PlainLines;
}(_core.Output);
exports.default = PlainLines;