Get safe file name from a given string
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
docs
test
.gitignore
.jshintrc
.travis.yml
LICENSE
README.md
bower.json
package.json
safename.js

README.md

safename

Get safe file name from a given string.

Build Status

Example

// require only in node/browserify
var safename = require( 'safename' );

safename('my file name.txt');
// => my_file_name.txt

safename('my file name.txt', '-');
// => my-file-name.txt

safename.low('my file name.txt');
// => my_file_name.txt

safename.middle('my file name.txt');
// => my-file-name.txt

safename.dot('my file name.txt');
// => my.file.name.txt

Installation

Install with npm

$ npm install safename

Install with Bower

$ bower install safename

safename API

safename( name, space )

Get safe name for files

Parameters:

  • name String: string to transform
  • space String: replace for spaces. Optional, low dash ('_') by default
  • Return String: safe name

low( )

Safe name with low dash '_'.

Parameters:

Same as safename('your file name.txt', '_');

middle( )

Safe name with middle dash '-'.

Parameters:

Same as safename('your file name.txt', '-');

dot( )

Safe name with dots '.'.

Parameters:

Same as safename('your file name.txt', '.');

Tests

npm install && npm test

Build API docs

npm install && npm run build-docs




© 2014 jacoborus

Released under MIT License