UNPKG

@afocommunity/eco-rcon

Version:
55 lines (54 loc) 1.81 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const rules_1 = __importDefault(require("./rules")); class RCONParser { rules = [...rules_1.default]; controller; constructor(controller) { this.controller = controller; //Do Thing } parse(input) { //eslint-disable-next-line @typescript-eslint/no-explicit-any let response = undefined; for (const rule of this.rules) { let match; if (rule.matchAll) { match = input.matchAll(rule.regex); } else { match = input.match(rule.regex); } if (!match) continue; if (rule.matchAll) { try { const items = Array.from(match); if (items.length === 0) continue; //eslint-disable-next-line @typescript-eslint/no-explicit-any match = items; } catch (error) { // Ignore } } //eslint-disable-next-line @typescript-eslint/no-explicit-any const res = rule.format(match, this.controller); if (rule.multiProperty) { if (response == undefined) { response = {}; } Reflect.set(response, rule.multiProperty, res); continue; } response = res; break; } return response; } } exports.default = RCONParser;