Neatly Punctuated Musings
Join us to discuss the challenges, solutions and best practices for in-house JavaScript code sharing. Tuesday, 12/17 at 10am PT/1pm ET.Sign up here »

filenamify

4.1.0 • Public • Published

filenamify Build Status

Convert a string to a valid safe filename

On Unix-like systems / is reserved and <>:"/\|?* on Windows.

Install

$ npm install filenamify

Usage

const filenamify = require('filenamify');
 
filenamify('<foo/bar>');
//=> 'foo!bar'
 
filenamify('foo:"bar"', {replacement: '🐴'});
//=> 'foo🐴bar'

API

filenamify(string, [options])

Convert a string to a valid filename.

filenamify.path(path, [options])

Convert the filename in a path a valid filename and return the augmented path.

options

Type: Object

replacement

Type: string
Default: '!'

String to use as replacement for reserved filename characters.

Cannot contain: < > : " / \ | ? *

maxLength

Type: boolean
Default: 100

Truncate the filename to the given length.

Systems generally allow up to 255 characters, but we default to 100 for usability reasons.

Related

License

MIT © Sindre Sorhus

Install

npm i filenamify

DownloadsWeekly Downloads

1,494,090

Version

4.1.0

License

MIT

Unpacked Size

6.06 kB

Total Files

5

Last publish

Collaborators

  • avatar