|
1 |
| -<table><thead> |
2 |
| - <tr> |
3 |
| - <th>Linux</th> |
4 |
| - <th>OS X</th> |
5 |
| - <th>Windows</th> |
6 |
| - <th>Coverage</th> |
7 |
| - <th>Downloads</th> |
8 |
| - </tr> |
9 |
| -</thead><tbody><tr> |
10 |
| - <td colspan="2" align="center"> |
11 |
| - <a href="https://github.com/kaelzhang/node-ignore/actions/workflows/nodejs.yml"> |
12 |
| - <img |
13 |
| - src="https://github.com/kaelzhang/node-ignore/actions/workflows/nodejs.yml/badge.svg" |
14 |
| - alt="Build Status" /></a> |
15 |
| - </td> |
16 |
| - <td align="center"> |
17 |
| - <a href="https://ci.appveyor.com/project/kaelzhang/node-ignore"> |
18 |
| - <img |
19 |
| - src="https://ci.appveyor.com/api/projects/status/github/kaelzhang/node-ignore?branch=master&svg=true" |
20 |
| - alt="Windows Build Status" /></a> |
21 |
| - </td> |
22 |
| - <td align="center"> |
23 |
| - <a href="https://codecov.io/gh/kaelzhang/node-ignore"> |
24 |
| - <img |
25 |
| - src="https://codecov.io/gh/kaelzhang/node-ignore/branch/master/graph/badge.svg" |
26 |
| - alt="Coverage Status" /></a> |
27 |
| - </td> |
28 |
| - <td align="center"> |
29 |
| - <a href="https://www.npmjs.org/package/ignore"> |
30 |
| - <img |
31 |
| - src="http://img.shields.io/npm/dm/ignore.svg" |
32 |
| - alt="npm module downloads per month" /></a> |
33 |
| - </td> |
34 |
| -</tr></tbody></table> |
| 1 | +| Linux / MacOS / Windows | Coverage | Downloads | |
| 2 | +| ----------------------- | -------- | --------- | |
| 3 | +| [![build][bb]][bl] | [![coverage][cb]][cl] | [![downloads][db]][dl] | |
| 4 | + |
| 5 | +[bb]: https://github.com/kaelzhang/node-ignore/actions/workflows/nodejs.yml/badge.svg |
| 6 | +[bl]: https://github.com/kaelzhang/node-ignore/actions/workflows/nodejs.yml |
| 7 | + |
| 8 | +[cb]: https://codecov.io/gh/kaelzhang/node-ignore/branch/master/graph/badge.svg |
| 9 | +[cl]: https://codecov.io/gh/kaelzhang/node-ignore |
| 10 | + |
| 11 | +[db]: http://img.shields.io/npm/dm/ignore.svg |
| 12 | +[dl]: https://www.npmjs.org/package/ignore |
35 | 13 |
|
36 | 14 | # ignore
|
37 | 15 |
|
@@ -124,9 +102,11 @@ ig.filter(['.abc\\a.js', '.abc\\d\\e.js'])
|
124 | 102 |
|
125 | 103 | ## .add(pattern: string | Ignore): this
|
126 | 104 | ## .add(patterns: Array<string | Ignore>): this
|
| 105 | +## .add({pattern: string, mark?: string}): this since 7.0.0 |
127 | 106 |
|
128 |
| -- **pattern** `String | Ignore` An ignore pattern string, or the `Ignore` instance |
129 |
| -- **patterns** `Array<String | Ignore>` Array of ignore patterns. |
| 107 | +- **pattern** `string | Ignore` An ignore pattern string, or the `Ignore` instance |
| 108 | +- **patterns** `Array<string | Ignore>` Array of ignore patterns. |
| 109 | +- **mark?** `string` Pattern mark, which is used to associate the pattern with a certain marker, such as the line no of the `.gitignore` file. Actually it could be an arbitrary string and is optional. |
130 | 110 |
|
131 | 111 | Adds a rule or several rules to the current manager.
|
132 | 112 |
|
@@ -218,7 +198,11 @@ Then the `paths` might be like this:
|
218 | 198 |
|
219 | 199 | #### 2. filenames and dirnames
|
220 | 200 |
|
221 |
| -`node-ignore` does NO `fs.stat` during path matching, so for the example below: |
| 201 | +`node-ignore` does NO `fs.stat` during path matching, so `node-ignore` treats |
| 202 | +- `foo` as a file |
| 203 | +- **`foo/` as a directory** |
| 204 | + |
| 205 | +For the example below: |
222 | 206 |
|
223 | 207 | ```js
|
224 | 208 | // First, we add a ignore pattern to ignore a directory
|
@@ -271,25 +255,64 @@ Creates a filter function which could filter an array of paths with `Array.proto
|
271 | 255 |
|
272 | 256 | Returns `function(path)` the filter function.
|
273 | 257 |
|
274 |
| -## .test(pathname: Pathname) since 5.0.0 |
| 258 | +## .test(pathname: Pathname): TestResult |
| 259 | +
|
| 260 | +> New in 5.0.0 |
275 | 261 |
|
276 | 262 | Returns `TestResult`
|
277 | 263 |
|
278 | 264 | ```ts
|
| 265 | +// Since 5.0.0 |
279 | 266 | interface TestResult {
|
280 | 267 | ignored: boolean
|
281 | 268 | // true if the `pathname` is finally unignored by some negative pattern
|
282 | 269 | unignored: boolean
|
| 270 | + // The `IgnoreRule` which ignores the pathname |
| 271 | + rule?: IgnoreRule |
| 272 | +} |
| 273 | + |
| 274 | +// Since 7.0.0 |
| 275 | +interface IgnoreRule { |
| 276 | + // The original pattern |
| 277 | + pattern: string |
| 278 | + // Whether the pattern is a negative pattern |
| 279 | + negative: boolean |
| 280 | + // Which is used for other packages to build things upon `node-ignore` |
| 281 | + mark?: string |
283 | 282 | }
|
284 | 283 | ```
|
285 | 284 |
|
286 | 285 | - `{ignored: true, unignored: false}`: the `pathname` is ignored
|
287 | 286 | - `{ignored: false, unignored: true}`: the `pathname` is unignored
|
288 | 287 | - `{ignored: false, unignored: false}`: the `pathname` is never matched by any ignore rules.
|
289 | 288 |
|
290 |
| -## .checkIgnore(pattern) since 6.1.0 |
| 289 | +## .checkIgnore(target: string): TestResult |
| 290 | + |
| 291 | +> new in 7.0.0 |
| 292 | +
|
| 293 | +Debugs gitignore / exclude files, which is equivalent to `git check-ignore -v`. Usually this method is used for other packages to implement the function of `git check-ignore -v` upon `node-ignore` |
| 294 | + |
| 295 | +- **target** `string` the target to test. |
291 | 296 |
|
292 |
| -> new in 6.1.0 |
| 297 | +Returns `TestResult` |
| 298 | + |
| 299 | +```js |
| 300 | +ig.add({ |
| 301 | + pattern: 'foo/*', |
| 302 | + mark: '60' |
| 303 | +}) |
| 304 | + |
| 305 | +const { |
| 306 | + ignored, |
| 307 | + rule |
| 308 | +} = checkIgnore('foo/') |
| 309 | + |
| 310 | +if (ignored) { |
| 311 | + console.log(`.gitignore:${result}:${rule.mark}:${rule.pattern} foo/`) |
| 312 | +} |
| 313 | + |
| 314 | +// .gitignore:60:foo/* foo/ |
| 315 | +``` |
293 | 316 |
|
294 | 317 | Please pay attention that this method does not have a strong built-in cache mechanism.
|
295 | 318 |
|
|
0 commit comments