UNPKG

1.88 kBTypeScriptView Raw
1type Pathname = string
2
3interface IgnoreRule {
4 pattern: string
5 mark?: string
6 negative: boolean
7}
8
9interface TestResult {
10 ignored: boolean
11 unignored: boolean
12 rule?: IgnoreRule
13}
14
15interface PatternParams {
16 pattern: string
17 mark?: string
18}
19
20export interface Ignore {
21 /**
22 * Adds one or several rules to the current manager.
23 * @param {string[]} patterns
24 * @returns IgnoreBase
25 */
26 add(
27 patterns: string | Ignore | readonly (string | Ignore)[] | PatternParams
28 ): this
29
30 /**
31 * Filters the given array of pathnames, and returns the filtered array.
32 * NOTICE that each path here should be a relative path to the root of your repository.
33 * @param paths the array of paths to be filtered.
34 * @returns The filtered array of paths
35 */
36 filter(pathnames: readonly Pathname[]): Pathname[]
37
38 /**
39 * Creates a filter function which could filter
40 * an array of paths with Array.prototype.filter.
41 */
42 createFilter(): (pathname: Pathname) => boolean
43
44 /**
45 * Returns Boolean whether pathname should be ignored.
46 * @param {string} pathname a path to check
47 * @returns boolean
48 */
49 ignores(pathname: Pathname): boolean
50
51 /**
52 * Returns whether pathname should be ignored or unignored
53 * @param {string} pathname a path to check
54 * @returns TestResult
55 */
56 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
64}
65
66export interface Options {
67 ignorecase?: boolean
68 // For compatibility
69 ignoreCase?: boolean
70 allowRelativePaths?: boolean
71}
72
73/**
74 * Creates new ignore manager.
75 */
76declare function ignore(options?: Options): Ignore
77declare function isPathValid (pathname: string): boolean
78
79export default ignore
80export {
81 isPathValid
82}
83
\No newline at end of file