How to use the micromatch.isMatch function in micromatch

To help you get started, we’ve selected a few micromatch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yarnpkg / yarn / src / util / filter.js View on Github external
export function matchesFilter(filter: IgnoreFilter, basename: string, loc: string): boolean {
  let filterByBasename = true;
  if (filter.base && filter.base !== '.') {
    loc = path.relative(filter.base, loc);
    filterByBasename = false;
  }
  // the micromatch regex expects unix path separators
  loc = loc.replace('\\', '/');

  return (
    filter.regex.test(loc) ||
    filter.regex.test(`/${loc}`) ||
    (filterByBasename && filter.regex.test(basename)) ||
    mm.isMatch(loc, filter.pattern)
  );
}
github GoogleContainerTools / kpt / site / node_modules / anymatch / index.js View on Github external
function testCriteria(criterion, index) {
    var result;
    switch (Object.prototype.toString.call(criterion)) {
    case '[object String]':
      result = string === criterion || altString && altString === criterion;
      result = result || micromatch.isMatch(string, criterion);
      break;
    case '[object RegExp]':
      result = criterion.test(string) || altString && criterion.test(altString);
      break;
    case '[object Function]':
      result = criterion.apply(null, value);
      result = result || altValue && criterion.apply(null, altValue);
      break;
    default:
      result = false;
    }
    if (result) {
      matchIndex = index + startIndex;
    }
    return result;
  }
github DSchau / gatsby-remark-toc / src / index.js View on Github external
module.exports = function generateTOCNodes(
  { markdownNode, markdownAST },
  {
    include = [],
    header = 'Table of Contents',
    useExistingHeader = false,
    orderedList = false,
    mdastUtilTocOptions = {}
  }
) {
  const filePath = markdownNode.fileAbsolutePath
    .split(process.cwd())
    .pop()
    .replace(/^\//, '');
  const isIncluded = mm.isMatch(filePath, include);

  if (!isIncluded) {
    return;
  }

  const index = markdownAST.children.findIndex(node => {
    if (useExistingHeader) {
      if (node.type === 'heading') {
        return node.children.findIndex(child => child.value === header) + 1;
      }
      return false;
    }
    return node.type !== 'yaml';
  });

  if (index < 0) {
github micromatch / glob-fs / middleware / any.js View on Github external
module.exports = function any(fp, patterns, options) {
  options = options || {};
  var res = {is: [], isnt: []};
  res.file = fp;
  var len = patterns.length;
  var i = -1;

  while (++i < len) {
    var pattern = patterns[i];
    if (mm.isMatch(fp, pattern, {dot: true, contains: true})) {
      res.is.push(pattern);
      break;
    } else {
      res.isnt.push(pattern);
    }
  }
  return res;
};
github flegall / monopack / scripts / build.js View on Github external
function buildFile(file, silent) {
  const destPath = getBuildPath(file, BUILD_DIR);

  mkdirp.sync(path.dirname(destPath));
  if (micromatch.isMatch(file, IGNORE_PATTERN)) {
    silent ||
      process.stdout.write(
        chalk.dim('  \u2022 ') +
          path.relative(PACKAGES_DIR, file) +
          ' (ignore)\n'
      );
  } else if (!micromatch.isMatch(file, JS_FILES_PATTERN)) {
    fs.createReadStream(file).pipe(fs.createWriteStream(destPath));
    silent ||
      process.stdout.write(
        chalk.red('  \u2022 ') +
          path.relative(PACKAGES_DIR, file) +
          chalk.red(' \u21D2 ') +
          path.relative(PACKAGES_DIR, destPath) +
          ' (copy)' +
          '\n'
github d4rkr00t / whybundled / lib / analyze.js View on Github external
reason =>
          !mm.isMatch(reason.clearName || reason.moduleName || "", ignore)
      );
github parcel-bundler / parcel / packages / resolvers / default / src / DefaultResolver.js View on Github external
function hasSideEffects(filePath: FilePath, pkg: InternalPackageJSON) {
  switch (typeof pkg.sideEffects) {
    case 'boolean':
      return pkg.sideEffects;
    case 'string':
      return micromatch.isMatch(
        path.relative(pkg.pkgdir, filePath),
        pkg.sideEffects,
        {matchBase: true},
      );
    case 'object':
      return pkg.sideEffects.some(sideEffects =>
        hasSideEffects(filePath, {...pkg, sideEffects}),
      );
  }

  return true;
}
github wooline / react-coat-helloworld / scripts / demo.js View on Github external
    if (passUrls.some(reg => mm.isMatch(req.url, reg))) {
      next();
github d4rkr00t / whybundled / commands / default.js View on Github external
const modules = report.modules.filter(module => {
    if (pattern && mm.isMatch(module.name, pattern, { format })) {
      return true;
    } else if (pattern) {
      return false;
    }

    if (flags.filesOnly && module.type !== "file") return false;
    if (flags.modulesOnly && module.type !== "module") return false;

    if (flags.directOnly && module.depsType !== "direct") return false;
    if (flags.transitiveOnly && module.depsType !== "transitive") return false;
    if (flags.duplicatesOnly && (module.locations || []).length < 2)
      return false;

    return true;
  });

micromatch

Glob matching for javascript/node.js. A replacement and faster alternative to minimatch and multimatch.

MIT
Latest version published 4 months ago

Package Health Score

92 / 100
Full package analysis