sanitize-basename
v2.0.1
Published
Sanitize a file name for cross-platform validity.
Downloads
1,005
Maintainers
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
npm install --save sanitize-basename
Usage
import sanitize from 'sanitize-basename';
sanitize ( '../foo' ); // => 'foo'
sanitize ( '<>:"/\\|?*.txt' ); // => '‹›꞉ˮ⁄∖ǀʔ⁎.txt'
sanitize ( 'aaaaaaaaaaaaaaaaa.txt', { maxLength: 10 } ); // => aaaaaa.txt
Related
- unsanitize-basename: Unsanitize a file name, the inverse of this library.
License
MIT © Fabio Spampinato