UNPKG

1.99 kBTypeScriptView Raw
1import Entry, { DefaultEntry, BaseEntry } from './entry';
2declare namespace FSTree {
3 type Operand = 'unlink' | 'rmdir' | 'create' | 'change' | 'mkdir';
4 type Operation = [Operand, string, DefaultEntry] | [Operand, string];
5 type Patch = Operation[];
6 type Entry = import('./entry').DefaultEntry;
7 interface Options {
8 entries?: BaseEntry[];
9 sortAndExpand?: boolean;
10 }
11 interface StaticOptions {
12 sortAndExpand?: boolean;
13 }
14 interface PatchDelegate {
15 unlink?(inputPath: string, outputPath: string, relativePath: string): void;
16 rmdir?(inputPath: string, outputPath: string, relativePath: string): void;
17 mkdir?(inputPath: string, outputPath: string, relativePath: string): void;
18 change?(inputPath: string, outputPath: string, relativePath: string): void;
19 create?(inputPath: string, outputPath: string, relativePath: string): void;
20 }
21}
22declare class FSTree<T extends BaseEntry = DefaultEntry> {
23 entries: T[];
24 constructor(options?: {
25 entries?: T[];
26 sortAndExpand?: boolean;
27 });
28 static fromPaths(paths: string[], options?: FSTree.StaticOptions): FSTree<Entry>;
29 static fromEntries<T extends BaseEntry>(entries: T[], options?: FSTree.StaticOptions): FSTree<T>;
30 readonly size: number;
31 addEntries(entries: T[], options?: FSTree.StaticOptions): void;
32 addPaths(paths: string[], options?: FSTree.StaticOptions): void;
33 forEach(fn: (entry: T, index: number, collection: T[]) => void, context: any): void;
34 calculatePatch<K extends BaseEntry>(theirFSTree: FSTree<K>, isEqual?: (a: T, b: K) => boolean): FSTree.Patch;
35 calculateAndApplyPatch(otherFSTree: FSTree<T>, input: string, output: string, delegate?: FSTree.PatchDelegate): void;
36 static defaultIsEqual(entryA: DefaultEntry, entryB: DefaultEntry): boolean;
37 static applyPatch(input: string, output: string, patch: FSTree.Patch, _delegate?: FSTree.PatchDelegate): void;
38}
39export = FSTree;