Skip to content

Instantly share code, notes, and snippets.

@mholtzhausen
Created September 8, 2015 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mholtzhausen/cb9b94f9cfbede852fbb to your computer and use it in GitHub Desktop.
Save mholtzhausen/cb9b94f9cfbede852fbb to your computer and use it in GitHub Desktop.
ES6 Snippets
function* uxid(pfix){
var idx=0;
var t = Date.now();
var r = Math.ceil(Math.random()*1000000);
while(true){
idx++;
yield (pfix ? (pfix) : '')+ t.toString(36) + idx.toString(36) + r.toString(36);
}
};
uxid.get =(function(){ var instance=uxid('UXID-'); return ()=>{ return instance.next().value;}})();
console.log(uxid.get());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment