mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-30 18:43:21 +08:00
[@types/mem-fs-editor] Add 'commit' override and 'object' -> 'any'
This commit is contained in:
29
types/mem-fs-editor/index.d.ts
vendored
29
types/mem-fs-editor/index.d.ts
vendored
@@ -17,30 +17,33 @@ export function create(store: Store): memFsEditor.Editor;
|
||||
export namespace memFsEditor {
|
||||
type Contents = string|Buffer;
|
||||
|
||||
type ReplacerFunc = (key: string, value: any) => string|null|undefined;
|
||||
type ReplacerFunc = (key: string, value: any) => any;
|
||||
|
||||
type Space = string|number;
|
||||
|
||||
type ProcessFunc = (contents: Buffer) => Contents;
|
||||
|
||||
type Callback = (err: any) => any;
|
||||
|
||||
interface CopyOptions {
|
||||
process?: ProcessFunc;
|
||||
globOptions?: GlobOptions;
|
||||
}
|
||||
|
||||
interface Editor {
|
||||
read: (filepath: string, options?: { raw: boolean, defaults: string }) => string;
|
||||
readJSON: (filepath: string, defaults?: string) => string;
|
||||
write: (filepath: string, contents: Contents) => void;
|
||||
writeJSON: (filepath: string, contents: object, replacer?: ReplacerFunc, space?: Space) => void;
|
||||
append: (filepath: string, contents: Contents, options?: { trimEnd: boolean, separator: string }) => void;
|
||||
extendJSON: (filepath: string, contents: object, replacer?: ReplacerFunc, space?: Space) => void;
|
||||
delete: (filepath: string, options?: { globOptions: GlobOptions }) => void;
|
||||
copy: (from: string, to: string, options?: CopyOptions) => void;
|
||||
copyTpl: (from: string, to: string, context: object, templateOptions?: TemplateOptions, copyOptions?: CopyOptions) => void;
|
||||
move: (from: string, to: string, options?: { globOptions: GlobOptions }) => void;
|
||||
exists: (filepath: string) => boolean;
|
||||
commit: (filters: ReadonlyArray<Transform>, callback: () => void) => void;
|
||||
read(filepath: string, options?: { raw: boolean, defaults: string }): string;
|
||||
readJSON(filepath: string, defaults?: any): any;
|
||||
write(filepath: string, contents: Contents): void;
|
||||
writeJSON(filepath: string, contents: any, replacer?: ReplacerFunc, space?: Space): void;
|
||||
append(filepath: string, contents: Contents, options?: { trimEnd: boolean, separator: string }): void;
|
||||
extendJSON(filepath: string, contents: object, replacer?: ReplacerFunc, space?: Space): void;
|
||||
delete(filepath: string, options?: { globOptions: GlobOptions }): void;
|
||||
copy(from: string, to: string, options?: CopyOptions): void;
|
||||
copyTpl(from: string, to: string, context: object, templateOptions?: TemplateOptions, copyOptions?: CopyOptions): void;
|
||||
move(from: string, to: string, options?: { globOptions: GlobOptions }): void;
|
||||
exists(filepath: string): boolean;
|
||||
commit(callback: Callback): void;
|
||||
commit(filters: ReadonlyArray<Transform>, callback: Callback): void;
|
||||
}
|
||||
|
||||
const prototype: {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { Transform } from 'stream';
|
||||
|
||||
import memFs = require('mem-fs');
|
||||
import editor = require('mem-fs-editor');
|
||||
|
||||
@@ -16,3 +18,17 @@ fs.copy('template.js', 'template.tpl', {
|
||||
fs.copyTpl('template.tpl', 'output.js', {
|
||||
foo: 'bar'
|
||||
});
|
||||
|
||||
const obj = fs.readJSON('template.json');
|
||||
fs.writeJSON('template.json', obj);
|
||||
fs.extendJSON('template.json', {qwer: 'asdf'});
|
||||
|
||||
fs.writeJSON('template.json', 'qwer'); // should not be an error, because the parameter is passed to JSON.stringify and it accepts the string
|
||||
// fs.extendJSON('template.json', 'qwer'); // should be an error, because it does not make sense to extend a json with string
|
||||
|
||||
// should accept both versions of commit - with filters and without:
|
||||
const cb = (err: any) => ({adsf: 'adsf'});
|
||||
fs.commit(cb);
|
||||
|
||||
const filters: Transform[] = [];
|
||||
fs.commit(filters, cb);
|
||||
|
||||
Reference in New Issue
Block a user