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.
npm install sanitize-basename
import sanitize from 'sanitize-basename';
// Let's sanitize some file names
sanitize ( '../foo' ); // => 'foo'
sanitize ( '<>:"/\\|?*.txt' ); // => '‹›꞉ˮ⁄∖ǀʔ⁎.txt'
sanitize ( 'aaaaaaaaaaaaaaaaa.txt', { maxLength: 10 } ); // => aaaaaa.txt
unsanitize-basename
: Unsanitize a file name, the inverse of this library.
MIT © Fabio Spampinato