# valid-filename

> Check if a string is a valid filename

Latest version **5.0.0** (published 2026-08-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install valid-filename
pnpm add valid-filename
yarn add valid-filename
bun add valid-filename
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2026-08-28 |
| First published | 2015-01-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=22 |
| Dependencies | 1 |
| Unpacked size | 3.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 60 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | regex, regexp, filename, valid, validate, check, detect, is, string |

## Links

- npm: https://www.npmjs.com/package/valid-filename
- Repository: https://github.com/sindresorhus/valid-filename
- Homepage: https://github.com/sindresorhus/valid-filename#readme
- Issues: https://github.com/sindresorhus/valid-filename/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/valid-filename

## Dependencies (1)

- [filename-reserved-regex](https://npm.io/package/filename-reserved-regex.md) ^4.0.1

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 5.0.0 (latest) — 2026-08-28
- 4.0.0 — 2021-08-16
- 3.1.0 — 2019-04-05
- 3.0.0 — 2019-03-10
- 2.0.1 — 2016-10-10
- 2.0.0 — 2016-10-10
- 1.1.1 — 2016-02-05
- 1.1.0 — 2015-02-16
- 1.0.0 — 2015-01-14

## README

# valid-filename

> Check if a string is a [valid filename](https://github.com/sindresorhus/filename-reserved-regex)

## Install

```sh
npm install valid-filename
```

## Usage

```js
import isValidFilename from 'valid-filename';

isValidFilename('foo/bar');
//=> false

isValidFilename('foo-bar');
//=> true
```

## API

### isValidFilename(input)

Returns a `boolean` of whether `input` is a valid filename.

#### input

Type: `string`

The string to check.

## Related

- [filenamify](https://github.com/sindresorhus/filenamify) - Convert a string to a valid safe filename

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