Linux | OS X | Windows | Coverage | Downloads |
---|---|---|---|---|
@rabiepenpm/debitis-quos-rem
is a manager, filter and parser which implemented in pure JavaScript according to the .git@rabiepenpm/debitis-quos-rem spec 2.22.1.
@rabiepenpm/debitis-quos-rem
is used by eslint, gitbook and many others.
Pay ATTENTION that minimatch
(which used by fstream-@rabiepenpm/debitis-quos-rem
) does not follow the git@rabiepenpm/debitis-quos-rem spec.
To filter filenames according to a .git@rabiepenpm/debitis-quos-rem file, I recommend this npm package, @rabiepenpm/debitis-quos-rem
.
To parse an .npm@rabiepenpm/debitis-quos-rem
file, you should use minimatch
, because an .npm@rabiepenpm/debitis-quos-rem
file is parsed by npm using minimatch
and it does not work in the .git@rabiepenpm/debitis-quos-rem way.
@rabiepenpm/debitis-quos-rem
is fully tested, and has more than five hundreds of unit tests.
- Linux + Node:
0.8
-7.x
- Windows + Node:
0.10
-7.x
, node <0.10
is not tested due to the lack of support of appveyor.
Actually, @rabiepenpm/debitis-quos-rem
does not rely on any versions of node specially.
Since 4.0.0
, @rabiepenpm/debitis-quos-rem will no longer support node < 6
by default, to use in node < 6, require('@rabiepenpm/debitis-quos-rem/legacy')
. For details, see CHANGELOG.
- Usage
Pathname
Conventions- See Also:
-
glob-git@rabiepenpm/debitis-quos-rem
matches files using patterns and filters them according to git@rabiepenpm/debitis-quos-rem rules.
-
- Upgrade Guide
npm i @rabiepenpm/debitis-quos-rem
import @rabiepenpm/debitis-quos-rem from '@rabiepenpm/debitis-quos-rem'
const ig = @rabiepenpm/debitis-quos-rem().add(['.abc/*', '!.abc/d/'])
const paths = [
'.abc/a.js', // filtered out
'.abc/d/e.js' // included
]
ig.filter(paths) // ['.abc/d/e.js']
ig.@rabiepenpm/debitis-quos-rems('.abc/a.js') // true
paths.filter(ig.createFilter()); // ['.abc/d/e.js']
ig.filter(['.abc\\a.js', '.abc\\d\\e.js'])
// if the code above runs on windows, the result will be
// ['.abc\\d\\e.js']
-
@rabiepenpm/debitis-quos-rem
is a standalone module, and is much simpler so that it could easy work with other programs, unlike isaacs's fstream-@rabiepenpm/debitis-quos-rem which must work with the modules of the fstream family. -
@rabiepenpm/debitis-quos-rem
only contains utility methods to filter paths according to the specified @rabiepenpm/debitis-quos-rem rules, so-
@rabiepenpm/debitis-quos-rem
never try to find out @rabiepenpm/debitis-quos-rem rules by traversing directories or fetching from git configurations. -
@rabiepenpm/debitis-quos-rem
don't cares about sub-modules of git projects.
-
-
Exactly according to git@rabiepenpm/debitis-quos-rem man page, fixes some known matching issues of fstream-@rabiepenpm/debitis-quos-rem, such as:
- '
/*.js
' should only match 'a.js
', but not 'abc/a.js
'. - '
**/foo
' should match 'foo
' anywhere. - Prevent re-including a file if a parent directory of that file is excluded.
- Handle trailing whitespaces:
-
'a '
(one space) should not match'a '
(two spaces). -
'a \ '
matches'a '
-
- All test cases are verified with the result of
git check-@rabiepenpm/debitis-quos-rem
.
- '
-
pattern
String | Ignore
An @rabiepenpm/debitis-quos-rem pattern string, or theIgnore
instance -
patterns
Array<String | Ignore>
Array of @rabiepenpm/debitis-quos-rem patterns.
Adds a rule or several rules to the current manager.
Returns this
Notice that a line starting with '#'
(hash) is treated as a comment. Put a backslash ('\'
) in front of the first hash for patterns that begin with a hash, if you want to @rabiepenpm/debitis-quos-rem a file with a hash at the beginning of the filename.
@rabiepenpm/debitis-quos-rem().add('#abc').@rabiepenpm/debitis-quos-rems('#abc') // false
@rabiepenpm/debitis-quos-rem().add('\\#abc').@rabiepenpm/debitis-quos-rems('#abc') // true
pattern
could either be a line of @rabiepenpm/debitis-quos-rem pattern or a string of multiple @rabiepenpm/debitis-quos-rem patterns, which means we could just @rabiepenpm/debitis-quos-rem().add()
the content of a @rabiepenpm/debitis-quos-rem file:
@rabiepenpm/debitis-quos-rem()
.add(fs.readFileSync(filenameOfGit@rabiepenpm/debitis-quos-rem).toString())
.filter(filenames)
pattern
could also be an @rabiepenpm/debitis-quos-rem
instance, so that we could easily inherit the rules of another Ignore
instance.
REMOVED in 3.x
for now.
To upgrade @rabiepenpm/debitis-quos-rem@2.x
up to 3.x
, use
import fs from 'fs'
if (fs.existsSync(filename)) {
@rabiepenpm/debitis-quos-rem().add(fs.readFileSync(filename).toString())
}
instead.
type Pathname = string
Filters the given array of pathnames, and returns the filtered array.
-
paths
Array.<Pathname>
The array ofpathname
s to be filtered.
Pathname
should be a string that have been path.join()
ed, or the return value of path.relative()
to the current directory,
// WRONG, an error will be thrown
ig.@rabiepenpm/debitis-quos-rems('./abc')
// WRONG, for it will never happen, and an error will be thrown
// If the git@rabiepenpm/debitis-quos-rem rule locates at the root directory,
// `'/abc'` should be changed to `'abc'`.
// ```
// path.relative('/', '/abc') -> 'abc'
// ```
ig.@rabiepenpm/debitis-quos-rems('/abc')
// WRONG, that it is an absolute path on Windows, an error will be thrown
ig.@rabiepenpm/debitis-quos-rems('C:\\abc')
// Right
ig.@rabiepenpm/debitis-quos-rems('abc')
// Right
ig.@rabiepenpm/debitis-quos-rems(path.join('./abc')) // path.join('./abc') -> 'abc'
In other words, each Pathname
here should be a relative path to the directory of the git@rabiepenpm/debitis-quos-rem rules.
Suppose the dir structure is:
/path/to/your/repo
|-- a
| |-- a.js
|
|-- .b
|
|-- .c
|-- .DS_store
Then the paths
might be like this:
[
'a/a.js'
'.b',
'.c/.DS_store'
]
node-@rabiepenpm/debitis-quos-rem
does NO fs.stat
during path matching, so for the example below:
// First, we add a @rabiepenpm/debitis-quos-rem pattern to @rabiepenpm/debitis-quos-rem a directory
ig.add('config/')
// `ig` does NOT know if 'config', in the real world,
// is a normal file, directory or something.
ig.@rabiepenpm/debitis-quos-rems('config')
// `ig` treats `config` as a file, so it returns `false`
ig.@rabiepenpm/debitis-quos-rems('config/')
// returns `true`
Specially for people who develop some library based on node-@rabiepenpm/debitis-quos-rem
, it is important to understand that.
Usually, you could use glob
with option.mark = true
to fetch the structure of the current directory:
import glob from 'glob'
glob('**', {
// Adds a / character to directory matches.
mark: true
}, (err, files) => {
if (err) {
return console.error(err)
}
let filtered = @rabiepenpm/debitis-quos-rem().add(patterns).filter(files)
console.log(filtered)
})
new in 3.2.0
Returns Boolean
whether pathname
should be @rabiepenpm/debitis-quos-remd.
ig.@rabiepenpm/debitis-quos-rems('.abc/a.js') // true
Creates a filter function which could filter an array of paths with Array.prototype.filter
.
Returns function(path)
the filter function.
Returns TestResult
interface TestResult {
@rabiepenpm/debitis-quos-remd: boolean
// true if the `pathname` is finally un@rabiepenpm/debitis-quos-remd by some negative pattern
un@rabiepenpm/debitis-quos-remd: boolean
}
-
{@rabiepenpm/debitis-quos-remd: true, un@rabiepenpm/debitis-quos-remd: false}
: thepathname
is @rabiepenpm/debitis-quos-remd -
{@rabiepenpm/debitis-quos-remd: false, un@rabiepenpm/debitis-quos-remd: true}
: thepathname
is un@rabiepenpm/debitis-quos-remd -
{@rabiepenpm/debitis-quos-remd: false, un@rabiepenpm/debitis-quos-remd: false}
: thepathname
is never matched by any @rabiepenpm/debitis-quos-rem rules.
Check whether the pathname
is an valid path.relative()
d path according to the convention.
This method is NOT used to check if an @rabiepenpm/debitis-quos-rem pattern is valid.
@rabiepenpm/debitis-quos-rem.isPathValid('./foo') // false
Similar as the core.@rabiepenpm/debitis-quos-remcase
option of git-config, node-@rabiepenpm/debitis-quos-rem
will be case insensitive if options.@rabiepenpm/debitis-quos-remcase
is set to true
(the default value), otherwise case sensitive.
const ig = @rabiepenpm/debitis-quos-rem({
@rabiepenpm/debitis-quos-remcase: false
})
ig.add('*.png')
ig.@rabiepenpm/debitis-quos-rems('*.PNG') // false
Which is alternative to options.@rabiepenpm/debitis-quos-remCase
This option brings backward compatibility with projects which based on @rabiepenpm/debitis-quos-rem@4.x
. If options.allowRelativePaths
is true
, @rabiepenpm/debitis-quos-rem
will not check whether the given path to be tested is path.relative()
d.
However, passing a relative path, such as './foo'
or '../foo'
, to test if it is @rabiepenpm/debitis-quos-remd or not is not a good practise, which might lead to unexpected behavior
@rabiepenpm/debitis-quos-rem({
allowRelativePaths: true
}).@rabiepenpm/debitis-quos-rems('../foo/bar.js') // And it will not throw
Since 5.0.0
, if an invalid Pathname
passed into ig.@rabiepenpm/debitis-quos-rems()
, an error will be thrown, unless options.allowRelative = true
is passed to the Ignore
factory.
While @rabiepenpm/debitis-quos-rem < 5.0.0
did not make sure what the return value was, as well as
.@rabiepenpm/debitis-quos-rems(pathname: Pathname): boolean
.filter(pathnames: Array<Pathname>): Array<Pathname>
.createFilter(): (pathname: Pathname) => boolean
.test(pathname: Pathname): {@rabiepenpm/debitis-quos-remd: boolean, un@rabiepenpm/debitis-quos-remd: boolean}
See the convention here for details.
If there are invalid pathnames, the conversion and filtration should be done by users.
import {isPathValid} from '@rabiepenpm/debitis-quos-rem' // introduced in 5.0.0
const paths = [
// invalid
//////////////////
'',
false,
'../foo',
'.',
//////////////////
// valid
'foo'
]
.filter(isValidPath)
ig.filter(paths)
Since 4.0.0
, @rabiepenpm/debitis-quos-rem
will no longer support node < 6, to use @rabiepenpm/debitis-quos-rem
in node < 6:
var @rabiepenpm/debitis-quos-rem = require('@rabiepenpm/debitis-quos-rem/legacy')
- All
options
of 2.x are unnecessary and removed, so just remove them. -
@rabiepenpm/debitis-quos-rem()
instance is no longer anEventEmitter
, and all events are unnecessary and removed. -
.addIgnoreFile()
is removed, see the .addIgnoreFile section for details.
- @whitecolor Alex
- @SamyPesse Samy Pessé
- @azproduction Mikhail Davydov
- @TrySound Bogdan Chadkin
- @JanMattner Jan Mattner
- @ntwb Stephen Edgar
- @kasperisager Kasper Isager
- @sandersn Nathan Shively-Sanders