UNPKG

1.92 kBTypeScriptView Raw
1// Type definitions for mem-fs-editor 5.1
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, Data as TemplateData } from 'ejs';
13import { IOptions as GlobOptions } from 'glob';
14
15type ReplacerFunc = (key: string, value: any) => any;
16
17type Space = string|number;
18
19type Contents = string|Buffer;
20
21type Callback = (err: any) => any;
22
23export type ProcessingFunc = (contents: Buffer, path: string) => Contents;
24
25export interface CopyOptions {
26 process?: ProcessingFunc;
27 globOptions?: GlobOptions;
28}
29
30export interface Editor {
31 read(filepath: string, options?: { raw?: boolean, defaults: string }): string;
32 readJSON(filepath: string, defaults?: any): any;
33 exists(filepath: string): boolean;
34 write(filepath: string, contents: Contents): string;
35 writeJSON(filepath: string, contents: any, replacer?: ReplacerFunc, space?: Space): string;
36 append(to: string, contents: Contents, options?: { trimEnd?: boolean, separator?: string }): string;
37 delete(paths: string|string[], options?: { globOptions?: GlobOptions }): void;
38 copy(from: string|string[], to: string, options?: CopyOptions, context?: TemplateData, templateOptions?: TemplateOptions): void;
39 copyTpl(from: string|string[], to: string, context?: TemplateData, templateOptions?: TemplateOptions, copyOptions?: CopyOptions): void;
40 move(from: string|string[], to: string, options?: { globOptions: GlobOptions }): void;
41 commit(callback: Callback): void;
42 commit(filters: ReadonlyArray<Transform>, callback: Callback): void;
43}
44
45export function create(store: Store): Editor;
46
47export {};