filenamify
Convert a string to a valid safe filename
Last updated 7 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm
$ cnpm install filenamify 
SYNC missed versions from official npm registry.

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

Current Tags

  • 5.1.1                                ...           latest (3 years ago)

7 Versions

  • 5.1.1                                ...           3 years ago
  • 5.1.0                                ...           4 years ago
  • 4.3.0                                ...           4 years ago
  • 3.0.0                                ...           6 years ago
  • 4.1.0                                ...           6 years ago
  • 2.1.0                                ...           7 years ago
  • 1.2.1                                ...           9 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org