import { Glob } from 'glob'; import * as minimatch from 'minimatch'; export interface IGlobOptions { nodir?: boolean; dot?: boolean; ignore?: string; } /** * Matches the given glob pattern as a promise. * See: * https://www.npmjs.com/package/glob */ export function find( pattern: string, options: IGlobOptions = {}, ): Promise { return new Promise((resolve, reject) => { new Glob(pattern, options, (err, matches) => { // tslint:disable-line if (err) { reject(err); } else { resolve(matches); } }); }); } export type IGlobMatchOptions = { debug?: boolean; }; /** * Determines if the given path matches a glob pattern. */ export function isMatch( pattern: string, path: string, options: IGlobMatchOptions = {}, ) { return minimatch(path, pattern, options); } /** * Returns a glob pattern matcher */ export function matcher(pattern: string, options: IGlobMatchOptions = {}) { const args = options; return (path: string, options: IGlobMatchOptions = {}) => { return isMatch(pattern, path, { ...args, ...options }); }; }