Skip to content

Instantly share code, notes, and snippets.

@yy-dev7
Created March 20, 2017 11:05
Show Gist options
  • Save yy-dev7/673b5b854e8a774bfc6eb51264e0f008 to your computer and use it in GitHub Desktop.
Save yy-dev7/673b5b854e8a774bfc6eb51264e0f008 to your computer and use it in GitHub Desktop.
generateUUID
/**
* 生成uuid
* @return {[string]} uuid
*/
function generateUUID() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1)
}
/* eslint-disable prefer-template */
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4()
}
export default generateUUID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment