UNPKG

1.15 kBMarkdownView Raw
1# filenamify [![Build Status](https://travis-ci.org/sindresorhus/filenamify.svg?branch=master)](https://travis-ci.org/sindresorhus/filenamify)
2
3> Convert a string to a valid filename
4
5On Unix-like systems `/` is reserved and [`<>:"/\|?*`](http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29#naming_conventions) on Windows.
6
7
8## Install
9
10```
11$ npm install --save filenamify
12```
13
14
15## Usage
16
17```js
18var filenamify = require('filenamify');
19
20filenamify('<foo/bar>');
21//=> foo!bar
22
23filenamify('foo:"bar"', {replacement: '🐴'});
24//=> foo🐴bar
25```
26
27
28## API
29
30### filenamify(input, options)
31
32#### input
33
34*Required*
35Type: `string`
36
37String you want to use as a filename.
38
39#### options
40
41##### replacement
42
43Type: `string`
44Default: `'!'`
45
46String to use as replacement for reserved filename characters.
47
48Cannot contain: `<` `>` `:` `"` `/` `\` `|` `?` `*`
49
50
51## Related
52
53- [`filenamify-url`](https://github.com/sindresorhus/filenamify-url) - Convert a URL to a valid filename
54- [`valid-filename`](https://github.com/sindresorhus/valid-filename) - Check if a string is a valid filename
55
56
57## License
58
59MIT © [Sindre Sorhus](http://sindresorhus.com)