Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export isIgnoredByIgnoreFiles and isIgnoredByIgnoreFilesSync for some bottom level scene #269

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,42 @@ 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.
*
* @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.
* @see {@link isIgnoredByIgnoreFiles}
*
* @example
* ```js
* 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 an ignore file.

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 an ignore file.

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