Sha256: 12846b83127636e53d02a12d5edcc68a4560040b067fcb139654818c1a0fddfb

Contents?: true

Size: 1.12 KB

Versions: 7

Compression:

Stored size: 1.12 KB

Contents

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = pathToPattern;

function _path() {
  const data = require("path");

  _path = function () {
    return data;
  };

  return data;
}

const sep = `\\${_path().sep}`;
const endSep = `(?:${sep}|$)`;
const substitution = `[^${sep}]+`;
const starPat = `(?:${substitution}${sep})`;
const starPatLast = `(?:${substitution}${endSep})`;
const starStarPat = `${starPat}*?`;
const starStarPatLast = `${starPat}*?${starPatLast}?`;

function escapeRegExp(string) {
  return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
}

function pathToPattern(pattern, dirname) {
  const parts = _path().resolve(dirname, pattern).split(_path().sep);

  return new RegExp(["^", ...parts.map((part, i) => {
    const last = i === parts.length - 1;
    if (part === "**") return last ? starStarPatLast : starStarPat;
    if (part === "*") return last ? starPatLast : starPat;

    if (part.indexOf("*.") === 0) {
      return substitution + escapeRegExp(part.slice(1)) + (last ? endSep : sep);
    }

    return escapeRegExp(part) + (last ? endSep : sep);
  })].join(""));
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
disco_app-0.16.1 test/dummy/node_modules/@babel/core/lib/config/pattern-to-regex.js
disco_app-0.15.2 test/dummy/node_modules/@babel/core/lib/config/pattern-to-regex.js
disco_app-0.18.4 test/dummy/node_modules/@babel/core/lib/config/pattern-to-regex.js
disco_app-0.18.1 test/dummy/node_modules/@babel/core/lib/config/pattern-to-regex.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/@babel/core/lib/config/pattern-to-regex.js
disco_app-0.14.0 test/dummy/node_modules/@babel/core/lib/config/pattern-to-regex.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/@babel/core/lib/config/pattern-to-regex.js