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