index.d.cts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import { FSLike } from "fdir";
  2. //#region src/types.d.ts
  3. type FileSystemAdapter = Partial<FSLike>;
  4. interface GlobOptions {
  5. /**
  6. * Whether to return absolute paths. Disable to have relative paths.
  7. * @default false
  8. */
  9. absolute?: boolean;
  10. /**
  11. * Enables support for brace expansion syntax, like `{a,b}` or `{1..9}`.
  12. * @default true
  13. */
  14. braceExpansion?: boolean;
  15. /**
  16. * Whether to match in case-sensitive mode.
  17. * @default true
  18. */
  19. caseSensitiveMatch?: boolean;
  20. /**
  21. * The working directory in which to search. Results will be returned relative to this directory, unless
  22. * {@link absolute} is set.
  23. *
  24. * It is important to avoid globbing outside this directory when possible, even with absolute paths enabled,
  25. * as doing so can harm performance due to having to recalculate relative paths.
  26. * @default process.cwd()
  27. */
  28. cwd?: string | URL;
  29. /**
  30. * Logs useful debug information. Meant for development purposes. Logs can change at any time.
  31. * @default false
  32. */
  33. debug?: boolean;
  34. /**
  35. * Maximum directory depth to crawl.
  36. * @default Infinity
  37. */
  38. deep?: number;
  39. /**
  40. * Whether to return entries that start with a dot, like `.gitignore` or `.prettierrc`.
  41. * @default false
  42. */
  43. dot?: boolean;
  44. /**
  45. * Whether to automatically expand directory patterns.
  46. *
  47. * Important to disable if migrating from [`fast-glob`](https://github.com/mrmlnc/fast-glob).
  48. * @default true
  49. */
  50. expandDirectories?: boolean;
  51. /**
  52. * Enables support for extglobs, like `+(pattern)`.
  53. * @default true
  54. */
  55. extglob?: boolean;
  56. /**
  57. * Whether to traverse and include symbolic links. Can slightly affect performance.
  58. * @default true
  59. */
  60. followSymbolicLinks?: boolean;
  61. /**
  62. * An object that overrides `node:fs` functions.
  63. * @default import('node:fs')
  64. */
  65. fs?: FileSystemAdapter;
  66. /**
  67. * Enables support for matching nested directories with globstars (`**`).
  68. * If `false`, `**` behaves exactly like `*`.
  69. * @default true
  70. */
  71. globstar?: boolean;
  72. /**
  73. * Glob patterns to exclude from the results.
  74. * @default []
  75. */
  76. ignore?: string | readonly string[];
  77. /**
  78. * Enable to only return directories.
  79. * If `true`, disables {@link onlyFiles}.
  80. * @default false
  81. */
  82. onlyDirectories?: boolean;
  83. /**
  84. * Enable to only return files.
  85. * @default true
  86. */
  87. onlyFiles?: boolean;
  88. /**
  89. * @deprecated Provide patterns as the first argument instead.
  90. */
  91. patterns?: string | readonly string[];
  92. /**
  93. * An `AbortSignal` to abort crawling the file system.
  94. * @default undefined
  95. */
  96. signal?: AbortSignal;
  97. }
  98. //#endregion
  99. //#region src/utils.d.ts
  100. /**
  101. * Converts a path to a pattern depending on the platform.
  102. * Identical to {@link escapePath} on POSIX systems.
  103. * @see {@link https://superchupu.dev/tinyglobby/documentation#convertPathToPattern}
  104. */
  105. declare const convertPathToPattern: (path: string) => string;
  106. /**
  107. * Escapes a path's special characters depending on the platform.
  108. * @see {@link https://superchupu.dev/tinyglobby/documentation#escapePath}
  109. */
  110. declare const escapePath: (path: string) => string;
  111. /**
  112. * Checks if a pattern has dynamic parts.
  113. *
  114. * Has a few minor differences with [`fast-glob`](https://github.com/mrmlnc/fast-glob) for better accuracy:
  115. *
  116. * - Doesn't necessarily return `false` on patterns that include `\`.
  117. * - Returns `true` if the pattern includes parentheses, regardless of them representing one single pattern or not.
  118. * - Returns `true` for unfinished glob extensions i.e. `(h`, `+(h`.
  119. * - Returns `true` for unfinished brace expansions as long as they include `,` or `..`.
  120. *
  121. * @see {@link https://superchupu.dev/tinyglobby/documentation#isDynamicPattern}
  122. */
  123. declare function isDynamicPattern(pattern: string, options?: {
  124. caseSensitiveMatch: boolean;
  125. }): boolean;
  126. //#endregion
  127. //#region src/index.d.ts
  128. /**
  129. * Asynchronously match files following a glob pattern.
  130. * @see {@link https://superchupu.dev/tinyglobby/documentation#glob}
  131. */
  132. declare function glob(patterns: string | readonly string[], options?: Omit<GlobOptions, "patterns">): Promise<string[]>;
  133. /**
  134. * @deprecated Provide patterns as the first argument instead.
  135. */
  136. declare function glob(options: GlobOptions): Promise<string[]>;
  137. /**
  138. * Synchronously match files following a glob pattern.
  139. * @see {@link https://superchupu.dev/tinyglobby/documentation#globSync}
  140. */
  141. declare function globSync(patterns: string | readonly string[], options?: Omit<GlobOptions, "patterns">): string[];
  142. /**
  143. * @deprecated Provide patterns as the first argument instead.
  144. */
  145. declare function globSync(options: GlobOptions): string[];
  146. //#endregion
  147. export { type GlobOptions, convertPathToPattern, escapePath, glob, globSync, isDynamicPattern };