UNPKG

simple-git

Version:

Simple GIT interface for node.js

51 lines 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class LineParser { constructor(regExp, useMatches) { this.matches = []; this.parse = (line, target) => { this.resetMatches(); if (!this._regExp.every((reg, index) => this.addMatch(reg, index, line(index)))) { return false; } return this.useMatches(target, this.prepareMatches()) !== false; }; this._regExp = Array.isArray(regExp) ? regExp : [regExp]; if (useMatches) { this.useMatches = useMatches; } } // @ts-ignore useMatches(target, match) { throw new Error(`LineParser:useMatches not implemented`); } resetMatches() { this.matches.length = 0; } prepareMatches() { return this.matches; } addMatch(reg, index, line) { const matched = line && reg.exec(line); if (matched) { this.pushMatch(index, matched); } return !!matched; } pushMatch(_index, matched) { this.matches.push(...matched.slice(1)); } } exports.LineParser = LineParser; class RemoteLineParser extends LineParser { addMatch(reg, index, line) { return /^remote:\s/.test(String(line)) && super.addMatch(reg, index, line); } pushMatch(index, matched) { if (index > 0 || matched.length > 1) { super.pushMatch(index, matched); } } } exports.RemoteLineParser = RemoteLineParser; //# sourceMappingURL=line-parser.js.map