Skip to content

Commit

Permalink
Export isIgnoredByIgnoreFiles and isIgnoredByIgnoreFilesSync func…
Browse files Browse the repository at this point in the history
…tions (#269)

Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
jiawei397 and sindresorhus authored Feb 7, 2025
1 parent c000568 commit cba8941
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
48 changes: 48 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,51 @@ export function isGitIgnored(options?: GitignoreOptions): Promise<GlobbyFilterFu
export function isGitIgnoredSync(options?: GitignoreOptions): GlobbyFilterFunction;

export function convertPathToPattern(source: string): FastGlob.Pattern;

/**
Check if a path is ignored by the ignore files.
@param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
@param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.
@returns A filter function indicating whether a given path is ignored via the ignore files.
This 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.
@example
```
import {isIgnoredByIgnoreFiles} from 'globby';
const isIgnored = await isIgnoredByIgnoreFiles('**\/.gitignore');
console.log(isIgnored('some/file'));
```
*/
export function isIgnoredByIgnoreFiles(
patterns: string | readonly string[],
options?: Options
): Promise<GlobbyFilterFunction>;

/**
Check if a path is ignored by the ignore files.
@param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
@param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.
@returns A filter function indicating whether a given path is ignored via the ignore files.
This 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.
@see {@link isIgnoredByIgnoreFiles}
@example
```
import {isIgnoredByIgnoreFilesSync} from 'globby';
const isIgnored = isIgnoredByIgnoreFilesSync('**\/.gitignore');
console.log(isIgnored('some/file'));
```
*/
export function isIgnoredByIgnoreFilesSync(
patterns: string | readonly string[],
options?: Options
): GlobbyFilterFunction;
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ export const generateGlobTasksSync = normalizeArgumentsSync(generateTasksSync);
export {
isGitIgnored,
isGitIgnoredSync,
isIgnoredByIgnoreFiles,
isIgnoredByIgnoreFilesSync,
} from './ignore.js';

export const {convertPathToPattern} = fastGlob;
33 changes: 33 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,39 @@ Returns a `(path: URL | string) => boolean` indicating whether a given path is i

Takes `cwd?: URL | string` as options.


### isIgnoredByIgnoreFiles(patterns, options?)

Returns a `Promise<(path: URL | string) => boolean>` indicating whether a given path is ignored via the ignore files.

This 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.

Takes `cwd?: URL | string` as options.

```js
import {isIgnoredByIgnoreFiles} from 'globby';

const isIgnored = await isIgnoredByIgnoreFiles("**/.gitignore");

console.log(isIgnored('some/file'));
```

### isIgnoredByIgnoreFilesSync(patterns, options?)

Returns a `(path: URL | string) => boolean` indicating whether a given path is ignored via the ignore files.

This 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.

Takes `cwd?: URL | string` as options.

```js
import {isIgnoredByIgnoreFilesSync} from 'globby';

const isIgnored = isIgnoredByIgnoreFilesSync("**/.gitignore");

console.log(isIgnored('some/file'));
```

## Globbing patterns

Just a quick overview.
Expand Down

0 comments on commit cba8941

Please sign in to comment.