|
| 1 | +import {IOptions as NodeGlobOptions} from 'glob'; |
| 2 | +import {Options as FastGlobOptions} from 'fast-glob'; |
| 3 | + |
| 4 | +export type ExpandDirectoriesOption = |
| 5 | + | boolean |
| 6 | + | ReadonlyArray<string> |
| 7 | + | {files: ReadonlyArray<string>; extensions: ReadonlyArray<string>}; |
| 8 | + |
| 9 | +export interface GlobbyOptions extends FastGlobOptions { |
| 10 | + /** |
| 11 | + * If set to `true`, `globby` will automatically glob directories for you. If you define an `Array` it will only glob files that matches the patterns inside the `Array`. You can also define an `Object` with `files` and `extensions` like in the example below. |
| 12 | + * |
| 13 | + * Note that if you set this option to `false`, you won't get back matched directories unless you set `onlyFiles: false`. |
| 14 | + * |
| 15 | + * @default true |
| 16 | + * |
| 17 | + * @example |
| 18 | + * |
| 19 | + * import globby from 'globby'; |
| 20 | + * |
| 21 | + * (async () => { |
| 22 | + * const paths = await globby('images', { |
| 23 | + * expandDirectories: { |
| 24 | + * files: ['cat', 'unicorn', '*.jpg'], |
| 25 | + * extensions: ['png'] |
| 26 | + * } |
| 27 | + * }); |
| 28 | + * console.log(paths); |
| 29 | + * //=> ['cat.png', 'unicorn.png', 'cow.jpg', 'rainbow.jpg'] |
| 30 | + * })(); |
| 31 | + */ |
| 32 | + readonly expandDirectories?: ExpandDirectoriesOption; |
| 33 | + |
| 34 | + /** |
| 35 | + * Respect ignore patterns in `.gitignore` files that apply to the globbed files. |
| 36 | + * |
| 37 | + * @default false |
| 38 | + */ |
| 39 | + readonly gitignore?: boolean; |
| 40 | +} |
| 41 | + |
| 42 | +/** |
| 43 | + * @param patterns - See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage). |
| 44 | + * @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-1) in addition to the ones in this package. |
| 45 | + * @returns A `Promise<Array>` of matching paths. |
| 46 | + */ |
| 47 | +export default function globby( |
| 48 | + patterns: string | ReadonlyArray<string>, |
| 49 | + options?: GlobbyOptions |
| 50 | +): Promise<string[]>; |
| 51 | + |
| 52 | +/** |
| 53 | + * @param patterns - See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage). |
| 54 | + * @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-1) in addition to the ones in this package. |
| 55 | + * @returns An `Array` of matching paths. |
| 56 | + */ |
| 57 | +export function sync( |
| 58 | + patterns: string | ReadonlyArray<string>, |
| 59 | + options?: GlobbyOptions |
| 60 | +): string[]; |
| 61 | + |
| 62 | +export interface GlobTask { |
| 63 | + readonly pattern: string; |
| 64 | + readonly options: GlobbyOptions; |
| 65 | +} |
| 66 | + |
| 67 | +/** |
| 68 | + * Note that you should avoid running the same tasks multiple times as they contain a file system cache. Instead, run this method each time to ensure file system changes are taken into consideration. |
| 69 | + * |
| 70 | + * @param patterns - See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage). |
| 71 | + * @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-1) in addition to the ones in this package. |
| 72 | + * @returns An `Array<Object>` in the format `{ pattern: string, options: Object }`, which can be passed as arguments to [`fast-glob`](https://github.com/mrmlnc/fast-glob). This is useful for other globbing-related packages. |
| 73 | + */ |
| 74 | +export function generateGlobTasks( |
| 75 | + patterns: string | ReadonlyArray<string>, |
| 76 | + options?: GlobbyOptions |
| 77 | +): GlobTask[]; |
| 78 | + |
| 79 | +/** |
| 80 | + * Note that the options affect the results. If `noext: true` is set, then `+(a|b)` will not be considered a magic pattern. If the pattern has a brace expansion, like `a/{b/c,x/y}`, then that is considered magical, unless `nobrace: true` is set. |
| 81 | + * |
| 82 | + * This function is backed by [`node-glob`](https://github.com/isaacs/node-glob#globhasmagicpattern-options). |
| 83 | + * |
| 84 | + * @param patterns - See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage). |
| 85 | + * @param options - See the [`node-glob` options](https://github.com/isaacs/node-glob#globhasmagicpattern-options). |
| 86 | + * @returns A boolean of whether there are any special glob characters in the `patterns`. |
| 87 | + */ |
| 88 | +export function hasMagic( |
| 89 | + patterns: string | ReadonlyArray<string>, |
| 90 | + options?: NodeGlobOptions |
| 91 | +): boolean; |
| 92 | + |
| 93 | +export interface GitignoreOptions { |
| 94 | + readonly cwd?: string; |
| 95 | + readonly ignore?: ReadonlyArray<string>; |
| 96 | +} |
| 97 | + |
| 98 | +export type FilterFunction = (path: string) => boolean; |
| 99 | + |
| 100 | +export interface Gitignore { |
| 101 | + (options?: GitignoreOptions): Promise<FilterFunction>; |
| 102 | + |
| 103 | + /** |
| 104 | + * @returns A filter function indicating whether a given path is ignored via a `.gitignore` file. |
| 105 | + */ |
| 106 | + sync(options?: GitignoreOptions): FilterFunction; |
| 107 | +} |
| 108 | + |
| 109 | +/** |
| 110 | + * `.gitignore` files matched by the ignore config are not used for the resulting filter function. |
| 111 | + * |
| 112 | + * @returns A `Promise` for a filter function indicating whether a given path is ignored via a `.gitignore` file. |
| 113 | + * |
| 114 | + * @example |
| 115 | + * |
| 116 | + * import {gitignore} from 'globby'; |
| 117 | + * |
| 118 | + * (async () => { |
| 119 | + * const isIgnored = await gitignore(); |
| 120 | + * console.log(isIgnored('some/file')); |
| 121 | + * })(); |
| 122 | + */ |
| 123 | +export const gitignore: Gitignore; |
0 commit comments