Skip to content

Instantly share code, notes, and snippets.

@jacoborus
Created July 23, 2013 03:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jacoborus/6059681 to your computer and use it in GitHub Desktop.
Basic safe name for files
/* safe name for files */
var safeFilename = function ( name ) {
name = name.replace(/ /g, '-');
name = name.replace(/[^A-Za-z0-9-_\.]/g, '');
name = name.replace(/\.+/g, '.');
name = name.replace(/-+/g, '-');
name = name.replace(/_+/g, '_');
return name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment