Comparing version 0.5.0 to 0.6.0
@@ -5,5 +5,5 @@ /// <reference types="node"/> | ||
declare namespace tempy { | ||
type Options = MergeExclusive< | ||
{ | ||
/** | ||
type FileOptions = MergeExclusive< | ||
{ | ||
/** | ||
File extension. | ||
@@ -15,6 +15,6 @@ | ||
*/ | ||
readonly extension?: string; | ||
}, | ||
{ | ||
/** | ||
readonly extension?: string; | ||
}, | ||
{ | ||
/** | ||
Filename. | ||
@@ -26,5 +26,16 @@ | ||
*/ | ||
readonly name?: string; | ||
} | ||
readonly name?: string; | ||
} | ||
>; | ||
type DirectoryOptions = { | ||
/** | ||
_You usually won't need this option. Specify it only when actually needed._ | ||
Directory prefix. | ||
Useful for testing by making it easier to identify cache directories that are created. | ||
*/ | ||
readonly prefix?: string; | ||
}; | ||
} | ||
@@ -53,3 +64,3 @@ | ||
*/ | ||
file(options?: tempy.Options): string; | ||
file: (options?: tempy.FileOptions) => string; | ||
@@ -65,5 +76,8 @@ /** | ||
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' | ||
tempy.directory({prefix: 'a'}); | ||
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/name_3c085674ad31223b9653c88f725d6b41' | ||
``` | ||
*/ | ||
directory(): string; | ||
directory: (options?: tempy.DirectoryOptions) => string; | ||
@@ -81,3 +95,3 @@ /** | ||
*/ | ||
write(fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, options?: tempy.Options): Promise<string>; | ||
write: (fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, options?: tempy.FileOptions) => Promise<string>; | ||
@@ -95,3 +109,3 @@ /** | ||
*/ | ||
writeSync(fileContent: string | Buffer | TypedArray | DataView, options?: tempy.Options): string; | ||
writeSync: (fileContent: string | Buffer | TypedArray | DataView, options?: tempy.FileOptions) => string; | ||
@@ -98,0 +112,0 @@ /** |
@@ -13,3 +13,3 @@ 'use strict'; | ||
const getPath = () => path.join(tempDir, uniqueString()); | ||
const getPath = (prefix = '') => path.join(tempDir, prefix + uniqueString()); | ||
@@ -34,4 +34,4 @@ const writeStream = async (filePath, data) => pipeline(data, fs.createWriteStream(filePath)); | ||
module.exports.directory = () => { | ||
const directory = getPath(); | ||
module.exports.directory = ({prefix = ''} = {}) => { | ||
const directory = getPath(prefix); | ||
fs.mkdirSync(directory); | ||
@@ -38,0 +38,0 @@ return directory; |
{ | ||
"name": "tempy", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "Get a random temporary file or directory path", | ||
@@ -40,10 +40,15 @@ "license": "MIT", | ||
"temp-dir": "^2.0.0", | ||
"type-fest": "^0.12.0", | ||
"type-fest": "^0.16.0", | ||
"unique-string": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"tsd": "^0.11.0", | ||
"xo": "^0.25.4" | ||
"ava": "^2.4.0", | ||
"tsd": "^0.13.1", | ||
"xo": "^0.32.1" | ||
}, | ||
"xo": { | ||
"rules": { | ||
"node/no-unsupported-features/node-builtins": "off" | ||
} | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# tempy [![Build Status](https://travis-ci.org/sindresorhus/tempy.svg?branch=master)](https://travis-ci.org/sindresorhus/tempy) | ||
# tempy [![Build Status](https://travis-ci.com/sindresorhus/tempy.svg?branch=master)](https://travis-ci.com/github/sindresorhus/tempy) | ||
@@ -27,2 +27,5 @@ > Get a random temporary file or directory path | ||
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' | ||
tempy.directory({prefix: 'name'}); | ||
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/name_3c085674ad31223b9653c88f725d6b41' | ||
``` | ||
@@ -54,6 +57,21 @@ | ||
### tempy.directory() | ||
### tempy.directory([options]) | ||
Get a temporary directory path. The directory is created for you. | ||
#### options | ||
Type: `Object` | ||
##### prefix | ||
Type: `string` | ||
Directory prefix. | ||
Useful for testing by making it easier to identify cache directories that are created. | ||
*You usually won't need this option. Specify it only when actually needed.* | ||
### tempy.write(fileContent, options?) | ||
@@ -60,0 +78,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8927
131
112
+ Addedtype-fest@0.16.0(transitive)
- Removedtype-fest@0.12.0(transitive)
Updatedtype-fest@^0.16.0