Package Exports
- sanitize-filename
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sanitize-filename) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
sanitize-filename
Sanitize a string to be safe for use as a filename in Windows and Unix
file systems by stripping control
characters,
restricted characters \/:*?"<>|, and the reserved filenames, . and
...
Usage
// Some string that may be unsafe as a filesystem filename
var UNSAFE_FILENAME = "h*ello:/world?\u0000";
// Sanitize the unsafe filename to be safe for use as a filename
var sanitize = require("sanitize-filename"),
filename = sanitize(UNSAFE_FILENAME);
// Create a file using the safe filename
require("fs").createWriteStream(filename).end();Unique filenames
Note that two unique inputs can result in the same output. For example,
sanitize("file?") and sanitize("file*") will both return "file".
Empty filenames
Note that the return value can be an empty string. For example,
sanitize("><") will return "". To avoid this, use a default value
(e.g., sanitize("><") || "default") or options.replacement.
API
sanitize(filename, [options])
Sanitize the input string, filename, removing or replacing unsafe
characters. The options.replacement can be a string to replace unsafe
characters with.
Installation
npm install sanitize-filename