From 336361b4e23da3f5e8b2181f9fc715213685d159 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 16 Dec 2015 18:09:23 -0800 Subject: [PATCH 1/2] Added 'temp'. --- temp/temp-tests.ts | 67 ++++++++++++++++++++++++++++++++++++++++++++++ temp/temp.d.ts | 43 +++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 temp/temp-tests.ts create mode 100644 temp/temp.d.ts 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..ea8f33d9d1 --- /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); + export function mkDir(affixes: AffixOptions, callback?: (err: any, dirPath: string) => 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); + export function open(affixes: AffixOptions, callback?: (err: any, result: {path: string, fd: number}) => 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); + export function path(affixes: AffixOptions, defaultPrefix: string); + + export function cleanup(callback?: (result: boolean | {files: number, dirs?: number}) => 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 From 8c0469357cd869d2766948d84a34561c5b8bd5c5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 16 Dec 2015 23:42:23 -0800 Subject: [PATCH 2/2] Made non-synchronous functions return 'void'. --- temp/temp.d.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/temp/temp.d.ts b/temp/temp.d.ts index ea8f33d9d1..3d37bf0c5b 100644 --- a/temp/temp.d.ts +++ b/temp/temp.d.ts @@ -19,22 +19,22 @@ declare module "temp" { export function track(value: boolean): typeof temp; - export function mkDir(affixes: string, callback?: (err: any, dirPath: string) => void); - export function mkDir(affixes: AffixOptions, callback?: (err: any, dirPath: string) => void); + 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); - export function open(affixes: AffixOptions, callback?: (err: any, result: {path: string, fd: number}) => void); + 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); - export function path(affixes: AffixOptions, defaultPrefix: string); + 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); + export function cleanup(callback?: (result: boolean | {files: number, dirs?: number}) => void): void; export function cleanupSync(): boolean | {files: number, dirs: number};