# sanitize-basename

> Sanitize a file name for cross-platform validity.

Latest version **2.0.2** (published 2025-01-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install sanitize-basename
pnpm add sanitize-basename
yarn add sanitize-basename
bun add sanitize-basename
```

## Health

**Score 50/100 (C)** — status: stable.

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

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2025-01-17 |
| First published | 2019-10-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | fabiospampinato |
| Keywords | sanitize, file, name, basename, cross-platform, unix, windows |

## Links

- npm: https://www.npmjs.com/package/sanitize-basename
- Repository: https://github.com/fabiospampinato/sanitize-basename
- Homepage: https://github.com/fabiospampinato/sanitize-basename#readme
- Issues: https://github.com/fabiospampinato/sanitize-basename/issues
- npm.io page: https://npm.io/package/sanitize-basename

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 2.0.2 (latest) — 2025-01-17
- 2.0.1 — 2024-04-04
- 2.0.0 — 2022-04-07
- 1.0.0 — 2019-10-09

## README

# Sanitize Basename

Sanitize a file name for cross-platform validity.

Instead of stripping out forbidden characters, like other libraries do, this library tries to replace them with similar-looking characters, trying to mainting maximum fidelity while still outputting valid file names for all platforms.

## Install

```sh
npm install sanitize-basename
```

## Usage

```ts
import sanitize from 'sanitize-basename';

// Let's sanitize some file names

sanitize ( '../foo' ); // => 'foo'
sanitize ( '<>:"/\\|?*.txt' ); // => '‹›꞉ˮ⁄∖ǀʔ⁎.txt'
sanitize ( 'aaaaaaaaaaaaaaaaa.txt', { maxLength: 10 } ); // => aaaaaa.txt
```

## Related

- [`unsanitize-basename`](https://github.com/fabiospampinato/unsanitize-basename): Unsanitize a file name, the inverse of this library.

## License

MIT © Fabio Spampinato

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