fabiospampinato / sanitize-basename

Sanitize a file name for cross-platform validity.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

License

MIT © Fabio Spampinato

About

Sanitize a file name for cross-platform validity.

License:MIT License


Languages

Language:TypeScript 56.1%Language:JavaScript 43.9%