https://github.com/jedwards1211/gitignore-fs
determine if any file is gitignored (complete Node.js implementation of gitignore rules)
https://github.com/jedwards1211/gitignore-fs
git gitignore
Last synced: 11 months ago
JSON representation
determine if any file is gitignored (complete Node.js implementation of gitignore rules)
- Host: GitHub
- URL: https://github.com/jedwards1211/gitignore-fs
- Owner: jedwards1211
- License: mit
- Created: 2021-06-04T04:04:43.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-10-15T15:35:36.000Z (over 2 years ago)
- Last Synced: 2025-07-25T14:25:23.182Z (11 months ago)
- Topics: git, gitignore
- Language: TypeScript
- Homepage:
- Size: 728 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# gitignore-fs
[](https://circleci.com/gh/jedwards1211/gitignore-fs)
[](https://codecov.io/gh/jedwards1211/gitignore-fs)
[](https://github.com/semantic-release/semantic-release)
[](http://commitizen.github.io/cz-cli/)
[](https://badge.fury.io/js/gitignore-fs)
If you're using a library to ignore gitignored files, it probably doesn't do it right! Use this library to be match git behavior 100%.
Determine if any file is gitignored. This is intended to be a complete implementation of the gitignore spec, including `$GIT_DIR`, `$GIT_DIR/info/excludes`, and the `core.excludesFile` configuration variable.
**Requires Node >= 8.**
# Getting started
```
npm install --save gitignore-fs
```
```js
const Gitignore = require('gitignore-fs')
const gitignore = new Gitignore()
console.log(gitignore.ignoresSync('node_modules')) // true or false depending on your config
```
# API
## `class Gitignore`
Each instance of this class keeps a separate cache of gitignore rules.
### `new Gitignore([options])`
Creates a new Gitignore instance.
#### `options.initialRules` (`string[]`, _optional_)
These rules will be applied at lowest precedence (lower than rules from `core.excludesFile`).
Paths with a slash in the beginning or middle are relative to the closest enclosing git directory.
#### `options.finalRules` (`string[]`, _optional_)
These rules will be applied at highest precedence (higher than `.gitignore` files).
Paths with a slash in the beginning or middle are relative to the closest enclosing git directory.
### `.ignores(path)`
Determines if the given `path` is gitignored asynchronously.
#### `path` (`string`, **required**)
The path to test. **Must end with / if it is a directory!**
#### Returns (`Promise`)
A promise that will resolve to `true` if `path` is gitignored, `false` otherwise
### `.ignoresSync(path)`
Determines if the given `path` is gitignored synchronously.
#### `path` (`string`, **required**)
The path to test. **Must end with / if it is a directory!**
#### Returns (`boolean`)
`true` if `path` is gitignored, `false` otherwise
### `.clearCache()`
Clears the entire gitignore rule cache.