Skip to content

Commit 872d495

Browse files
committed
7.0.0: update ts definition and test spec
1 parent bc4e324 commit 872d495

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

index.d.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
type Pathname = string
22

3+
interface IgnoreRule {
4+
pattern: string
5+
mark?: string
6+
negative: boolean
7+
}
8+
39
interface TestResult {
410
ignored: boolean
511
unignored: boolean
12+
rule?: IgnoreRule
13+
}
14+
15+
interface PatternParams {
16+
pattern: string
17+
mark?: string
618
}
719

820
export interface Ignore {
@@ -11,7 +23,9 @@ export interface Ignore {
1123
* @param {string[]} patterns
1224
* @returns IgnoreBase
1325
*/
14-
add(patterns: string | Ignore | readonly (string | Ignore)[]): this
26+
add(
27+
patterns: string | Ignore | readonly (string | Ignore)[] | PatternParams
28+
): this
1529

1630
/**
1731
* Filters the given array of pathnames, and returns the filtered array.
@@ -40,6 +54,13 @@ export interface Ignore {
4054
* @returns TestResult
4155
*/
4256
test(pathname: Pathname): TestResult
57+
58+
/**
59+
* Debugs ignore rules and returns the checking result, which is
60+
* equivalent to `git check-ignore -v`.
61+
* @returns TestResult
62+
*/
63+
checkIgnore(pathname: Pathname): TestResult
4364
}
4465

4566
export interface Options {

test/ts/simple.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,15 @@ ignore({
7070
ignoreCase: false,
7171
allowRelativePaths: true
7272
})
73+
74+
const ig7 = ignore()
75+
76+
ig7.add({pattern: 'foo/*', mark: '10'})
77+
const {
78+
ignored: ignored7,
79+
rule: ignoreRule7
80+
} = ig7.checkIgnore('foo/')
81+
82+
equal(ignored7, true, 'should ignore')
83+
equal(ignoreRule7.mark, '10', 'mark is 10')
84+
equal(ignoreRule7.pattern, 'foo/*', 'ignored by foo/*')

0 commit comments

Comments
 (0)