How to use the micromatch 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 babel / babel / packages / babel-core / src / config / build-config-chain.js View on Github external
if (res.some(re => re.test(context.filename))) return true;
  if (fns.some(fn => fn(filename))) return true;

  if (strings.length > 0) {
    const possibleDirs = getPossibleDirs(context);

    const absolutePatterns = strings.map(pattern => {
      // Preserve the "!" prefix so that micromatch can use it for negation.
      const negate = pattern[0] === "!";
      if (negate) pattern = pattern.slice(1);

      return (negate ? "!" : "") + path.resolve(dirname, pattern);
    });

    if (
      micromatch(possibleDirs, absolutePatterns, { nocase: true }).length > 0
    ) {
      return true;
    }
  }

  return false;
}
github yarnpkg / yarn / __tests__ / package-hoister.js View on Github external
test('match glob pattern', () => {
      expect(mm(paths, '**')).toEqual(paths);
      expect(mm(paths, '*')).toEqual(['a']);

      expect(mm(paths, 'a/*')).toEqual(['a/b', 'a/d']);
      expect(mm(paths, 'a/**')).toEqual(['a/b', 'a/b/c', 'a/b/c/d', 'a/d']);
      expect(mm(paths, '*/a')).toEqual(['d/a']);
      expect(mm(paths, '**/a')).toEqual(['a', 'd/a', 'e/d/a']);
      expect(mm(paths, '*/a/*')).toEqual(['d/a/e']);
      expect(mm(paths, '**/a/**')).toEqual(['a/b', 'a/b/c', 'a/b/c/d', 'a/d', 'd/a/e', 'd/a/e/b']);
    });
  });
github yarnpkg / yarn / __tests__ / package-hoister.js View on Github external
test('match explicit path', () => {
      expect(mm(paths, 'a')).toEqual(['a']);
      expect(mm(paths, 'b/c')).toEqual(['b/c']);
      expect(mm(paths, 'd')).toEqual([]);
      expect(mm(paths, 'a/b')).toEqual(['a/b']);
    });
    test('match glob pattern', () => {
github yarnpkg / yarn / __tests__ / package-hoister.js View on Github external
test('match glob pattern', () => {
      expect(mm(paths, '**')).toEqual(paths);
      expect(mm(paths, '*')).toEqual(['a']);

      expect(mm(paths, 'a/*')).toEqual(['a/b', 'a/d']);
      expect(mm(paths, 'a/**')).toEqual(['a/b', 'a/b/c', 'a/b/c/d', 'a/d']);
      expect(mm(paths, '*/a')).toEqual(['d/a']);
      expect(mm(paths, '**/a')).toEqual(['a', 'd/a', 'e/d/a']);
      expect(mm(paths, '*/a/*')).toEqual(['d/a/e']);
      expect(mm(paths, '**/a/**')).toEqual(['a/b', 'a/b/c', 'a/b/c/d', 'a/d', 'd/a/e', 'd/a/e/b']);
    });
  });
github yarnpkg / yarn / __tests__ / package-hoister.js View on Github external
test('match glob pattern', () => {
      expect(mm(paths, '**')).toEqual(paths);
      expect(mm(paths, '*')).toEqual(['a']);

      expect(mm(paths, 'a/*')).toEqual(['a/b', 'a/d']);
      expect(mm(paths, 'a/**')).toEqual(['a/b', 'a/b/c', 'a/b/c/d', 'a/d']);
      expect(mm(paths, '*/a')).toEqual(['d/a']);
      expect(mm(paths, '**/a')).toEqual(['a', 'd/a', 'e/d/a']);
      expect(mm(paths, '*/a/*')).toEqual(['d/a/e']);
      expect(mm(paths, '**/a/**')).toEqual(['a/b', 'a/b/c', 'a/b/c/d', 'a/d', 'd/a/e', 'd/a/e/b']);
    });
  });
github percy / react-percy / packages / react-percy-config / src / __tests__ / defaults-tests.js View on Github external
const expectFileToMatchPatterns = (file, patterns) => {
  const matches = micromatch([file], patterns);
  expect(matches).toEqual([file]);
};
github saojs / kopy / src / transform.js View on Github external
globs.map(glob => {
      const handler = transforms[glob]
      const filepaths = match(stream.fileList, glob)
      return Promise.all(
        filepaths.map(filepath => {
          return handler(filepath, stream)
        })
      )
    })
  )
github adana-coverage / babel-plugin-transform-adana / src / instrumenter.js View on Github external
export function skip({ignore, only}, file) {
  if (only) {
    return micromatch(
      [file],
      Array.isArray(only) ? only : [only],
      {nocase: true}
    ).length <= 0;
  }
  if (ignore) {
    return micromatch(
      [file],
      Array.isArray(ignore) ? ignore : [ignore],
      {nocase: true}
    ).length > 0;
  }
  return false;
}

micromatch

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

MIT
Latest version published 2 years ago

Package Health Score

87 / 100
Full package analysis