UNPKG

@stryke/path

Version:

A package containing various utilities that expand the functionality of NodeJs's built-in `path` module

44 lines 1.27 kB
//#region src/glob-to-regex.d.ts /** * Options for the `globToRegex` function. */ interface GlobToRegexOptions { /** * Enables globstar support (`**`). * * @defaultValue true */ globstar?: boolean; /** * Flags to use for the generated regular expression. */ flags?: string; } /** * Converts a glob pattern to a regular expression. * * @see https://mergify.com/blog/origin-and-evolution-of-the-globstar * @see https://en.wikipedia.org/wiki/Glob_(programming) * * @remarks * This function converts a glob pattern (like `*.{js,ts}` or `**\/src/**`) into a regular expression * * @example * ```ts * import { globToRegex } from "@stryke/path/glob-to-regex"; * * const test1 = globToRegex("*.{js,ts}"); * console.log(test1); // Output: /^([^/]*)\.(js|ts)$/ * * const test2 = globToRegex("**\/src/**"); * console.log(test2); // Output: /^((?:[^/]*(?:\/|$))*)?\/src\/((?:[^/]*(?:\/|$))*)?$/ * ``` * * @param glob - The glob pattern to convert. * @param options - The options for the conversion. * @returns The converted regular expression. */ declare function globToRegex(glob: string, options?: GlobToRegexOptions): RegExp; //#endregion export { GlobToRegexOptions, globToRegex }; //# sourceMappingURL=glob-to-regex.d.mts.map