JSPM

  • Created
  • Published
  • Downloads 90435780
  • Score
    100M100P100Q248548F
  • License MIT

Ignore is a manager and filter for .gitignore rules.

Package Exports

  • ignore

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ignore) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Build Status

ignore

ignore is a manager and filter for .gitignore rules.

Installation

npm install ignore --save

Usage

var ignore = require('ignore');
var ig = ignore({
    ignore: [
        '.abc/*' // or use the `.add()` method
    ]

}).add('!.abc/d/');

var paths = [
    '.abc/a.js',    // filtered out
    '.abc/d/e.js'   // included
];

ig.filter(paths); // ['.abc/d/e.js']
paths.filter(ig.createFilter()); // ['.abc/d/e.js']

Why another ignore?

  1. ignore is a standalone module, and is much simpler so that it could easily work with other programs, unlike isaacs's fstream-ignore which must work with the modules of the fstream family.

  2. ignore only contains utility methods to filter paths according to the specified ignore rules.

  3. Exactly according to gitignore man page, fixes some known matching issues of fstream-ignore, such as:

    • '/*.js' should match 'a.js', but not 'abc/a.js'.
    • '**/foo' should match 'foo' anywhere.

Methods

.add(rule)

Adds a rule or several rules to the current manager.

Returns this

Rule String|Array.<String>

The ignore rule or a array of rules.

.filter(paths)

Filters the given array of pathnames, and returns the filtered array.

paths Array

The array of paths to be filtered

.createFilter()

Creates a filter function which could be used with Array.prototype.filter.

Returns function(path)

The filter function.

Constructor: ignore.Ignore

new ignore.Ignore(options);
ignore(options);

options.noCase boolean=true

By default, all ignore rules will be treated as case-insensitive ones as well as the git does.

options.twoGlobstars boolean=false

By defailt, ignoreRules will omit every pattern that includes '**' (two consecutive asterisks) which is not compatible cross operating systems, because the behavior of file .gitignore depends on the implementation of command fnmatch in shell.

By the way, Mac OS doesn't support '**'.

options.ignore Array.<String>

The ignore rules to be added.

You can also use .add() method to do this.