Skip to content

Instantly share code, notes, and snippets.

@clauswitt
Created November 1, 2011 20:27
Show Gist options
  • Select an option

  • Save clauswitt/1331802 to your computer and use it in GitHub Desktop.

Select an option

Save clauswitt/1331802 to your computer and use it in GitHub Desktop.
Unique Filename generator
define('utils/files/nameGenerator', function() {
var count = 0;
var lastId = 0;
this.getName = function(ext) {
var d = new Date;
var f = d.getTime();
if(f == lastId) {
count++;
} else {
count = 0;
}
lastId = f;
if(count>0) {
f += '_'+count;
}
if(typeof ext != 'undefined') {
f += '.'+ext;
}
return f;
};
return this;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment