diff --git a/temp/temp-tests.ts b/temp/temp-tests.ts new file mode 100644 index 0000000000..eddf870a4f --- /dev/null +++ b/temp/temp-tests.ts @@ -0,0 +1,67 @@ +// Author: Daniel Rosenwasser + +/// + +import * as temp from "temp"; + +function testCleanup() { + temp.cleanup(result => { + if (typeof result === "boolean") { + const x = result === true; + } + else { + const { files, dirs } = result; + } + }); +} + +function testCleanupSync() { + const cleanupResult = temp.cleanupSync() + if (typeof cleanupResult === "boolean") { + const x = cleanupResult === true; + } + else { + const { dirs, files } = cleanupResult + } +} + +function testOpen() { + temp.open({ dir: "tempDir", prefix: "pref", suffix: "suff" }, (err, result) => { + const { path, fd } = result; + }); + + temp.open("strPrefix", (err, result) => { + const { path, fd } = result; + }); +} + +function testOpenSync() { + const { fd: openFd1, path: openPath1 } = temp.openSync({ dir: "tempDir", prefix: "pref", suffix: "suff" }); + const { fd: openFd2, path: openPath2 } = temp.openSync("str"); +} + +function testCreateWriteStream() { + const stream = temp.createWriteStream("HelloStreamAffix"); + stream.write("data"); +} + +function testMkDir() { + temp.mkDir("prefix", (err, dirPath) => { + dirPath.length; + }); +} + +function testMkDirSync() { + const result = temp.mkDirSync("prefix"); + result.length; +} + +function testPath() { + temp.path({ suffix: "justSuffix" }, "defaultPrefix"); +} + +function testTrack() { + const tempChained = temp.track(true).track(false); + tempChained.dir; + tempChained.cleanupSync(); +} \ No newline at end of file diff --git a/temp/temp.d.ts b/temp/temp.d.ts new file mode 100644 index 0000000000..3d37bf0c5b --- /dev/null +++ b/temp/temp.d.ts @@ -0,0 +1,43 @@ +// Type definitions for temp 0.8.3 +// Project: https://www.npmjs.com/package/temp, https://github.com/bruce/node-temp +// Definitions by: Daniel Rosenwasser +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare module "temp" { + import * as temp from "temp"; + import * as fs from "fs"; + + export interface AffixOptions { + prefix?: string; + suffix?: string; + dir?: string; + } + + export var dir: string; + + export function track(value: boolean): typeof temp; + + export function mkDir(affixes: string, callback?: (err: any, dirPath: string) => void): void; + export function mkDir(affixes: AffixOptions, callback?: (err: any, dirPath: string) => void): void; + + export function mkDirSync(affixes: string): string; + export function mkDirSync(affixes: AffixOptions): string; + + export function open(affixes: string, callback?: (err: any, result: {path: string, fd: number}) => void): void; + export function open(affixes: AffixOptions, callback?: (err: any, result: {path: string, fd: number}) => void): void; + + export function openSync(affixes: string): { path: string, fd: number }; + export function openSync(affixes: AffixOptions): { path: string, fd: number }; + + export function path(affixes: string, defaultPrefix: string): void; + export function path(affixes: AffixOptions, defaultPrefix: string): void; + + export function cleanup(callback?: (result: boolean | {files: number, dirs?: number}) => void): void; + + export function cleanupSync(): boolean | {files: number, dirs: number}; + + export function createWriteStream(affixes: string): fs.WriteStream; + export function createWriteStream(affixes: AffixOptions): fs.WriteStream; +} \ No newline at end of file