1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = pathToPattern;
|
---|
7 | function _path() {
|
---|
8 | const data = require("path");
|
---|
9 | _path = function () {
|
---|
10 | return data;
|
---|
11 | };
|
---|
12 | return data;
|
---|
13 | }
|
---|
14 | const sep = `\\${_path().sep}`;
|
---|
15 | const endSep = `(?:${sep}|$)`;
|
---|
16 | const substitution = `[^${sep}]+`;
|
---|
17 | const starPat = `(?:${substitution}${sep})`;
|
---|
18 | const starPatLast = `(?:${substitution}${endSep})`;
|
---|
19 | const starStarPat = `${starPat}*?`;
|
---|
20 | const starStarPatLast = `${starPat}*?${starPatLast}?`;
|
---|
21 | function escapeRegExp(string) {
|
---|
22 | return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
|
---|
23 | }
|
---|
24 | function 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 | }
|
---|
36 | 0 && 0;
|
---|
37 |
|
---|
38 | //# sourceMappingURL=pattern-to-regex.js.map
|
---|