Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
parse-gitignore
Advanced tools
Parse a gitignore file into an array of patterns. Comments and empty lines are stripped.
The parse-gitignore npm package is used to parse .gitignore files and return an array of patterns specified in the file. This can be useful for various tasks such as filtering files, generating ignore lists, or integrating with other tools that need to respect .gitignore rules.
Parse .gitignore file
This feature allows you to read and parse a .gitignore file, returning an array of patterns specified in the file. This can be useful for filtering files or integrating with other tools.
const parseGitignore = require('parse-gitignore');
const fs = require('fs');
const gitignoreContent = fs.readFileSync('.gitignore', 'utf8');
const patterns = parseGitignore(gitignoreContent);
console.log(patterns);
Parse .gitignore from a string
This feature allows you to parse .gitignore content from a string, which can be useful if you have the content in memory or from another source.
const parseGitignore = require('parse-gitignore');
const gitignoreContent = 'node_modules\n.DS_Store\n';
const patterns = parseGitignore(gitignoreContent);
console.log(patterns);
The 'ignore' package is a more feature-rich alternative that not only parses .gitignore files but also provides functionality to filter paths based on the parsed patterns. It supports multiple ignore file formats and is highly configurable.
The 'gitignore-parser' package is another alternative that focuses on parsing .gitignore files and provides methods to check if a given path should be ignored based on the parsed patterns. It is simpler than 'ignore' but more feature-rich than 'parse-gitignore'.
Parse a gitignore file into an array of patterns. Comments and empty lines are stripped.
Install with npm
$ npm i parse-gitignore --save
var gitignore = require('parse-gitignore');
// pass a filepath
var patterns = gitignore('.gitignore');
//=> ['*.DS_Store', 'node_modules', ...];
Pass additional patterns
Since the function already does unique-ifying on patterns, you can optionally pass an additional array of patterns to add to the patterns parsed from .gitignore
:
gitignore('.gitignore', ['foo', 'bar']);
//=> ['*.DS_Store', 'node_modules', 'foo', 'bar', ...]
true
if the given string looks like a glob pattern.Install dev dependencies:
$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Jon Schlinkert
Copyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on July 09, 2015.
FAQs
Parse a .gitignore or .npmignore file into an array of patterns.
The npm package parse-gitignore receives a total of 461,514 weekly downloads. As such, parse-gitignore popularity was classified as popular.
We found that parse-gitignore demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.