[@types/mem-fs-editor] Add 'commit' override and 'object' -> 'any'

This commit is contained in:
Dmitry Mazurok
2018-05-22 20:45:49 +07:00
parent 88fc0023e6
commit f4f78cffa3
2 changed files with 32 additions and 13 deletions

View File

@@ -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: {

View File

@@ -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);