source: imaps-frontend/node_modules/@babel/core/lib/config/pattern-to-regex.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 3 months ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.2 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = pathToPattern;
7function _path() {
8 const data = require("path");
9 _path = function () {
10 return data;
11 };
12 return data;
13}
14const sep = `\\${_path().sep}`;
15const endSep = `(?:${sep}|$)`;
16const substitution = `[^${sep}]+`;
17const starPat = `(?:${substitution}${sep})`;
18const starPatLast = `(?:${substitution}${endSep})`;
19const starStarPat = `${starPat}*?`;
20const starStarPatLast = `${starPat}*?${starPatLast}?`;
21function escapeRegExp(string) {
22 return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
23}
24function pathToPattern(pattern, dirname) {
25 const parts = _path().resolve(dirname, pattern).split(_path().sep);
26 return new RegExp(["^", ...parts.map((part, i) => {
27 const last = i === parts.length - 1;
28 if (part === "**") return last ? starStarPatLast : starStarPat;
29 if (part === "*") return last ? starPatLast : starPat;
30 if (part.indexOf("*.") === 0) {
31 return substitution + escapeRegExp(part.slice(1)) + (last ? endSep : sep);
32 }
33 return escapeRegExp(part) + (last ? endSep : sep);
34 })].join(""));
35}
360 && 0;
37
38//# sourceMappingURL=pattern-to-regex.js.map
Note: See TracBrowser for help on using the repository browser.