basant307/AI_Governance_Project
048
1# globby2 3> User-friendly glob matching4 5Based on [`fast-glob`](https://github.com/mrmlnc/fast-glob) but adds a bunch of useful features.6 7## Features8 9- Promise API10- Multiple patterns11- Negated patterns: `['foo*', '!foobar']`12- Expands directories: `foo` → `foo/**/*`13- Supports `.gitignore` and similar ignore config files14- Supports `URL` as `cwd`15 16## Install17 18```sh19npm install globby20```21 22## Usage23 24```25├── unicorn26├── cake27└── rainbow28```29 30```js31import {globby} from 'globby';32 33const paths = await globby(['*', '!cake']);34 35console.log(paths);36//=> ['unicorn', 'rainbow']37```38 39## API40 41Note that glob patterns can only contain forward-slashes, not backward-slashes, so if you want to construct a glob pattern from path components, you need to use `path.posix.join()` instead of `path.join()`.42 43### globby(patterns, options?)44 45Returns a `Promise<string[]>` of matching paths.46 47#### patterns48 49Type: `string | string[]`50 51See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage).52 53#### options54 55Type: `object`56 57See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones below.58 59##### expandDirectories60 61Type: `boolean | string[] | object`\62Default: `true`63 64If 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 below:65 66```js67import {globby} from 'globby';68 69const paths = await globby('images', {70 expandDirectories: {71 files: ['cat', 'unicorn', '*.jpg'],72 extensions: ['png']73 }74});75 76console.log(paths);77//=> ['cat.png', 'unicorn.png', 'cow.jpg', 'rainbow.jpg']78```79 80Note that if you set this option to `false`, you won't get back matched directories unless you set `onlyFiles: false`.81 82##### gitignore83 84Type: `boolean`\85Default: `false`86 87Respect ignore patterns in `.gitignore` files that apply to the globbed files.88 89##### ignoreFiles90 91Type: `string | string[]`\92Default: `undefined`93 94Glob patterns to look for ignore files, which are then used to ignore globbed files.95 96This is a more generic form of the `gitignore` option, allowing you to find ignore files with a [compatible syntax](http://git-scm.com/docs/gitignore). For instance, this works with Babel's `.babelignore`, Prettier's `.prettierignore`, or ESLint's `.eslintignore` files.97 98### globbySync(patterns, options?)99 100Returns `string[]` of matching paths.101 102### globbyStream(patterns, options?)103 104Returns a [`stream.Readable`](https://nodejs.org/api/stream.html#stream_readable_streams) of matching paths.105 106For example, loop over glob matches in a [`for await...of` loop](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of) like this:107 108```js109import {globbyStream} from 'globby';110 111for await (const path of globbyStream('*.tmp')) {112 console.log(path);113}114```115 116### convertPathToPattern(path)117 118Convert a path to a pattern. [Learn more.](https://github.com/mrmlnc/fast-glob#convertpathtopatternpath)119 120### generateGlobTasks(patterns, options?)121 122Returns an `Promise<object[]>` in the format `{patterns: 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.123 124Note 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.125 126### generateGlobTasksSync(patterns, options?)127 128Returns an `object[]` in the format `{patterns: 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.129 130Takes the same arguments as `generateGlobTasks`.131 132### isDynamicPattern(patterns, options?)133 134Returns a `boolean` of whether there are any special glob characters in the `patterns`.135 136Note that the options affect the results.137 138This function is backed by [`fast-glob`](https://github.com/mrmlnc/fast-glob#isdynamicpatternpattern-options).139 140### isGitIgnored(options?)141 142Returns a `Promise<(path: URL | string) => boolean>` indicating whether a given path is ignored via a `.gitignore` file.143 144Takes `cwd?: URL | string` as options.145 146```js147import {isGitIgnored} from 'globby';148 149const isIgnored = await isGitIgnored();150 151console.log(isIgnored('some/file'));152```153 154### isGitIgnoredSync(options?)155 156Returns a `(path: URL | string) => boolean` indicating whether a given path is ignored via a `.gitignore` file.157 158Takes `cwd?: URL | string` as options.159 160 161### isIgnoredByIgnoreFiles(patterns, options?)162 163Returns a `Promise<(path: URL | string) => boolean>` indicating whether a given path is ignored via the ignore files.164 165This is a more generic form of the `isGitIgnored` function, allowing you to find ignore files with a [compatible syntax](http://git-scm.com/docs/gitignore). For instance, this works with Babel's `.babelignore`, Prettier's `.prettierignore`, or ESLint's `.eslintignore` files.166 167Takes `cwd?: URL | string` as options.168 169```js170import {isIgnoredByIgnoreFiles} from 'globby';171 172const isIgnored = await isIgnoredByIgnoreFiles("**/.gitignore");173 174console.log(isIgnored('some/file'));175```176 177### isIgnoredByIgnoreFilesSync(patterns, options?)178 179Returns a `(path: URL | string) => boolean` indicating whether a given path is ignored via the ignore files.180 181This is a more generic form of the `isGitIgnoredSync` function, allowing you to find ignore files with a [compatible syntax](http://git-scm.com/docs/gitignore). For instance, this works with Babel's `.babelignore`, Prettier's `.prettierignore`, or ESLint's `.eslintignore` files.182 183Takes `cwd?: URL | string` as options.184 185```js186import {isIgnoredByIgnoreFilesSync} from 'globby';187 188const isIgnored = isIgnoredByIgnoreFilesSync("**/.gitignore");189 190console.log(isIgnored('some/file'));191```192 193## Globbing patterns194 195Just a quick overview.196 197- `*` matches any number of characters, but not `/`198- `?` matches a single character, but not `/`199- `**` matches any number of characters, including `/`, as long as it's the only thing in a path part200- `{}` allows for a comma-separated list of "or" expressions201- `!` at the beginning of a pattern will negate the match202 203[Various patterns and expected matches.](https://github.com/sindresorhus/multimatch/blob/main/test/test.js)204 205## Related206 207- [multimatch](https://github.com/sindresorhus/multimatch) - Match against a list instead of the filesystem208- [matcher](https://github.com/sindresorhus/matcher) - Simple wildcard matching209- [del](https://github.com/sindresorhus/del) - Delete files and directories210- [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed211 