mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-02 19:43:20 +08:00
Add typings for mem-fs-editor (#24886)
* Add mem-fs-editor * Tidy up imports * wip * Typings for mem-fs-editor * Change type to ReadonlyArray<Transform> * Bump minimum TypeScript version based on requirements of EJS * revert * ...
This commit is contained in:
committed by
Mohamed Hegazy
parent
53714e16a5
commit
b46ec025ce
48
types/mem-fs-editor/index.d.ts
vendored
Normal file
48
types/mem-fs-editor/index.d.ts
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
// Type definitions for mem-fs-editor 4.0
|
||||
// Project: https://github.com/SBoudrias/mem-fs-editor#readme
|
||||
// Definitions by: My Food Bag <https://github.com/MyFoodBag>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as Buffer from 'buffer';
|
||||
import { Transform } from 'stream';
|
||||
import { Store } from 'mem-fs';
|
||||
import { Options as TemplateOptions } from 'ejs';
|
||||
import { IOptions as GlobOptions } from 'glob';
|
||||
|
||||
export function create(store: Store): memFsEditor.Editor;
|
||||
|
||||
export namespace memFsEditor {
|
||||
type Contents = string|Buffer;
|
||||
|
||||
type ReplacerFunc = (key: string, value: any) => string|null|undefined;
|
||||
|
||||
type Space = string|number;
|
||||
|
||||
type ProcessFunc = (contents: Buffer) => Contents;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
const prototype: {
|
||||
};
|
||||
}
|
||||
18
types/mem-fs-editor/mem-fs-editor-tests.ts
Normal file
18
types/mem-fs-editor/mem-fs-editor-tests.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import memFs = require('mem-fs');
|
||||
import editor = require('mem-fs-editor');
|
||||
|
||||
const store = memFs.create();
|
||||
const fs = editor.create(store);
|
||||
|
||||
fs.write('template.js', 'var a = 1; console.log(\'<%= foo %>\', a);');
|
||||
|
||||
fs.copy('template.js', 'template.tpl', {
|
||||
process: (contents) => contents,
|
||||
globOptions: {
|
||||
cwd: '.'
|
||||
}
|
||||
});
|
||||
|
||||
fs.copyTpl('template.tpl', 'output.js', {
|
||||
foo: 'bar'
|
||||
});
|
||||
23
types/mem-fs-editor/tsconfig.json
Normal file
23
types/mem-fs-editor/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"mem-fs-editor-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/mem-fs-editor/tslint.json
Normal file
1
types/mem-fs-editor/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user