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 1.0.1 to 2.0.0

95

index.d.ts

@@ -1,45 +0,44 @@

/// <reference types="node"/>
/* eslint-disable @typescript-eslint/member-ordering */
import {Buffer} from 'node:buffer';
import {MergeExclusive, TypedArray} from 'type-fest';
declare namespace tempy {
type FileOptions = MergeExclusive<
{
/**
File extension.
export type FileOptions = MergeExclusive<
{
/**
File extension.
Mutually exclusive with the `name` option.
Mutually exclusive with the `name` 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 extension?: string;
},
{
/**
Filename.
Mutually exclusive with the `extension` option.
Mutually exclusive with the `extension` option.
_You usually won't need this option. Specify it only when actually needed._
*/
readonly name?: string;
}
>;
_You usually won't need this option. Specify it only when actually needed._
*/
readonly name?: string;
}
>;
type DirectoryOptions = {
/**
_You usually won't need this option. Specify it only when actually needed._
export type DirectoryOptions = {
/**
Directory prefix.
Directory prefix.
_You usually won't need this option. Specify it only when actually needed._
Useful for testing by making it easier to identify cache directories that are created.
*/
readonly prefix?: string;
};
/**
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<ReturnValueType> = (tempPath: string) => Promise<ReturnValueType> | ReturnValueType;
}
readonly prefix?: string;
};
/**
The temporary path created by the function. Can be asynchronous.
*/
export type TaskCallback<ReturnValueType> = (temporaryPath: string) => Promise<ReturnValueType> | ReturnValueType;
declare const tempy: {

@@ -54,3 +53,3 @@ file: {

```
import tempy = require('tempy');
import tempy from 'tempy';

@@ -63,3 +62,3 @@ await tempy.file.task(tempFile => {

*/
task: <ReturnValueType>(callback: tempy.TaskCallback<ReturnValueType>, options?: tempy.FileOptions) => Promise<ReturnValueType>;
task: <ReturnValueType>(callback: TaskCallback<ReturnValueType>, options?: FileOptions) => Promise<ReturnValueType>;

@@ -71,3 +70,3 @@ /**

```
import tempy = require('tempy');
import tempy from 'tempy';

@@ -87,3 +86,3 @@ tempy.file();

*/
(options?: tempy.FileOptions): string;
(options?: FileOptions): string;
};

@@ -99,3 +98,3 @@

```
import tempy = require('tempy');
import tempy from 'tempy';

@@ -107,3 +106,3 @@ await tempy.directory.task(tempDirectory => {

*/
task: <ReturnValueType>(callback: tempy.TaskCallback<ReturnValueType>, options?: tempy.DirectoryOptions) => Promise<ReturnValueType>;
task: <ReturnValueType>(callback: TaskCallback<ReturnValueType>, options?: DirectoryOptions) => Promise<ReturnValueType>;

@@ -115,3 +114,3 @@ /**

```
import tempy = require('tempy');
import tempy from 'tempy';

@@ -125,3 +124,3 @@ tempy.directory();

*/
(options?: tempy.DirectoryOptions): string;
(options?: DirectoryOptions): string;
};

@@ -137,3 +136,3 @@

```
import tempy = require('tempy');
import tempy from 'tempy';

@@ -145,3 +144,3 @@ await tempy.write.task('🦄', tempFile => {

*/
task: <ReturnValueType>(fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, callback: tempy.TaskCallback<ReturnValueType>, options?: tempy.FileOptions) => Promise<ReturnValueType>;
task: <ReturnValueType>(fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, callback: TaskCallback<ReturnValueType>, options?: FileOptions) => Promise<ReturnValueType>;

@@ -153,3 +152,3 @@ /**

```
import tempy = require('tempy');
import tempy from 'tempy';

@@ -160,3 +159,3 @@ await tempy.write('🦄');

*/
(fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, options?: tempy.FileOptions): Promise<string>;
(fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, options?: FileOptions): Promise<string>;
};

@@ -169,3 +168,3 @@

