sanitize-basename
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

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

npm install sanitize-basename

Usage

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

License

MIT © Fabio Spampinato

Package Sidebar

Install

npm i sanitize-basename

Weekly Downloads

359

Version

2.0.2

License

MIT

Unpacked Size

5.29 kB

Total Files

9

Last publish

Collaborators

  • fabiospampinato