sanitize-filepath
v0.0.6
Published
safe filename and path
Downloads
1,192
Readme
sanitize-filepath
Sanitize a string for use as a filename/filepath.
Installation
npm i sanitize-filepath
Example
import { sanitize, sanitizePath } from 'sanitize-filepath';
const filename = sanitize('/home/user/<file>.ext'); // homeuserfile.ext
const filepath = sanitizePath('/home/user/<file>.ext'); // home/user/file.ext
Configure
const options: SanitizeOptions = {
maxLength: 255, // max filename length in bytes
replacement: "" // replacement for invalid characters
whitespaceReplacement: undefined // replacement for spaces, tabs, and newlines
};
const filename = sanitize('/home/user/<file>.ext', options)