uuid 【唯一序列号】🔥
描述
生成 UUID
# 1.示例
import { uuid } from 'sf-utils2'
console.log(uuid()) // be939ce7-213a-4f52-9c50-64486ca4cfb9
console.log(uuid()) // 8bfbb935-7e17-4acd-afcd-f7bf7f3bd05c
console.log(uuid()) // 7beac9b6-194f-4bf4-aad6-1823eae87931
console.log(uuid()) // 36c0a17c-7804-4dfe-8571-9c5b4334ee16
1
2
3
4
5
6
2
3
4
5
6
# 2.入参说明
| 参数 | 说明 | 类型 | 是否必填 |
|---|
# 3.源码
/**
* 返回uuid
* @returns {string}
*/
function uuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
let r = (Math.random() * 16) | 0,
v = c == 'x' ? r : (r & 0x3) | 0x8
return v.toString(16)
})
// return (
// `${Math.random().toString(16).slice(2)}${Math.random().toString(16).slice(2)}`.replace(/\./g, '-') +
// String(new Date().getTime())
// )
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
上次更新: 2024/01/16, 00:19:48