# random-path

> Generate a random path name.

Latest version **1.0.0** (published 2021-07-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install random-path
pnpm add random-path
yarn add random-path
bun add random-path
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-07-24 |
| First published | 2016-08-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 2 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | linusu |

## Links

- npm: https://www.npmjs.com/package/random-path
- Repository: https://github.com/LinusU/node-random-path
- Homepage: https://github.com/LinusU/node-random-path#readme
- Issues: https://github.com/LinusU/node-random-path/issues
- npm.io page: https://npm.io/package/random-path

## Dependencies (2)

- [murmur-32](https://npm.io/package/murmur-32.md) ^1.0.0
- [base32-encode](https://npm.io/package/base32-encode.md) ^2.0.0

## Recent versions

- 1.0.0 (latest) — 2021-07-24
- 0.1.2 — 2020-05-18
- 0.1.1 — 2016-11-08
- 0.1.0 — 2016-08-21

## README

# Random Path

Generate a random path name.

## Installation

```sh
npm install --save random-path
```

## Usage

```js
import os from 'node:os'
import randomPath from 'random-path'

const path = randomPath(os.tmpDir(), '%s.txt')

console.log(path)
//=> /tmp/Y374CW8.txt
```

## API

### `randomPath(directory, template)`

- `directory` (`string`, required)
- `template` (`string`, required)
- returns `string` - the generated path

Generates a random path name with the specified `directory` and `template`.

`template` should be a string where `%s` will be replaced with some random characters (e.g. `'linusu-%s'`). The string should contain `%s` exactly once. If you want to include a literal percent sign, escape it with another one, e.g. `'%%string'` becomes `'%string'`.

**Important:** This module makes no guarantees on wether there exists a file at the returned path or not. Do not simply write data to the returned path. If you want a random file, use the higher level module [fs-temp](https://github.com/LinusU/fs-temp).

### `validateTemplate(template)`

- `template` (`string`, required)

Check to see if the template is a valid template accepted by `randomPath`. Throws an error if the template is invalid.

## See also

- [fs-temp](https://github.com/LinusU/fs-temp) - A quick and simple way to create temporary files and directories.

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