"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Texts = void 0; const path_1 = __importDefault(require("path")); class Texts { static joinPaths(...paths) { return path_1.default.join.apply(null, paths); } static makeSticky(regexp) { if (regexp.sticky) { return regexp; } var source = regexp.source; var flags = regexp.flags; if (flags.indexOf("y") === -1) { flags += "y"; } return new RegExp(source, flags); } static splitLines(text) { return text.split(/(?:\r\n)|\n|\r/g); } static fileName(fullPath) { return path_1.default.basename(fullPath); } static splitLinesCaptureBreaks(text) { return text.split(/((?:\r\n)|\n|\r)/g); } static makeGlobal(regexp) { if (regexp.global) { return regexp; } var source = regexp.source; var flags = regexp.flags; if (flags.indexOf("g") === -1) { flags += "g"; } return new RegExp(source, flags); } static replaceAllIn(texts, replacements) { if (texts === undefined || texts === null) { return texts; } let outputTexts = []; for (let i = 0; i < texts.length; i++) { outputTexts.push(Texts.replaceAll(texts[i], replacements)); } return outputTexts; } static replaceAll(text, replacements) { if (text === undefined || text === null) { return text; } for (let [variable, replacement] of replacements) { let replacementRegexSource = Texts.toRegexSource(variable); let regex = new RegExp(replacementRegexSource, "g"); text = text.replace(regex, replacement); } return text; } static toRegexSource(source) { source = source.replace(/\./g, "\\."); source = source.replace(/\(/g, "\\("); source = source.replace(/\)/g, "\\)"); source = source.replace(/\[/g, "\\["); source = source.replace(/\]/g, "\\]"); source = source.replace(/\^/g, "\\^"); source = source.replace(/\$/g, "\\$"); source = source.replace(/\*/g, "\\*"); source = source.replace(/\+/g, "\\+"); source = source.replace(/\-/g, "\\-"); source = source.replace(/\?/g, "\\?"); source = source.replace(/\//g, "\\/"); source = source.replace(/\|/g, "\\|"); return source; } static getMatches(source, regex, type = null) { regex = this.makeGlobal(regex); let offset = 0; let matches = []; while (offset < source.length) { regex.lastIndex = offset; let result = regex.exec(source); let match = result ? result[0] : null; if (result && result.index != offset && match.length > 0) { offset = result.index + match.length; matches.push({ match: match, index: result.index, type: type }); } else { return matches; } } return matches; } static insertText(sourceText, insertText, insertPosition) { let before = sourceText.substring(0, insertPosition); let after = sourceText.substring(insertPosition, sourceText.length); return before + insertText + after; } } exports.Texts = Texts; //# sourceMappingURL=Texts.js.map