Sanitize string for use as filename
Sanitize a string to be safe for use as a filename in Windows and Unix file systems.
var sanitize = require"sanitize-filename";// Some string that may be unsafe or invalid as a filenamevar UNSAFE_USER_INPUT = "~/.\u0000ssh/authorized_keys";// Sanitize the string to be safe for use as a filename.var filename = sanitizeUNSAFE_USER_INPUT;// -> "~.sshauthrozied_keys"
sanitize-filename works by searching the input string for the following and removes them.
The return value is capped at 255 characters in length.
The return value will be safe for use as a filename on modern Windows,
OSX, and Unix file systems (
FAT 8.3 filenames are not supported.
Running tests will attempt write various filenames to disk (in the
working directory). Run
npm test to run tests against your file
Note that two unique inputs can result in the same return value. For example:
var sanitize = require"sanitize-filename";sanitize"file?"// -> "file"sanitize "file*"// -> "file"
Note that the return value can be an empty string. For example:
var sanitize = require"sanitize-filename";sanitize".."// -> ""
Sanitize the input string
filename by removing or replacing invalid
options.replacement can be a string to replace characters
npm install sanitize-filename