Skip to content

Instantly share code, notes, and snippets.

@alexanderjeurissen
Created August 1, 2014 10:39
Show Gist options
  • Save alexanderjeurissen/3cd2e8be561f3796dd20 to your computer and use it in GitHub Desktop.
Save alexanderjeurissen/3cd2e8be561f3796dd20 to your computer and use it in GitHub Desktop.
A simple file name parser factory for angular projects.
angular.module('appointment')
.factory('FileNameParser', function () {
return {
parse: function (file) {
var extensionPattern = /\.[0-9a-z]+$/i;
var extension = extensionPattern.exec(file);
return {
file_name: file.replace(extension, ''),
file_type: extension[0].replace('.', '').toLowerCase()
};
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment