UNPKG

2.01 kBTypeScriptView Raw
1// Type definitions for mem-fs-editor 4.0
2// Project: https://github.com/SBoudrias/mem-fs-editor#readme
3// Definitions by: My Food Bag <https://github.com/MyFoodBag>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5// TypeScript Version: 2.4
6
7/// <reference types="node" />
8
9import * as Buffer from 'buffer';
10import { Transform } from 'stream';
11import { Store } from 'mem-fs';
12import { Options as TemplateOptions } from 'ejs';
13import { IOptions as GlobOptions } from 'glob';
14
15export function create(store: Store): memFsEditor.Editor;
16
17export namespace memFsEditor {
18 type Contents = string|Buffer;
19
20 type ReplacerFunc = (key: string, value: any) => any;
21
22 type Space = string|number;
23
24 type ProcessFunc = (contents: Buffer) => Contents;
25
26 type Callback = (err: any) => any;
27
28 interface CopyOptions {
29 process?: ProcessFunc;
30 globOptions?: GlobOptions;
31 }
32
33 interface Editor {
34 read(filepath: string, options?: { raw: boolean, defaults: string }): string;
35 readJSON(filepath: string, defaults?: any): any;
36 write(filepath: string, contents: Contents): void;
37 writeJSON(filepath: string, contents: any, replacer?: ReplacerFunc, space?: Space): void;
38 append(filepath: string, contents: Contents, options?: { trimEnd: boolean, separator: string }): void;
39 extendJSON(filepath: string, contents: object, replacer?: ReplacerFunc, space?: Space): void;
40 delete(filepath: string, options?: { globOptions: GlobOptions }): void;
41 copy(from: string, to: string, options?: CopyOptions): void;
42 copyTpl(from: string, to: string, context: object, templateOptions?: TemplateOptions, copyOptions?: CopyOptions): void;
43 move(from: string, to: string, options?: { globOptions: GlobOptions }): void;
44 exists(filepath: string): boolean;
45 commit(callback: Callback): void;
46 commit(filters: ReadonlyArray<Transform>, callback: Callback): void;
47 }
48
49 const prototype: {
50 };
51}