Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/tempy
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 943ade0c935367117adbe2b690516ebc94139c6d
Choose a base ref
...
head repository: sindresorhus/tempy
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: df25f8156b677561e22ad13be24ad46f799a1ec2
Choose a head ref
  • 10 commits
  • 9 files changed
  • 2 contributors

Commits on Oct 12, 2020

  1. Verified

    This commit was signed with the committer’s verified signature.
    benjamn Ben Newman
    Copy the full SHA
    77a5091 View commit details
  2. 1.0.0

    sindresorhus committed Oct 12, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    benjamn Ben Newman
    Copy the full SHA
    3f5d3f4 View commit details

Commits on Dec 2, 2020

  1. Move to GitHub Actions

    sindresorhus committed Dec 2, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    benjamn Ben Newman
    Copy the full SHA
    66e464a View commit details

Commits on Mar 17, 2021

  1. Automatically clean up after an error is thrown (#31)

    Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
    Richienb and sindresorhus authored Mar 17, 2021

    Verified

    This commit was signed with the committer’s verified signature.
    benjamn Ben Newman
    Copy the full SHA
    d859280 View commit details
  2. 1.0.1

    sindresorhus committed Mar 17, 2021

    Verified

    This commit was signed with the committer’s verified signature.
    benjamn Ben Newman
    Copy the full SHA
    0e498c9 View commit details

Commits on Aug 18, 2021

  1. Verified

    This commit was signed with the committer’s verified signature.
    benjamn Ben Newman
    Copy the full SHA
    ca35430 View commit details
  2. 2.0.0

    sindresorhus committed Aug 18, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    578a8ac View commit details

Commits on Apr 18, 2022

  1. Require Node.js 14 (#41)

    Richienb authored Apr 18, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    benjamn Ben Newman
    Copy the full SHA
    4b3e859 View commit details
  2. Meta tweaks

    sindresorhus committed Apr 18, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    benjamn Ben Newman
    Copy the full SHA
    66a774e View commit details
  3. 3.0.0

    sindresorhus committed Apr 18, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    df25f81 View commit details
Showing with 325 additions and 304 deletions.
  1. +0 −3 .github/funding.yml
  2. +20 −0 .github/workflows/main.yml
  3. +0 −5 .travis.yml
  4. +139 −156 index.d.ts
  5. +37 −46 index.js
  6. +31 −19 index.test-d.ts
  7. +12 −15 package.json
  8. +20 −20 readme.md
  9. +66 −40 test.js
3 changes: 0 additions & 3 deletions .github/funding.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 16
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

295 changes: 139 additions & 156 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,173 +1,156 @@
/// <reference types="node"/>
import {Buffer} from 'node:buffer';
import {MergeExclusive, TypedArray} from 'type-fest';

declare namespace tempy {
type FileOptions = MergeExclusive<
{
/**
File extension.
Mutually exclusive with the `name` option.
export type FileOptions = MergeExclusive<
{
/**
File extension.
_You usually won't need this option. Specify it only when actually needed._
*/
readonly extension?: string;
},
{
/**
Filename.
Mutually exclusive with the `name` option.
Mutually exclusive with the `extension` option.
_You usually won't need this option. Specify it only when actually needed._
*/
readonly extension?: string;
},
{
/**
Filename.
_You usually won't need this option. Specify it only when actually needed._
*/
readonly name?: string;
}
>;
Mutually exclusive with the `extension` option.
type DirectoryOptions = {
/**
_You usually won't need this option. Specify it only when actually needed._
_You usually won't need this option. Specify it only when actually needed._
*/
readonly name?: string;
}
>;

Directory prefix.
export type DirectoryOptions = {
/**
Directory prefix.
Useful for testing by making it easier to identify cache directories that are created.
*/
readonly prefix?: string;
};
_You usually won't need this option. Specify it only when actually needed._
/**
The temporary path created by the function. Can be asynchronous.
Useful for testing by making it easier to identify cache directories that are created.
*/
type TaskCallback = (tempPath: string) => Promise<void> | void;
}
readonly prefix?: string;
};

declare const tempy: {
file: {
/**
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.
@example
```
import tempy = require('tempy');
await tempy.file.task(tempFile => {
console.log(tempFile);
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd'
});
```
*/
task: (callback: tempy.TaskCallback, options?: tempy.FileOptions) => Promise<void>;

/**
Get a temporary file path you can write to.
@example
```
import tempy = require('tempy');
tempy.file();
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd'
tempy.file({extension: 'png'});
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/a9fb0decd08179eb6cf4691568aa2018.png'
tempy.file({name: 'unicorn.png'});
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/f7f62bfd4e2a05f1589947647ed3f9ec/unicorn.png'
tempy.directory();
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
```
*/
(options?: tempy.FileOptions): string;
};

directory: {
/**
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.
@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>;
};
/**
The temporary path created by the function. Can be asynchronous.
*/
export type TaskCallback<ReturnValueType> = (temporaryPath: string) => Promise<ReturnValueType> | ReturnValueType;

/**
Synchronously write data to a random temp file.
/**
Get a temporary file path you can write to.
@example
```
import tempy = require('tempy');
@example
```
import {temporaryFile, temporaryDirectory} from 'tempy';
tempy.writeSync('🦄');
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
```
*/
writeSync: (fileContent: string | Buffer | TypedArray | DataView, options?: tempy.FileOptions) => string;
temporaryFile();
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd'
/**
Get the root temporary directory path.
temporaryFile({extension: 'png'});
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/a9fb0decd08179eb6cf4691568aa2018.png'
For example: `/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T`.
*/
readonly root: string;
};
temporaryFile({name: 'unicorn.png'});
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/f7f62bfd4e2a05f1589947647ed3f9ec/unicorn.png'
temporaryDirectory();
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
```
*/
export function temporaryFile(options?: FileOptions): string;

/**
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.
@example
```
import {temporaryFileTask} from 'tempy';
await temporaryFileTask(tempFile => {
console.log(tempFile);
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd'
});
```
*/
export function temporaryFileTask<ReturnValueType>(callback: TaskCallback<ReturnValueType>, options?: FileOptions): Promise <ReturnValueType>;

/**
Get a temporary directory path. The directory is created for you.
export = tempy;
@example
```
import {temporaryDirectory} from 'tempy';
temporaryDirectory();
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
temporaryDirectory({prefix: 'a'});
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/name_3c085674ad31223b9653c88f725d6b41'
```
*/
export function temporaryDirectory(options?: DirectoryOptions): string;

/**
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.
@example
```
import {temporaryDirectoryTask} from 'tempy';
await temporaryDirectoryTask(tempDirectory => {
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
})
```
*/
export function temporaryDirectoryTask<ReturnValueType>(callback: TaskCallback<ReturnValueType>, options?: DirectoryOptions): Promise<ReturnValueType>;

/**
Write data to a random temp file.
@example
```
import {temporaryWrite} from 'tempy';
await temporaryWrite('🦄');
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
```
*/
export function temporaryWrite(fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, options?: FileOptions): Promise<string>;

/**
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 {temporaryWriteTask} from 'tempy';
await temporaryWriteTask('🦄', tempFile => {
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd'
});
```
*/
export function temporaryWriteTask<ReturnValueType>(fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, callback: TaskCallback<ReturnValueType>, options?: FileOptions): Promise<ReturnValueType>;

/**
Synchronously write data to a random temp file.
@example
```
import {temporaryWriteSync} from 'tempy';
temporaryWriteSync('🦄');
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
```
*/
export function temporaryWriteSync(fileContent: string | Buffer | TypedArray | DataView, options?: FileOptions): string;

export {default as rootTemporaryDirectory} from 'temp-dir';
Loading