feat: add definition for memory-fs (#12377)

* feat: add definition for memory-fs

* fix: enable strictNullChecks and adjust tests

* feat: add standalone module definitions for memory-fs
This commit is contained in:
Scott(JuJiang)
2016-11-02 23:54:22 +09:00
committed by Masahiro Wakame
parent 00740e74f7
commit 34f6ecfb32
7 changed files with 137 additions and 0 deletions
+83
View File
@@ -0,0 +1,83 @@
// Type definitions for memory-fs 0.3.0
// Project: https://github.com/webpack/memory-fs
// Definitions by: e-cloud <https://github.com/e-cloud>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
declare class MemoryFileSystem {
data: any;
constructor(data?: any);
meta(_path: string): any;
existsSync(_path: string): boolean;
statSync(_path: string): {
isFile: () => boolean;
isDirectory: () => boolean;
isBlockDevice: () => boolean;
isCharacterDevice: () => boolean;
isSymbolicLink: () => boolean;
isFIFO: () => boolean;
isSocket: () => boolean;
};
readFileSync(_path: string, encoding?: string): any;
readdirSync(_path: string): string[];
mkdirpSync(_path: string): void;
mkdirSync(_path: string): void;
_remove(_path: string, name: string, testFn: ((part: string) => boolean)): void;
rmdirSync(_path: string): void;
unlinkSync(_path: string): void;
readlinkSync(_path: string): void;
writeFileSync(_path: string, content: string | Buffer, encoding?: string): void;
createReadStream(
path: string, options: {
start: number;
end: number;
}
): any;
createWriteStream(path: string, options: any): any;
exists(path: string, callback: (isExist: boolean) => any): any;
writeFile(path: string, content: string | Buffer, callback: (err?: Error) => any): any;
writeFile(path: string, content: string | Buffer, encoding: string, callback: (err?: Error) => any): any;
join(path: string, request: string): string;
pathToArray(path: string): string[];
normalize(path: string): string;
stat(path: string, callback: (err?: Error, result?: any) => any): void;
readdir(path: string, callback: (err?: Error, result?: any) => any): void;
mkdirp(path: string, callback: (err?: Error, result?: any) => any): void;
rmdir(path: string, callback: (err?: Error, result?: any) => any): void;
unlink(path: string, callback: (err?: Error, result?: any) => any): void;
readlink(path: string, callback: (err?: Error, result?: any) => any): void;
mkdir(path: string, optArg: {}, callback: (err?: Error, result?: any) => any): void;
readFile(path: string, optArg: {}, callback: (err?: Error, result?: any) => any): void;
}
export = MemoryFileSystem;
+3
View File
@@ -0,0 +1,3 @@
import memoryFsJoin = require('memory-fs/lib/join');
memoryFsJoin('hello', 'world');
+3
View File
@@ -0,0 +1,3 @@
declare function join(path: string, request: string): string;
export = join;
+3
View File
@@ -0,0 +1,3 @@
import normalize = require('memory-fs/lib/normalize');
normalize('hello world');
+3
View File
@@ -0,0 +1,3 @@
declare function normalize(path: string): string;
export = normalize;
+19
View File
@@ -0,0 +1,19 @@
/// <reference path="./index.d.ts" />
import MemoryFileSystem = require('memory-fs');
const fs = new MemoryFileSystem({});
fs.existsSync('./kd/sdkfj');
fs.writeFile('hello', 'hahahahah', function (err) {
if(err){
console.log(err.message);
}
});
fs.writeFile('hello', 'hahahahah', 'utf-8', function (err) {
if(err){
console.log(err.message);
}
});
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"memory-fs-tests.ts",
"lib/join-tests.ts",
"lib/join.d.ts",
"lib/normalize-tests.ts",
"lib/normalize.d.ts"
]
}