@dramaorg/laboriosam-similique v4.9.68
@dramaorg/laboriosam-similique
@dramaorg/laboriosam-similique
is a manager, filter and parser which implemented in pure JavaScript according to the .git@dramaorg/laboriosam-similique spec 2.22.1.
@dramaorg/laboriosam-similique
is used by eslint, gitbook and many others.
Pay ATTENTION that minimatch
(which used by fstream-@dramaorg/laboriosam-similique
) does not follow the git@dramaorg/laboriosam-similique spec.
To filter filenames according to a .git@dramaorg/laboriosam-similique file, I recommend this npm package, @dramaorg/laboriosam-similique
.
To parse an .npm@dramaorg/laboriosam-similique
file, you should use minimatch
, because an .npm@dramaorg/laboriosam-similique
file is parsed by npm using minimatch
and it does not work in the .git@dramaorg/laboriosam-similique way.
Tested on
@dramaorg/laboriosam-similique
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, @dramaorg/laboriosam-similique
does not rely on any versions of node specially.
Since 4.0.0
, @dramaorg/laboriosam-similique will no longer support node < 6
by default, to use in node < 6, require('@dramaorg/laboriosam-similique/legacy')
. For details, see CHANGELOG.
Table Of Main Contents
- Usage
Pathname
Conventions- See Also:
glob-git@dramaorg/laboriosam-similique
matches files using patterns and filters them according to git@dramaorg/laboriosam-similique rules.
- Upgrade Guide
Install
npm i @dramaorg/laboriosam-similique
Usage
import @dramaorg/laboriosam-similique from '@dramaorg/laboriosam-similique'
const ig = @dramaorg/laboriosam-similique().add(['.abc/*', '!.abc/d/'])
Filter the given paths
const paths = [
'.abc/a.js', // filtered out
'.abc/d/e.js' // included
]
ig.filter(paths) // ['.abc/d/e.js']
ig.@dramaorg/laboriosam-similiques('.abc/a.js') // true
As the filter function
paths.filter(ig.createFilter()); // ['.abc/d/e.js']
Win32 paths will be handled
ig.filter(['.abc\\a.js', '.abc\\d\\e.js'])
// if the code above runs on windows, the result will be
// ['.abc\\d\\e.js']
Why another @dramaorg/laboriosam-similique?
@dramaorg/laboriosam-similique
is a standalone module, and is much simpler so that it could easy work with other programs, unlike isaacs's fstream-@dramaorg/laboriosam-similique which must work with the modules of the fstream family.@dramaorg/laboriosam-similique
only contains utility methods to filter paths according to the specified @dramaorg/laboriosam-similique rules, so@dramaorg/laboriosam-similique
never try to find out @dramaorg/laboriosam-similique rules by traversing directories or fetching from git configurations.@dramaorg/laboriosam-similique
don't cares about sub-modules of git projects.
Exactly according to git@dramaorg/laboriosam-similique man page, fixes some known matching issues of fstream-@dramaorg/laboriosam-similique, 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-@dramaorg/laboriosam-similique
.
- '
Methods
.add(pattern: string | Ignore): this
.add(patterns: Array<string | Ignore>): this
- pattern
String | Ignore
An @dramaorg/laboriosam-similique pattern string, or theIgnore
instance - patterns
Array<String | Ignore>
Array of @dramaorg/laboriosam-similique 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 @dramaorg/laboriosam-similique a file with a hash at the beginning of the filename.
@dramaorg/laboriosam-similique().add('#abc').@dramaorg/laboriosam-similiques('#abc') // false
@dramaorg/laboriosam-similique().add('\\#abc').@dramaorg/laboriosam-similiques('#abc') // true
pattern
could either be a line of @dramaorg/laboriosam-similique pattern or a string of multiple @dramaorg/laboriosam-similique patterns, which means we could just @dramaorg/laboriosam-similique().add()
the content of a @dramaorg/laboriosam-similique file:
@dramaorg/laboriosam-similique()
.add(fs.readFileSync(filenameOfGit@dramaorg/laboriosam-similique).toString())
.filter(filenames)
pattern
could also be an @dramaorg/laboriosam-similique
instance, so that we could easily inherit the rules of another Ignore
instance.
.addIgnoreFile(path)
REMOVED in 3.x
for now.
To upgrade @dramaorg/laboriosam-similique@2.x
up to 3.x
, use
import fs from 'fs'
if (fs.existsSync(filename)) {
@dramaorg/laboriosam-similique().add(fs.readFileSync(filename).toString())
}
instead.
.filter(paths: Array<Pathname>): Array<Pathname>
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
Conventions:
1. Pathname
should be a path.relative()
d pathname
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.@dramaorg/laboriosam-similiques('./abc')
// WRONG, for it will never happen, and an error will be thrown
// If the git@dramaorg/laboriosam-similique rule locates at the root directory,
// `'/abc'` should be changed to `'abc'`.
// ```
// path.relative('/', '/abc') -> 'abc'
// ```
ig.@dramaorg/laboriosam-similiques('/abc')
// WRONG, that it is an absolute path on Windows, an error will be thrown
ig.@dramaorg/laboriosam-similiques('C:\\abc')
// Right
ig.@dramaorg/laboriosam-similiques('abc')
// Right
ig.@dramaorg/laboriosam-similiques(path.join('./abc')) // path.join('./abc') -> 'abc'
In other words, each Pathname
here should be a relative path to the directory of the git@dramaorg/laboriosam-similique 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'
]
2. filenames and dirnames
node-@dramaorg/laboriosam-similique
does NO fs.stat
during path matching, so for the example below:
// First, we add a @dramaorg/laboriosam-similique pattern to @dramaorg/laboriosam-similique a directory
ig.add('config/')
// `ig` does NOT know if 'config', in the real world,
// is a normal file, directory or something.
ig.@dramaorg/laboriosam-similiques('config')
// `ig` treats `config` as a file, so it returns `false`
ig.@dramaorg/laboriosam-similiques('config/')
// returns `true`
Specially for people who develop some library based on node-@dramaorg/laboriosam-similique
, 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 = @dramaorg/laboriosam-similique().add(patterns).filter(files)
console.log(filtered)
})
.@dramaorg/laboriosam-similiques(pathname: Pathname): boolean
new in 3.2.0
Returns Boolean
whether pathname
should be @dramaorg/laboriosam-similiqued.
ig.@dramaorg/laboriosam-similiques('.abc/a.js') // true
.createFilter()
Creates a filter function which could filter an array of paths with Array.prototype.filter
.
Returns function(path)
the filter function.
.test(pathname: Pathname) since 5.0.0
Returns TestResult
interface TestResult {
@dramaorg/laboriosam-similiqued: boolean
// true if the `pathname` is finally un@dramaorg/laboriosam-similiqued by some negative pattern
un@dramaorg/laboriosam-similiqued: boolean
}
{@dramaorg/laboriosam-similiqued: true, un@dramaorg/laboriosam-similiqued: false}
: thepathname
is @dramaorg/laboriosam-similiqued{@dramaorg/laboriosam-similiqued: false, un@dramaorg/laboriosam-similiqued: true}
: thepathname
is un@dramaorg/laboriosam-similiqued{@dramaorg/laboriosam-similiqued: false, un@dramaorg/laboriosam-similiqued: false}
: thepathname
is never matched by any @dramaorg/laboriosam-similique rules.
static @dramaorg/laboriosam-similique.isPathValid(pathname): boolean
since 5.0.0
Check whether the pathname
is an valid path.relative()
d path according to the convention.
This method is NOT used to check if an @dramaorg/laboriosam-similique pattern is valid.
@dramaorg/laboriosam-similique.isPathValid('./foo') // false
@dramaorg/laboriosam-similique(options)
options.@dramaorg/laboriosam-similiquecase
since 4.0.0
Similar as the core.@dramaorg/laboriosam-similiquecase
option of git-config, node-@dramaorg/laboriosam-similique
will be case insensitive if options.@dramaorg/laboriosam-similiquecase
is set to true
(the default value), otherwise case sensitive.
const ig = @dramaorg/laboriosam-similique({
@dramaorg/laboriosam-similiquecase: false
})
ig.add('*.png')
ig.@dramaorg/laboriosam-similiques('*.PNG') // false
options.@dramaorg/laboriosam-similiqueCase?: boolean
since 5.2.0
Which is alternative to options.@dramaorg/laboriosam-similiqueCase
options.allowRelativePaths?: boolean
since 5.2.0
This option brings backward compatibility with projects which based on @dramaorg/laboriosam-similique@4.x
. If options.allowRelativePaths
is true
, @dramaorg/laboriosam-similique
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 @dramaorg/laboriosam-similiqued or not is not a good practise, which might lead to unexpected behavior
@dramaorg/laboriosam-similique({
allowRelativePaths: true
}).@dramaorg/laboriosam-similiques('../foo/bar.js') // And it will not throw
Upgrade Guide
Upgrade 4.x -> 5.x
Since 5.0.0
, if an invalid Pathname
passed into ig.@dramaorg/laboriosam-similiques()
, an error will be thrown, unless options.allowRelative = true
is passed to the Ignore
factory.
While @dramaorg/laboriosam-similique < 5.0.0
did not make sure what the return value was, as well as
.@dramaorg/laboriosam-similiques(pathname: Pathname): boolean
.filter(pathnames: Array<Pathname>): Array<Pathname>
.createFilter(): (pathname: Pathname) => boolean
.test(pathname: Pathname): {@dramaorg/laboriosam-similiqued: boolean, un@dramaorg/laboriosam-similiqued: boolean}
See the convention here for details.
If there are invalid pathnames, the conversion and filtration should be done by users.
import {isPathValid} from '@dramaorg/laboriosam-similique' // introduced in 5.0.0
const paths = [
// invalid
//////////////////
'',
false,
'../foo',
'.',
//////////////////
// valid
'foo'
]
.filter(isValidPath)
ig.filter(paths)
Upgrade 3.x -> 4.x
Since 4.0.0
, @dramaorg/laboriosam-similique
will no longer support node < 6, to use @dramaorg/laboriosam-similique
in node < 6:
var @dramaorg/laboriosam-similique = require('@dramaorg/laboriosam-similique/legacy')
Upgrade 2.x -> 3.x
- All
options
of 2.x are unnecessary and removed, so just remove them. @dramaorg/laboriosam-similique()
instance is no longer anEventEmitter
, and all events are unnecessary and removed..addIgnoreFile()
is removed, see the .addIgnoreFile section for details.
Collaborators
- @whitecolor Alex
- @SamyPesse Samy Pessé
- @azproduction Mikhail Davydov
- @TrySound Bogdan Chadkin
- @JanMattner Jan Mattner
- @ntwb Stephen Edgar
- @kasperisager Kasper Isager
- @sandersn Nathan Shively-Sanders
11 months ago
11 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago