uuid增加连接符

master
yutent 2023-06-05 15:51:56 +08:00
parent 7323499dae
commit 51f83f4145
2 changed files with 4 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "crypto.web.js", "name": "crypto.web.js",
"version": "1.0.0", "version": "1.0.1",
"type": "module", "type": "module",
"description": "crypto.js浏览器版本,提供常用的加密封装", "description": "crypto.js浏览器版本,提供常用的加密封装",
"keywords": [ "keywords": [

View File

@ -5,7 +5,7 @@ const subtle = window.crypto.subtle
var __stamp__ = 0 var __stamp__ = 0
var __inc__ = 0 //用于生成保证唯一的uuid种子 var __inc__ = 0 //用于生成保证唯一的uuid种子
export function uuid() { export function uuid(pipe = '-') {
var rand = Math.random().toString(16).slice(2) + Math.random().toString(16).slice(2) var rand = Math.random().toString(16).slice(2) + Math.random().toString(16).slice(2)
var now = (~~(Date.now() / 1000)).toString(16) var now = (~~(Date.now() / 1000)).toString(16)
@ -15,8 +15,8 @@ export function uuid() {
__stamp__ = now __stamp__ = now
__inc__ = 0 __inc__ = 0
} }
rand = __stamp__ + __inc__.toString(16) + rand rand = __inc__.toString(16) + rand
return rand.slice(0, 24) return __stamp__ + pipe + rand.slice(0, 4) + pipe + rand.slice(4, 8) + pipe + rand.slice(-8)
} }
/** /**