Comparing version 0.1.0 to 0.2.0
@@ -1,3 +0,1 @@ | ||
export declare const tmpfile: () => Promise<Tmp>; | ||
export declare const tmpdir: () => Promise<Tmp>; | ||
export type Tmp = { | ||
@@ -7,2 +5,7 @@ path: string; | ||
}; | ||
export declare const tmpdir: () => Promise<Tmp>; | ||
export interface TmpFileOptions { | ||
fd: boolean; | ||
} | ||
export declare const tmpfile: (options?: TmpFileOptions) => Promise<Tmp>; | ||
export declare const config: { | ||
@@ -14,1 +17,2 @@ randomName: typeof randomName; | ||
export declare function randomName(length: number): string; | ||
export declare function close(fd: number): Promise<void>; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -39,10 +50,27 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.randomName = exports.config = exports.tmpdir = exports.tmpfile = void 0; | ||
exports.close = exports.randomName = exports.config = exports.tmpfile = exports.tmpdir = void 0; | ||
var fs = require("fs"); | ||
var os = require("os"); | ||
var path_1 = require("path"); | ||
var tmpfile = function () { return _tmp(_file); }; | ||
exports.tmpfile = tmpfile; | ||
var tmpdir = function () { return _tmp(_dir); }; | ||
exports.tmpdir = tmpdir; | ||
var tmpfile = function (options) { return __awaiter(void 0, void 0, void 0, function () { | ||
var tmp; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
options = __assign({ fd: true }, options); | ||
return [4 /*yield*/, _tmp(_file)]; | ||
case 1: | ||
tmp = _a.sent(); | ||
if (!!options.fd) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, close(tmp.fd)]; | ||
case 2: | ||
_a.sent(); | ||
_a.label = 3; | ||
case 3: return [2 /*return*/, tmp]; | ||
} | ||
}); | ||
}); }; | ||
exports.tmpfile = tmpfile; | ||
function _file(path) { | ||
@@ -116,1 +144,14 @@ var _a = fs.constants, O_CREAT = _a.O_CREAT, O_EXCL = _a.O_EXCL, O_RDWR = _a.O_RDWR; | ||
exports.randomName = randomName; | ||
function close(fd) { | ||
return new Promise(function (resolve, reject) { | ||
fs.close(fd, function (err) { | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} | ||
exports.close = close; |
@@ -68,5 +68,10 @@ "use strict"; | ||
var path = (0, path_1.join)(os.tmpdir(), name); | ||
if (fs.lstatSync(path).isFile()) { | ||
fs.unlinkSync(path); | ||
try { | ||
if (fs.lstatSync(path).isFile()) { | ||
fs.unlinkSync(path); | ||
} | ||
} | ||
catch (err) { | ||
// ENOENT | ||
} | ||
}); | ||
@@ -73,0 +78,0 @@ return [4 /*yield*/, Promise.all([(0, tmp_1.tmpfile)(), (0, tmp_1.tmpfile)(), (0, tmp_1.tmpfile)()])]; |
{ | ||
"name": "amisc", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Random helpers", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -5,2 +5,2 @@ Random utility stuff. | ||
`$ npm install mytmp` | ||
`$ npm install amisc` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
15408
9
313
1