Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tempy

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tempy - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

136

index.d.ts

@@ -38,56 +38,116 @@ /// <reference types="node"/>

};
/**
The temporary path created by the function. Can be asynchronous.
*/
type TaskCallback = (tempPath: string) => Promise<void> | void;
}
declare const tempy: {
/**
Get a temporary file path you can write to.
file: {
/**
The `callback` resolves with a temporary file path you can write to. The file is automatically cleaned up after the callback is executed.
@example
```
import tempy = require('tempy');
@returns A promise that resolves after the callback is executed and the file is cleaned up.
tempy.file();
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd'
@example
```
import tempy = require('tempy');
tempy.file({extension: 'png'});
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/a9fb0decd08179eb6cf4691568aa2018.png'
await tempy.file.task(tempFile => {
console.log(tempFile);
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd'
});
```
*/
task: (callback: tempy.TaskCallback, options?: tempy.FileOptions) => Promise<void>;
tempy.file({name: 'unicorn.png'});
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/f7f62bfd4e2a05f1589947647ed3f9ec/unicorn.png'
/**
Get a temporary file path you can write to.
tempy.directory();
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
```
*/
file: (options?: tempy.FileOptions) => string;
@example
```
import tempy = require('tempy');
/**
Get a temporary directory path. The directory is created for you.
tempy.file();
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd'
@example
```
import tempy = require('tempy');
tempy.file({extension: 'png'});
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/a9fb0decd08179eb6cf4691568aa2018.png'
tempy.directory();
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
tempy.file({name: 'unicorn.png'});
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/f7f62bfd4e2a05f1589947647ed3f9ec/unicorn.png'
tempy.directory({prefix: 'a'});
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/name_3c085674ad31223b9653c88f725d6b41'
```
*/
directory: (options?: tempy.DirectoryOptions) => string;
tempy.directory();
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
```
*/
(options?: tempy.FileOptions): string;
};
/**
Write data to a random temp file.
directory: {
/**
The `callback` resolves with a temporary directory path you can write to. The directory is automatically cleaned up after the callback is executed.
@example
```
import tempy = require('tempy');
@returns A promise that resolves after the callback is executed and the directory is cleaned up.
await tempy.write('🦄');
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
```
*/
write: (fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, options?: tempy.FileOptions) => Promise<string>;
@example
```
import tempy = require('tempy');
await tempy.directory.task(tempDirectory => {
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
})
```
*/
task: (callback: tempy.TaskCallback, options?: tempy.DirectoryOptions) => Promise<void>;
/**
Get a temporary directory path. The directory is created for you.
@example
```
import tempy = require('tempy');
tempy.directory();
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
tempy.directory({prefix: 'a'});
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/name_3c085674ad31223b9653c88f725d6b41'
```
*/
(options?: tempy.DirectoryOptions): string;
};
write: {
/**
Write data to a random temp file. The file is automatically cleaned up after the callback is executed.
@returns A promise that resolves after the callback is executed and the file is cleaned up.
@example
```
import tempy = require('tempy');
await tempy.write.task('🦄', tempFile => {
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd'
});
```
*/
task: (fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, callback: tempy.TaskCallback, options?: tempy.FileOptions) => Promise<void>;
/**
Write data to a random temp file.
@example
```
import tempy = require('tempy');
await tempy.write('🦄');
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
```
*/
(fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, options?: tempy.FileOptions): Promise<string>;
};
/**

@@ -94,0 +154,0 @@ Synchronously write data to a random temp file.

@@ -7,2 +7,3 @@ 'use strict';

const isStream = require('is-stream');
const del = require('del');
const stream = require('stream');

@@ -18,2 +19,9 @@ const {promisify} = require('util');

const createTask = (tempyFunction, {extraArguments = 0} = {}) => async (...arguments_) => {
const [callback, options] = arguments_.slice(extraArguments);
const result = await tempyFunction(...arguments_.slice(0, extraArguments), options);
await callback(result);
await del(result, {force: true});
};
module.exports.file = options => {

@@ -35,2 +43,4 @@ options = {

module.exports.file.task = createTask(module.exports.file);
module.exports.directory = ({prefix = ''} = {}) => {

@@ -42,2 +52,4 @@ const directory = getPath(prefix);

module.exports.directory.task = createTask(module.exports.directory);
module.exports.write = async (data, options) => {

@@ -50,2 +62,4 @@ const filename = module.exports.file(options);

module.exports.write.task = createTask(module.exports.write, {extraArguments: 1});
module.exports.writeSync = (data, options) => {

@@ -52,0 +66,0 @@ const filename = module.exports.file(options);

{
"name": "tempy",
"version": "0.6.0",
"version": "0.7.0",
"description": "Get a random temporary file or directory path",

@@ -38,2 +38,3 @@ "license": "MIT",

"dependencies": {
"del": "^5.1.0",
"is-stream": "^2.0.0",

@@ -46,2 +47,4 @@ "temp-dir": "^2.0.0",

"ava": "^2.4.0",
"path-exists": "^4.0.0",
"touch": "^3.1.0",
"tsd": "^0.13.1",

@@ -48,0 +51,0 @@ "xo": "^0.32.1"

@@ -38,2 +38,12 @@ # tempy [![Build Status](https://travis-ci.com/sindresorhus/tempy.svg?branch=master)](https://travis-ci.com/github/sindresorhus/tempy)

### tempy.file.task(callback, options?)
The `callback` resolves with a temporary file path you can write to. The file is automatically cleaned up after the callback is executed. Returns a promise that resolves after the callback is executed and the file is cleaned up.
#### callback
Type: `(tempPath: string) => void`
A callback that is executed with the temp file path. Can be asynchronous.
#### options

@@ -57,6 +67,16 @@

### tempy.directory([options])
### tempy.directory(options?)
Get a temporary directory path. The directory is created for you.
### tempy.directory.task(callback, options?)
The `callback` resolves with a temporary directory path you can write to. The directory is automatically cleaned up after the callback is executed. Returns a promise that resolves after the callback is executed and the directory is cleaned up.
##### callback
Type: `(tempPath: string) => void`
A callback that is executed with the temp directory path. Can be asynchronous.
#### options

@@ -68,3 +88,2 @@

Type: `string`

@@ -82,2 +101,6 @@

### tempy.write.task(fileContent, callback, options?)
Write data to a random temp file. The file is automatically cleaned up after the callback is executed. Returns a promise that resolves after the callback is executed and the file is cleaned up.
##### fileContent

@@ -89,2 +112,8 @@

##### callback
Type: `(tempPath: string) => void`
A callback that is executed with the temp file path. Can be asynchronous.
##### options

@@ -111,7 +140,1 @@

Get the root temporary directory path. For example: `/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T`
## FAQ
#### Why doesn't it have a cleanup method?
Temp files will be periodically cleaned up on macOS. Most Linux distros will clean up on reboot. If you're generating a lot of temp files, it's recommended to use a complementary module like [`del`](https://github.com/sindresorhus/del) for cleanup.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc