提交学习笔记专用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
4.5 KiB

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