# git-ignore-parser

> A Node.js module to parse raw gitignore data

Latest version **0.0.2** (published 2017-05-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install git-ignore-parser
pnpm add git-ignore-parser
yarn add git-ignore-parser
bun add git-ignore-parser
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2017-05-23 |
| First published | 2016-07-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Clément Paris |
| Maintainers | clementparis016 |
| Keywords | git, git-ignore, .gitignore, ignore, parser, cli |

## Links

- npm: https://www.npmjs.com/package/git-ignore-parser
- Repository: https://github.com/clementparis016/git-ignore-parser
- Homepage: https://github.com/clementparis016/git-ignore-parser#readme
- Issues: https://github.com/clementparis016/git-ignore-parser/issues
- npm.io page: https://npm.io/package/git-ignore-parser

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.0.2 (latest) — 2017-05-23
- 0.0.1 — 2016-07-04

## README

# git-ignore-parser
> A Node.js module to parse raw gitignore data

**WARNING**: this tool is a work-in-progress and might be unstable or unsuitable for serious use.

This modules parses a raw gitignore content, as specified in the [official Git documentation](https://git-scm.com/docs/gitignore#_pattern_format), and returns an array of ignored paths that Git will look against.

## Installation
```
npm install git-ignore-parser
```

## Usage
Given this `.gitignore` file:
```.gitignore
# Logs
logs/
*.log
npm-debug.log*

# Dependency directories
/node_modules/
jspm_packages
```

It would return the following:
```js
const fs = require('fs');
const gitIgnoreParser = require('git-ignore-parser');

fs.readFile('.gitignore', 'utf-8', (error, data) {
  if (!error) {
    const ignoredPaths = gitIgnoreParser(data);
    console.log(ignoredPaths);
      // >> ['logs', '*.log', 'npm-debug.log*', 'node_modules', 'jspm_packages']
  }
});
```

## Parsing rules
The parser will apply the following rules, as specified in the [official Git documentation](https://git-scm.com/docs/gitignore#_pattern_format):

- Empty lines are ignored
- Lines starting with a `#` are treated as comments and are ignored
- Trailing spaces are ignored
- Trailing slashes are ignored
- Duplicates are ignored
- Globs and negative patterns are treated as is

## License
[The MIT License](https://opensource.org/licenses/MIT) © [Clément Paris](http://www.clementparis.fr)

---
_Source: https://npm.io/package/git-ignore-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
