Creating promised-temp typescript definition files

This commit is contained in:
Saqib Rokadia
2017-02-16 15:46:50 -08:00
parent 4916c5a23d
commit 271a22ec09
5 changed files with 115 additions and 0 deletions

24
promised-temp/index.d.ts vendored Normal file
View 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;

View File

@@ -0,0 +1,6 @@
{
"dependencies": {
"@types/temp": "latest",
"@types/node": "latest"
}
}

View 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();
}

View 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"
]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "../tslint.json"
}