# temp-sandbox

> Create a predictable temporary directory that makes it easy to create, list, and delete files.

Latest version **4.0.1** (published 2019-07-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install temp-sandbox
pnpm add temp-sandbox
yarn add temp-sandbox
bun add temp-sandbox
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.1 |
| Published | 2019-07-11 |
| First published | 2018-05-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8.9.0 |
| Dependencies | 6 |
| Unpacked size | 49.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Chris Blossom |
| Maintainers | chrisblossom |
| Keywords | sandbox, temp, tmp, test |

## Links

- npm: https://www.npmjs.com/package/temp-sandbox
- Repository: https://github.com/chrisblossom/temp-sandbox
- Issues: https://github.com/chrisblossom/temp-sandbox/issues
- npm.io page: https://npm.io/package/temp-sandbox

## Dependencies (6)

- [del](https://npm.io/package/del.md) ^5.0.0
- [slash](https://npm.io/package/slash.md) ^3.0.0
- [make-dir](https://npm.io/package/make-dir.md) ^3.0.0
- [read-pkg-up](https://npm.io/package/read-pkg-up.md) ^6.0.0
- [parent-module](https://npm.io/package/parent-module.md) ^2.0.0
- [read-dir-deep](https://npm.io/package/read-dir-deep.md) ^7.0.1

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 4.0.1 (latest) — 2019-07-11
- 4.0.0 — 2019-07-11
- 3.0.0 — 2019-05-18
- 2.0.0 — 2019-04-22
- 1.0.17 — 2019-03-04
- 1.0.16 — 2019-01-29
- 1.0.15 — 2019-01-18
- 1.0.14 — 2019-01-18
- 1.0.13 — 2019-01-17
- 1.0.12 — 2019-01-17
- 1.0.11 — 2019-01-16
- 1.0.10 — 2019-01-16
- 1.0.9 — 2019-01-15
- 1.0.8 — 2019-01-15
- 1.0.7 — 2019-01-08
- … 7 more at https://npm.io/package/temp-sandbox/versions

## README

# temp-sandbox

[![npm](https://img.shields.io/npm/v/temp-sandbox.svg?label=npm%20version)](https://www.npmjs.com/package/temp-sandbox)
[![Linux Build Status](https://img.shields.io/circleci/project/github/chrisblossom/temp-sandbox/master.svg?label=linux%20build)](https://circleci.com/gh/chrisblossom/temp-sandbox/tree/master)
[![Windows Build Status](https://img.shields.io/appveyor/ci/chrisblossom/temp-sandbox/master.svg?label=windows%20build)](https://ci.appveyor.com/project/chrisblossom/temp-sandbox/branch/master)
[![Code Coverage](https://img.shields.io/codecov/c/github/chrisblossom/temp-sandbox/master.svg)](https://codecov.io/gh/chrisblossom/temp-sandbox/branch/master)

## About

Create a predictable temporary directory that makes it easy to create, list, and delete files inside of the sandbox.

## Installation

`npm install --save-dev temp-sandbox`

## Usage

```js
// index.test.js
import { TempSandbox } from 'temp-sandbox';

// Create sandbox with a predictable directory name
const sandbox = new TempSandbox();

// Create sandbox with randomized directory name
// Typically used inside of a beforeEach
let sandboxRandom = new TempSandbox({ randomDir: true });

beforeEach(async () => {
	sandboxRandom = new TempSandbox({ randomDir: true });

	// Remove all files/directories inside sandbox
	await sandbox.clean();
	sandbox.cleanSync();
});

afterAll(async () => {
	// delete sandbox and sandbox instance
	await sandbox.destroySandbox();
	sandbox.destroySandboxSync();
});

test('create file', async () => {
	// Get absolute path of <SANDBOX>/file1.js
	sandbox.path.resolve('file1.js');

	// Get relative path of <SANDBOX>/nested/file1.js
	sandbox.path.relative('<SANDBOX>/nested/file1.js');

	// Get relative path of <SANDBOX>/nested/file1.js from <SANDBOX>/nested directory
	sandbox.path.relative('nested', '<SANDBOX>/nested/file1.js'); // file1.js

	// Create directory <SANDBOX>/nested/dir
	await sandbox.createDir('nested/dir');
	sandbox.createDirSync('nested/dir');

	// Create file <SANDBOX>/file1.js with contents: // file1.js
	await sandbox.createFile('file1.js', '// file1.js');
	sandbox.createFileSync('file1.js', '// file1.js');

	// Read <SANDBOX>/file1.js contents
	await sandbox.readFile('file1.js');
	sandbox.readFileSync('file1.js');

	// Delete file/folders <SANDBOX>/file1.js
	await sandbox.delete('file1.js');
	sandbox.deleteSync('file1.js');

	// List all files inside sandbox
	const fileList = await sandbox.getFileList();
	const fileListSync = sandbox.getFileListSync();

	// List all files and their checksum
	const fileHashes = await sandbox.getAllFilesHash();
	const fileHashesSync = sandbox.getAllFilesHashSync();

	// Get checksum of file1.js
	const file1Hash = await sandbox.getFileHash('file1.js');
	const file1HashSync = sandbox.getFileHashSync('file1.js');
});
```

---
_Source: https://npm.io/package/temp-sandbox · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