```
import tempy = require('tempy');
import tempy from 'tempy';

@@ -176,3 +175,3 @@ tempy.writeSync('🦄');

*/
writeSync: (fileContent: string | Buffer | TypedArray | DataView, options?: tempy.FileOptions) => string;
writeSync: (fileContent: string | Buffer | TypedArray | DataView, options?: FileOptions) => string;

@@ -187,2 +186,2 @@ /**

export = tempy;
export default tempy;

@@ -1,13 +0,11 @@

'use strict';
const fs = require('fs');
const path = require('path');
const uniqueString = require('unique-string');
const tempDir = require('temp-dir');
const isStream = require('is-stream');
const del = require('del');
const stream = require('stream');
const {promisify} = require('util');
import fs, {promises as fsPromises} from 'node:fs';
import path from 'node:path';
import stream from 'node:stream';
import {promisify} from 'node:util';
import uniqueString from 'unique-string';
import tempDir from 'temp-dir';
import {isStream} from 'is-stream';
import del from 'del'; // TODO: Replace this with `fs.rm` when targeting Node.js 14.
const pipeline = promisify(stream.pipeline);
const {writeFile} = fs.promises;
const pipeline = promisify(stream.pipeline); // TODO: Use `node:stream/promises` when targeting Node.js 16.

@@ -29,5 +27,7 @@ const getPath = (prefix = '') => path.join(tempDir, prefix + uniqueString());

module.exports.file = options => {
const tempy = {};
tempy.file = options => {
options = {
...options
...options,
};

@@ -40,3 +40,3 @@

return path.join(module.exports.directory(), options.name);
return path.join(tempy.directory(), options.name);
}

@@ -47,5 +47,5 @@

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

@@ -56,7 +56,7 @@ fs.mkdirSync(directory);

module.exports.directory.task = createTask(module.exports.directory);
tempy.directory.task = createTask(tempy.directory);
module.exports.write = async (data, options) => {
const filename = module.exports.file(options);
const write = isStream(data) ? writeStream : writeFile;
tempy.write = async (data, options) => {
const filename = tempy.file(options);
const write = isStream(data) ? writeStream : fsPromises.writeFile;
await write(filename, data);

@@ -66,6 +66,6 @@ return filename;

module.exports.write.task = createTask(module.exports.write, {extraArguments: 1});
tempy.write.task = createTask(tempy.write, {extraArguments: 1});
module.exports.writeSync = (data, options) => {
const filename = module.exports.file(options);
tempy.writeSync = (data, options) => {
const filename = tempy.file(options);
fs.writeFileSync(filename, data);

@@ -75,6 +75,8 @@ return filename;

Object.defineProperty(module.exports, 'root', {
Object.defineProperty(tempy, 'root', {
get() {
return tempDir;
}
},
});
export default tempy;
{
"name": "tempy",
"version": "1.0.1",
"version": "2.0.0",
"description": "Get a random temporary file or directory path",

@@ -13,4 +13,6 @@ "license": "MIT",

},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=10"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},

@@ -40,19 +42,14 @@ "scripts": {

"del": "^6.0.0",
"is-stream": "^2.0.0",
"is-stream": "^3.0.0",
"temp-dir": "^2.0.0",
"type-fest": "^0.16.0",
"unique-string": "^2.0.0"
"type-fest": "^2.0.0",
"unique-string": "^3.0.0"
},
"devDependencies": {
"ava": "^2.4.0",
"path-exists": "^4.0.0",
"ava": "^4.0.0-alpha.2",
"path-exists": "^5.0.0",
"touch": "^3.1.0",
"tsd": "^0.13.1",
"xo": "^0.33.1"
},
"xo": {
"rules": {
"node/no-unsupported-features/node-builtins": "off"
}
"tsd": "^0.17.0",
"xo": "^0.44.0"
}
}

@@ -14,3 +14,3 @@ # tempy

```js
const tempy = require('tempy');
import tempy from 'tempy';

@@ -17,0 +17,0 @@ tempy.file();

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