Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
index.d.cts155 linesDownload Raw Back to dist
1/// <reference types="node" />
2import * as nativeFs from "fs";
3import picomatch from "picomatch";
4
5//#region src/api/aborter.d.ts
6/**
7 * AbortController is not supported on Node 14 so we use this until we can drop
8 * support for Node 14.
9 */
10declare class Aborter {
11  aborted: boolean;
12  abort(): void;
13}
14//#endregion
15//#region src/api/queue.d.ts
16type OnQueueEmptyCallback = (error: Error | null, output: WalkerState) => void;
17/**
18 * This is a custom stateless queue to track concurrent async fs calls.
19 * It increments a counter whenever a call is queued and decrements it
20 * as soon as it completes. When the counter hits 0, it calls onQueueEmpty.
21 */
22declare class Queue {
23  private onQueueEmpty?;
24  count: number;
25  constructor(onQueueEmpty?: OnQueueEmptyCallback | undefined);
26  enqueue(): number;
27  dequeue(error: Error | null, output: WalkerState): void;
28}
29//#endregion
30//#region src/types.d.ts
31type Counts = {
32  files: number;
33  directories: number;
34  /**
35   * @deprecated use `directories` instead. Will be removed in v7.0.
36   */
37  dirs: number;
38};
39type Group = {
40  directory: string;
41  files: string[];
42  /**
43   * @deprecated use `directory` instead. Will be removed in v7.0.
44   */
45  dir: string;
46};
47type GroupOutput = Group[];
48type OnlyCountsOutput = Counts;
49type PathsOutput = string[];
50type Output = OnlyCountsOutput | PathsOutput | GroupOutput;
51type FSLike = {
52  readdir: typeof nativeFs.readdir;
53  readdirSync: typeof nativeFs.readdirSync;
54  realpath: typeof nativeFs.realpath;
55  realpathSync: typeof nativeFs.realpathSync;
56  stat: typeof nativeFs.stat;
57  statSync: typeof nativeFs.statSync;
58};
59type WalkerState = {
60  root: string;
61  paths: string[];
62  groups: Group[];
63  counts: Counts;
64  options: Options;
65  queue: Queue;
66  controller: Aborter;
67  fs: FSLike;
68  symlinks: Map<string, string>;
69  visited: string[];
70};
71type ResultCallback<TOutput extends Output> = (error: Error | null, output: TOutput) => void;
72type FilterPredicate = (path: string, isDirectory: boolean) => boolean;
73type ExcludePredicate = (dirName: string, dirPath: string) => boolean;
74type PathSeparator = "/" | "\\";
75type Options<TGlobFunction = unknown> = {
76  includeBasePath?: boolean;
77  includeDirs?: boolean;
78  normalizePath?: boolean;
79  maxDepth: number;
80  maxFiles?: number;
81  resolvePaths?: boolean;
82  suppressErrors: boolean;
83  group?: boolean;
84  onlyCounts?: boolean;
85  filters: FilterPredicate[];
86  resolveSymlinks?: boolean;
87  useRealPaths?: boolean;
88  excludeFiles?: boolean;
89  excludeSymlinks?: boolean;
90  exclude?: ExcludePredicate;
91  relativePaths?: boolean;
92  pathSeparator: PathSeparator;
93  signal?: AbortSignal;
94  globFunction?: TGlobFunction;
95  fs?: FSLike;
96};
97type GlobMatcher = (test: string) => boolean;
98type GlobFunction = (glob: string | string[], ...params: unknown[]) => GlobMatcher;
99type GlobParams<T> = T extends ((globs: string | string[], ...params: infer TParams extends unknown[]) => GlobMatcher) ? TParams : [];
100//#endregion
101//#region src/builder/api-builder.d.ts
102declare class APIBuilder<TReturnType extends Output> {
103  private readonly root;
104  private readonly options;
105  constructor(root: string, options: Options);
106  withPromise(): Promise<TReturnType>;
107  withCallback(cb: ResultCallback<TReturnType>): void;
108  sync(): TReturnType;
109}
110//#endregion
111//#region src/builder/index.d.ts
112declare class Builder<TReturnType extends Output = PathsOutput, TGlobFunction = typeof picomatch> {
113  private readonly globCache;
114  private options;
115  private globFunction?;
116  constructor(options?: Partial<Options<TGlobFunction>>);
117  group(): Builder<GroupOutput, TGlobFunction>;
118  withPathSeparator(separator: "/" | "\\"): this;
119  withBasePath(): this;
120  withRelativePaths(): this;
121  withDirs(): this;
122  withMaxDepth(depth: number): this;
123  withMaxFiles(limit: number): this;
124  withFullPaths(): this;
125  withErrors(): this;
126  withSymlinks({
127    resolvePaths
128  }?: {
129    resolvePaths?: boolean | undefined;
130  }): this;
131  withAbortSignal(signal: AbortSignal): this;
132  normalize(): this;
133  filter(predicate: FilterPredicate): this;
134  onlyDirs(): this;
135  exclude(predicate: ExcludePredicate): this;
136  onlyCounts(): Builder<OnlyCountsOutput, TGlobFunction>;
137  crawl(root?: string): APIBuilder<TReturnType>;
138  withGlobFunction<TFunc>(fn: TFunc): Builder<TReturnType, TFunc>;
139  /**
140   * @deprecated Pass options using the constructor instead:
141   * ```ts
142   * new fdir(options).crawl("/path/to/root");
143   * ```
144   * This method will be removed in v7.0
145   */
146  crawlWithOptions(root: string, options: Partial<Options<TGlobFunction>>): APIBuilder<TReturnType>;
147  glob(...patterns: string[]): Builder<TReturnType, TGlobFunction>;
148  globWithOptions(patterns: string[]): Builder<TReturnType, TGlobFunction>;
149  globWithOptions(patterns: string[], ...options: GlobParams<TGlobFunction>): Builder<TReturnType, TGlobFunction>;
150}
151//#endregion
152//#region src/index.d.ts
153type Fdir = typeof Builder;
154//#endregion
155export { Counts, ExcludePredicate, FSLike, Fdir, FilterPredicate, GlobFunction, GlobMatcher, GlobParams, Group, GroupOutput, OnlyCountsOutput, Options, Output, PathSeparator, PathsOutput, ResultCallback, WalkerState, Builder as fdir };
codekingpro/portable-devtools · Team Ai