Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

with-local-tmp-dir

2.2.11 • Public • Published

with-local-tmp-dir

NPM version Linux macOS Windows compatible Build status Coverage status Dependency status Renovate enabled

Open in Gitpod

Creates a temporary folder inside CWD and passes the path to a function. Afterwards, the folder is removed. Especially useful for testing.

Install

# NPM 
$ npm install with-local-tmp-dir
 
# Yarn 
$ yarn add with-local-tmp-dir

Usage

const withLocalTmpDir = require('with-local-tmp-dir')
 
await withLocalTmpDir(() => {
  console.log(process.cwd())
  //> /Users/max/project/tmp-18815DudQxmdn03Rz
})
// Now the folder does not exist anymore
 
// Also works with async functions =)
await withLocalTmpDir(async () => await ...)
 
// The folder is removed even if an exception is thrown
await withLocalTmpDir(async () => throw new Error('File could not be found'))
 
// Create the temporary folder in a specific path
await withLocalTmpDir('my-subpath', () => console.log(process.cwd()))
 
// Keep folder if not empty
await withLocalTmpDir('my-subpath', () => console.log(process.cwd()), { unsafeCleanup: false })

License

Unless stated otherwise all works are:

Copyright © Sebastian Landwehr info@dword-design.de

and licensed under:

MIT License

Install

npm i with-local-tmp-dir

DownloadsWeekly Downloads

749

Version

2.2.11

License

MIT

Unpacked Size

6.57 kB

Total Files

5

Last publish

Collaborators

  • avatar