UNPKG

gbf-raidfinder-parser

Version:
44 lines 1.75 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var 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 function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var TextParser_1 = require("./TextParser"); var Raid_1 = require("../Raid"); var RAID_CODE_SUFFIXES = [' :Battle ID', ' :参戦ID']; function getRaidCode(text) { for (var _i = 0, RAID_CODE_SUFFIXES_1 = RAID_CODE_SUFFIXES; _i < RAID_CODE_SUFFIXES_1.length; _i++) { var suffix = RAID_CODE_SUFFIXES_1[_i]; var index = text.indexOf(suffix); if (index < 0) { continue; } return text.substr(0, index); } return null; } var RaidParser = /** @class */ (function (_super) { __extends(RaidParser, _super); function RaidParser() { return _super !== null && _super.apply(this, arguments) || this; } RaidParser.prototype.parse = function (text) { var parts = (getRaidCode(text) || '').split(' '); var code = parts.pop(); if (!code) { throw this.invalidFormatError(text); } var message = parts.length > 0 ? parts.join(' ') : undefined; return new Raid_1.default(text, code, message); }; return RaidParser; }(TextParser_1.default)); exports.default = RaidParser; //# sourceMappingURL=RaidParser.js.map