18 lines
469 B
JavaScript
18 lines
469 B
JavaScript
|
|
import { v4 as uuidv4 } from 'uuid'
|
|||
|
|
|
|||
|
|
export function createUUID() {
|
|||
|
|
return uuidv4().replace(/-/g, '')
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export function createHashCodeByStr(str) {
|
|||
|
|
let hash = 0
|
|||
|
|
if (str.length === 0) return hash
|
|||
|
|
for (let i = 0; i < str.length; i++) {
|
|||
|
|
const char = str.charCodeAt(i)
|
|||
|
|
hash = ((hash << 5) - hash) + char
|
|||
|
|
hash = hash & hash // 转换为32位整数
|
|||
|
|
}
|
|||
|
|
// 将整数转换为16进制字符串,以缩短code长度
|
|||
|
|
return Math.abs(hash).toString(16)
|
|||
|
|
}
|