Optimize uuid

This commit is contained in:
jiaming743 2020-07-02 11:00:19 +08:00
parent 9b84417f01
commit 026d9139c4
1 changed files with 3 additions and 3 deletions

View File

@ -38,10 +38,10 @@ export function getPointDistance (pointOne, pointTwo) {
return Math.sqrt(minusX * minusX + minusY * minusY)
}
export function uuid () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
export function uuid (hasHyphen) {
return (hasHyphen ? 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' : 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx').replace(/[xy]/g, function (c) {
const r = Math.random() * 16 | 0
const v = c == 'x' ? r : (r & 0x3 | 0x8)
return v.toString(16)
})
})
}