mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-11 19:09:04 +08:00
Creating promised-temp typescript definition files
This commit is contained in:
24
promised-temp/index.d.ts
vendored
Normal file
24
promised-temp/index.d.ts
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
// Type definitions for promised-temp 0.1
|
||||
// Project: https://www.npmjs.com/package/promised-temp, https://github.com/mikaturunen/promised-temp
|
||||
// Definitions by: Saqib Rokadia <https://github.com/rokadias>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as fs from 'fs';
|
||||
import { AffixOptions, OpenFile, Stats } from "temp";
|
||||
export { AffixOptions, OpenFile, Stats } from "temp";
|
||||
|
||||
interface TempStatic {
|
||||
dir: string;
|
||||
track(value?: boolean): TempStatic;
|
||||
|
||||
path(affixes?: string | AffixOptions, defaultPrefix?: string): string;
|
||||
mkdir(affixes?: string | AffixOptions): Promise<string>;
|
||||
open(affixes?: string | AffixOptions): Promise<OpenFile>;
|
||||
cleanup(): Promise<boolean | Stats>;
|
||||
createWriteStream(affixes?: string | AffixOptions): Promise<fs.WriteStream>;
|
||||
}
|
||||
|
||||
declare var PromisedTemp: TempStatic;
|
||||
export default PromisedTemp;
|
||||
6
promised-temp/package.json
Normal file
6
promised-temp/package.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"@types/temp": "latest",
|
||||
"@types/node": "latest"
|
||||
}
|
||||
}
|
||||
59
promised-temp/promised-temp-tests.ts
Normal file
59
promised-temp/promised-temp-tests.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as fs from "fs";
|
||||
import temp from 'promised-temp';
|
||||
import { AffixOptions, OpenFile, Stats } from "promised-temp";
|
||||
|
||||
function testCleanup() {
|
||||
temp.cleanup().then((result: boolean | Stats) => {
|
||||
if (typeof result === "boolean") {
|
||||
const x = result === true;
|
||||
}
|
||||
else {
|
||||
const { files, dirs } = result;
|
||||
files.toPrecision(4);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function testOpen() {
|
||||
temp.open({ dir: "tempDir", prefix: "pref", suffix: "suff" }).then((result: OpenFile) => {
|
||||
const { path, fd } = result;
|
||||
path.length;
|
||||
fd.toPrecision(5);
|
||||
});
|
||||
|
||||
temp.open("strPrefix").then((result: OpenFile) => {
|
||||
const { path, fd } = result;
|
||||
path.length;
|
||||
fd.toPrecision(5);
|
||||
});
|
||||
}
|
||||
|
||||
function testCreateWriteStream() {
|
||||
const stream =
|
||||
temp.createWriteStream("HelloStreamAffix")
|
||||
.then((stream: fs.WriteStream) => stream.write("data"));
|
||||
|
||||
const stream2 = temp.createWriteStream();
|
||||
}
|
||||
|
||||
function testMkdir() {
|
||||
temp.mkdir("prefix").then((dirPath: string) => {
|
||||
dirPath.length;
|
||||
});
|
||||
}
|
||||
|
||||
function testPath() {
|
||||
const p = temp.path({ suffix: "justSuffix" }, "defaultPrefix");
|
||||
p.length;
|
||||
const p2: string = temp.path("prefix");
|
||||
const p3: string = temp.path({ prefix: "prefix" });
|
||||
}
|
||||
|
||||
function testTrack() {
|
||||
const tempChained = temp.track().track(true).track(false);
|
||||
tempChained.dir;
|
||||
tempChained.cleanup();
|
||||
}
|
||||
23
promised-temp/tsconfig.json
Normal file
23
promised-temp/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"promised-temp-tests.ts"
|
||||
]
|
||||
}
|
||||
3
promised-temp/tslint.json
Normal file
3
promised-temp/tslint.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../tslint.json"
|
||||
}
|
||||
Reference in New Issue
Block a user