mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Add fs-promise declarations (#13223)
This commit is contained in:
parent
43b47cd512
commit
9d6ee729f8
51
fs-promise/fs-promise-tests.ts
Normal file
51
fs-promise/fs-promise-tests.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import * as fs from "fs-promise";
|
||||
|
||||
var src: string;
|
||||
var dst: string;
|
||||
var dir: string;
|
||||
var path: string;
|
||||
var data: any;
|
||||
var writeOptions: fs.WriteOptions;
|
||||
var writeJsonOptions: fs.WriteJsonOptions;
|
||||
var readJsonOptions: fs.ReadJsonOptions;
|
||||
|
||||
async function test() {
|
||||
await fs.copy(src, dst);
|
||||
await fs.emptyDir(dir);
|
||||
await fs.emptydir(dir);
|
||||
await fs.ensureFile(path);
|
||||
await fs.createFile(path);
|
||||
await fs.ensureDir(dir);
|
||||
await fs.ensureLink(src, dst);
|
||||
await fs.createLink(src, dst);
|
||||
await fs.ensureSymlink(src, dst);
|
||||
await fs.ensureSymlink(src, dst, "dir");
|
||||
await fs.ensureSymlink(src, dst, "file");
|
||||
await fs.ensureSymlink(src, dst, "junction");
|
||||
await fs.createSymlink(src, dst, "dir");
|
||||
await fs.mkdirs(dir);
|
||||
await fs.mkdirp(dir);
|
||||
await fs.move(src, dst);
|
||||
await fs.outputFile(path, "test");
|
||||
await fs.outputFile(path, "test", writeOptions);
|
||||
await fs.outputFile(path, new Buffer([1,2]));
|
||||
await fs.outputFile(path, new Buffer([1,2]), writeOptions);
|
||||
await fs.outputJson(path, data);
|
||||
await fs.outputJson(path, data, writeJsonOptions);
|
||||
await fs.outputJSON(path, data, writeJsonOptions);
|
||||
let json = await fs.readJson(path);
|
||||
json = await fs.readJson(path, readJsonOptions);
|
||||
json = await fs.readJSON(path, readJsonOptions);
|
||||
await fs.remove(path);
|
||||
let dirs: string[] = await fs.walk(dir);
|
||||
await fs.writeJson(path, data);
|
||||
await fs.writeJson(path, data, writeJsonOptions);
|
||||
await fs.writeJSON(path, data, writeJsonOptions);
|
||||
return dirs;
|
||||
}
|
||||
|
||||
test().then((dirs: string[]) => {
|
||||
console.log(dirs);
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
58
fs-promise/index.d.ts
vendored
Normal file
58
fs-promise/index.d.ts
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
// Type definitions for fs-promise 1.0
|
||||
// Project: https://github.com/kevinbeaty/fs-promise#readme
|
||||
// Definitions by: Thiago de Arruda <https://github.com/tarruda>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
export * from "mz/fs";
|
||||
|
||||
export interface WriteOptions {
|
||||
encoding?: string;
|
||||
mode?: number;
|
||||
flag?: string;
|
||||
}
|
||||
|
||||
type JsonReplacerArray = Array<number | string>;
|
||||
|
||||
type JsonReplacerFunction = (key: any, value: any) => any;
|
||||
|
||||
type JsonReplacer = JsonReplacerArray | JsonReplacerFunction;
|
||||
|
||||
export interface WriteJsonOptions extends WriteOptions {
|
||||
spaces?: number;
|
||||
replacer?: JsonReplacer;
|
||||
}
|
||||
|
||||
export interface ReadJsonOptions {
|
||||
encoding: string;
|
||||
flag?: string;
|
||||
reviver: (key: any, value: any) => any;
|
||||
}
|
||||
|
||||
export function copy(src: string, dst: string): Promise<void>;
|
||||
export function emptyDir(dir: string): Promise<void>;
|
||||
export function ensureFile(file: string): Promise<void>;
|
||||
export function ensureDir(dir: string): Promise<void>;
|
||||
export function ensureLink(srcpath: string, dstpath: string): Promise<void>;
|
||||
export function ensureSymlink(srcpath: string, dstpath: string, type?: "dir" | "file" | "junction"): Promise<void>;
|
||||
export function mkdirs(dir: string): Promise<void>;
|
||||
export function move(src: string, dst: string): Promise<void>;
|
||||
export function outputFile(file: string, data: string | Buffer, options?: WriteOptions): Promise<void>;
|
||||
export function outputJson(file: string, data: any, options?: WriteJsonOptions): Promise<void>;
|
||||
export function readJson(file: string, options?: ReadJsonOptions): Promise<any>;
|
||||
export function remove(path: string): Promise<void>;
|
||||
export function walk(dir: string): Promise<string[]>;
|
||||
export function writeJson(file: string, data: any, options?: WriteJsonOptions): Promise<void>;
|
||||
|
||||
// aliases
|
||||
export {
|
||||
emptyDir as emptydir,
|
||||
ensureFile as createFile,
|
||||
ensureLink as createLink,
|
||||
ensureSymlink as createSymlink,
|
||||
mkdirs as mkdirp,
|
||||
outputJson as outputJSON,
|
||||
readJson as readJSON,
|
||||
writeJson as writeJSON
|
||||
};
|
||||
19
fs-promise/tsconfig.json
Normal file
19
fs-promise/tsconfig.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"fs-promise-tests.ts"
|
||||
]
|
||||
}
|
||||
1
fs-promise/tslint.json
Normal file
1
fs-promise/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Loading…
Reference in New Issue
Block a user