Last active
August 29, 2015 14:22
-
-
Save jesusalber1/2bd949ec1ece0b1407a8 to your computer and use it in GitHub Desktop.
Sanitize filename
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sanitizeFileName(name) { | |
return name | |
.replace(/ /g, '-') /* Spaces as - (slug...) */ | |
.replace(/[^A-Za-z0-9-_\.]/g, '') /* Only letters, numbers and symbols: - _ . */ | |
.replace(/\.+/g, '.') /* .. or more -> . */ | |
.replace(/-+/g, '-') /* -- or more -> - */ | |
.replace(/_+/g, '_'); /* __ or more -> _ */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment