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, and returns an array of ignored paths that Git will look against.
Installation
npm install git-ignore-parser
Usage
Given this .gitignore
file:
# Logslogs/*.lognpm-debug.log* # Dependency directories/node_modules/jspm_packages
It would return the following:
const fs = ;const gitIgnoreParser = ; fs;
Parsing rules
The parser will apply the following rules, as specified in the official Git documentation:
- 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