Skip to content

Commit

Permalink
7.0.0: update ts definition and test spec
Browse files Browse the repository at this point in the history
  • Loading branch information
kaelzhang committed Dec 23, 2024
1 parent bc4e324 commit 872d495
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
23 changes: 22 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
type Pathname = string

interface IgnoreRule {
pattern: string
mark?: string
negative: boolean
}

interface TestResult {
ignored: boolean
unignored: boolean
rule?: IgnoreRule
}

interface PatternParams {
pattern: string
mark?: string
}

export interface Ignore {
Expand All @@ -11,7 +23,9 @@ export interface Ignore {
* @param {string[]} patterns
* @returns IgnoreBase
*/
add(patterns: string | Ignore | readonly (string | Ignore)[]): this
add(
patterns: string | Ignore | readonly (string | Ignore)[] | PatternParams
): this

/**
* Filters the given array of pathnames, and returns the filtered array.
Expand Down Expand Up @@ -40,6 +54,13 @@ export interface Ignore {
* @returns TestResult
*/
test(pathname: Pathname): TestResult

/**
* Debugs ignore rules and returns the checking result, which is
* equivalent to `git check-ignore -v`.
* @returns TestResult
*/
checkIgnore(pathname: Pathname): TestResult
}

export interface Options {
Expand Down
12 changes: 12 additions & 0 deletions test/ts/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,15 @@ ignore({
ignoreCase: false,
allowRelativePaths: true
})

const ig7 = ignore()

ig7.add({pattern: 'foo/*', mark: '10'})
const {
ignored: ignored7,
rule: ignoreRule7
} = ig7.checkIgnore('foo/')

equal(ignored7, true, 'should ignore')
equal(ignoreRule7.mark, '10', 'mark is 10')
equal(ignoreRule7.pattern, 'foo/*', 'ignored by foo/*')

0 comments on commit 872d495

Please sign in to comment.