sanitize-filename

Sanitize string for use as filename

npm install sanitize-filename
4 downloads in the last day
24 downloads in the last week
122 downloads in the last month

sanitize-filename

Sanitize a string to be safe for use as a file name in Windows and Unix systems by stripping all control characters and restricted characters (\/:*?"<>|).

Example

// 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();

API

sanitize(filename)

Sanitize the input string.

Installation

npm install sanitize-filename
npm loves you