mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-19 13:32:17 +08:00
67
temp/temp-tests.ts
Normal file
67
temp/temp-tests.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
// Author: Daniel Rosenwasser <https://github.com/DanielRosenwasser>
|
||||
|
||||
/// <reference path="temp.d.ts" />
|
||||
|
||||
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();
|
||||
}
|
||||
43
temp/temp.d.ts
vendored
Normal file
43
temp/temp.d.ts
vendored
Normal file
@@ -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 <https://github.com/DanielRosenwasser>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user