Skip to content

Instantly share code, notes, and snippets.

@kanakiyajay
Created August 14, 2014 09:09
Show Gist options
  • Save kanakiyajay/c21e294757b71a9b4a9c to your computer and use it in GitHub Desktop.
Save kanakiyajay/c21e294757b71a9b4a9c to your computer and use it in GitHub Desktop.
Angular: UID function creator
var uid = ['0', '0', '0'];
function nextUid() {
var index = uid.length;
var digit;
while(index) {
index--;
digit = uid[index].charCodeAt(0);
if (digit == 57 /*'9'*/) {
uid[index] = 'A';
return uid.join('');
}
if (digit == 90 /*'Z'*/) {
uid[index] = '0';
} else {
uid[index] = String.fromCharCode(digit + 1);
return uid.join('');
}
}
uid.unshift('0');
return uid.join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment