Skip to content

Instantly share code, notes, and snippets.

@darkcris1
Created January 7, 2021 10:36
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 darkcris1/23ef4eae8a35f6ccd784781bf28cfcfd to your computer and use it in GitHub Desktop.
Save darkcris1/23ef4eae8a35f6ccd784781bf28cfcfd to your computer and use it in GitHub Desktop.
Simple Unique ID Generator
function uuid(prefix = '', date = true) {
let counter = 0
return {
create: () => {
return `${date ? Date.now().toString(16) : ''}${prefix}${counter++}`
},
}
}
const uid = uuid('prefix')
console.log(uid.create()) // 176dc698f58prefix0
console.log(uid.create()) // 176dc698f59prefix1
console.log(uid.create()) // 176dc698f5aprefix2
console.log(uid.create()) // 176dc698f5bprefix3
console.log(uid.create()) // 176dc698f5bprefix4
console.log(uid.create()) // 176dc698f74prefix5
console.log(uid.create()) // 176dc698f76prefix6
console.log(uid.create()) // 176dc698f77prefix7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment