How to use picomatch - 10 common examples

To help you get started, we’ve selected a few picomatch 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 pencil-js / pencil.js / modules / sprite / sprite.js View on Github external
const filter = ((matcher) => {
            if (typeof matcher === "function") {
                return matcher;
            }
            if (typeof matcher === "string") {
                const glob = picomatch(matcher);
                return string => matcher === string || glob(string);
            }
            if (matcher instanceof RegExp) {
                return string => matcher.test(string);
            }
            return () => false;
        })(selector);
github adonisjs / assembler / src / RcFile / index.ts View on Github external
public rcFilePath = resolveFrom(this.appRoot, `./${RCFILE_NAME}`)

  /**
   * Raw rcfile contents
   */
  public raw = this.getDiskContents()

  /**
   * Reference to application
   */
  public application = new Application(this.appRoot, new Ioc(), this.raw, {})

  /**
   * A matcher to know if a file is part of the meta files globs
   */
  public isMetaFile: (filePath: string) => boolean = picomatch(this.getMetaFilesGlob())

  /**
   * A matcher to know if a file is part of the restart server files globs
   */
  public isRestartServerFile: (filePath: string) => boolean = picomatch(this.getRestartServerFilesGlob())

  /**
   * Commands match to know, if file path is part of the commands paths defined
   * inside `.adonisrc.json` file
   */
  public isCommandsPath: (filePath: string) => boolean = picomatch(this.commandsGlob())

  constructor (private appRoot: string) {
  }

  /**
github adonisjs / assembler / src / RcFile / index.ts View on Github external
public raw = this.getDiskContents()

  /**
   * Reference to application
   */
  public application = new Application(this.appRoot, new Ioc(), this.raw, {})

  /**
   * A matcher to know if a file is part of the meta files globs
   */
  public isMetaFile: (filePath: string) => boolean = picomatch(this.getMetaFilesGlob())

  /**
   * A matcher to know if a file is part of the restart server files globs
   */
  public isRestartServerFile: (filePath: string) => boolean = picomatch(this.getRestartServerFilesGlob())

  /**
   * Commands match to know, if file path is part of the commands paths defined
   * inside `.adonisrc.json` file
   */
  public isCommandsPath: (filePath: string) => boolean = picomatch(this.commandsGlob())

  constructor (private appRoot: string) {
  }

  /**
   * Returns true when file is `.adonisrc.json` itself
   */
  public isRcFile (filePath: string) {
    return filePath === RCFILE_NAME
  }
github adonisjs / assembler / src / RcFile / index.ts View on Github external
/**
   * A matcher to know if a file is part of the meta files globs
   */
  public isMetaFile: (filePath: string) => boolean = picomatch(this.getMetaFilesGlob())

  /**
   * A matcher to know if a file is part of the restart server files globs
   */
  public isRestartServerFile: (filePath: string) => boolean = picomatch(this.getRestartServerFilesGlob())

  /**
   * Commands match to know, if file path is part of the commands paths defined
   * inside `.adonisrc.json` file
   */
  public isCommandsPath: (filePath: string) => boolean = picomatch(this.commandsGlob())

  constructor (private appRoot: string) {
  }

  /**
   * Returns true when file is `.adonisrc.json` itself
   */
  public isRcFile (filePath: string) {
    return filePath === RCFILE_NAME
  }

  /**
   * Reloads the rcfile.json bypassing the require cache
   */
  public getDiskContents (): any {
    return importFresh(this.rcFilePath) as any
github micromatch / micromatch / index.js View on Github external
micromatch.capture = (glob, input, options) => {
  let posix = utils.isWindows(options);
  let regex = picomatch.makeRe(String(glob), { ...options, capture: true });
  let match = regex.exec(posix ? utils.toPosixSlashes(input) : input);

  if (match) {
    return match.slice(1).map(v => v === void 0 ? '' : v);
  }
};
github micromatch / micromatch / index.js View on Github external
micromatch.parse = (patterns, options) => {
  let res = [];
  for (let pattern of [].concat(patterns || [])) {
    for (let str of braces(String(pattern), options)) {
      res.push(picomatch.parse(str, options));
    }
  }
  return res;
};
github jonschlinkert / matched / lib / utils.js View on Github external
exports.sift = (patterns, options = {}) => {
  let results = { includes: [], excludes: [], globs: 0 };
  let index = 0;

  for (let pattern of [].concat(patterns || [])) {
    if (typeof pattern !== 'string') return null;
    let res = picomatch.scan(pattern);
    res.pattern = path.posix.join(res.base, res.glob);
    res.index = index++;

    if (res.isGlob) results.globs++;
    if (options.relative) {
      res.pattern = exports.toRelative(res.pattern, options);
      delete options.cwd;
    }

    if (res.negated) {
      results.excludes.push(res);
    } else {
      results.includes.push(res);
    }
  }
  return results;
github micromatch / micromatch / index.js View on Github external
micromatch.matchKeys = (obj, patterns, options) => {
  if (!utils.isObject(obj)) {
    throw new TypeError('Expected the first argument to be an object');
  }
  let keys = micromatch(Object.keys(obj), patterns, options);
  let res = {};
  for (let key of keys) res[key] = obj[key];
  return res;
};
github micromatch / micromatch / index.js View on Github external
micromatch.capture = (glob, input, options) => {
  let posix = utils.isWindows(options);
  let regex = picomatch.makeRe(String(glob), { ...options, capture: true });
  let match = regex.exec(posix ? utils.toPosixSlashes(input) : input);

  if (match) {
    return match.slice(1).map(v => v === void 0 ? '' : v);
  }
};
github micromatch / micromatch / index.js View on Github external
micromatch.capture = (glob, input, options) => {
  let posix = utils.isWindows(options);
  let regex = picomatch.makeRe(String(glob), { ...options, capture: true });
  let match = regex.exec(posix ? utils.toPosixSlashes(input) : input);

  if (match) {
    return match.slice(1).map(v => v === void 0 ? '' : v);
  }
};

picomatch

Blazing fast and accurate glob matcher written in JavaScript, with no dependencies and full support for standard and extended Bash glob features, including braces, extglobs, POSIX brackets, and regular expressions.

MIT
Latest version published 30 days ago

Package Health Score

92 / 100
Full package analysis