npm.io
2.0.2 • Published 1 year ago

sanitize-basename

Licence
MIT
Version
2.0.2
Deps
0
Size
5 kB
Vulns
0
Weekly
0
Stars
2

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

License

MIT Fabio Spampinato

Keywords