index.d.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. type Pathname = string
  2. interface IgnoreRule {
  3. pattern: string
  4. mark?: string
  5. negative: boolean
  6. }
  7. interface TestResult {
  8. ignored: boolean
  9. unignored: boolean
  10. rule?: IgnoreRule
  11. }
  12. interface PatternParams {
  13. pattern: string
  14. mark?: string
  15. }
  16. /**
  17. * Creates new ignore manager.
  18. */
  19. declare function ignore(options?: ignore.Options): ignore.Ignore
  20. declare namespace ignore {
  21. interface Ignore {
  22. /**
  23. * Adds one or several rules to the current manager.
  24. * @param {string[]} patterns
  25. * @returns IgnoreBase
  26. */
  27. add(
  28. patterns: string | Ignore | readonly (string | Ignore)[] | PatternParams
  29. ): this
  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. * Creates a filter function which could filter
  39. * an array of paths with Array.prototype.filter.
  40. */
  41. createFilter(): (pathname: Pathname) => boolean
  42. /**
  43. * Returns Boolean whether pathname should be ignored.
  44. * @param {string} pathname a path to check
  45. * @returns boolean
  46. */
  47. ignores(pathname: Pathname): boolean
  48. /**
  49. * Returns whether pathname should be ignored or unignored
  50. * @param {string} pathname a path to check
  51. * @returns TestResult
  52. */
  53. test(pathname: Pathname): TestResult
  54. /**
  55. * Debugs ignore rules and returns the checking result, which is
  56. * equivalent to `git check-ignore -v`.
  57. * @returns TestResult
  58. */
  59. checkIgnore(pathname: Pathname): TestResult
  60. }
  61. interface Options {
  62. ignorecase?: boolean
  63. // For compatibility
  64. ignoreCase?: boolean
  65. allowRelativePaths?: boolean
  66. }
  67. function isPathValid(pathname: string): boolean
  68. }
  69. export = ignore