mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
27 lines
704 B
JavaScript
27 lines
704 B
JavaScript
export default class Guid {
|
|
static generateGuid(random) {
|
|
let result = ""
|
|
let values = new Uint32Array(4);
|
|
if (random === true) {
|
|
crypto.getRandomValues(values)
|
|
}
|
|
values.forEach(n => {
|
|
this.result += ('00000000' + n.toString(16).toUpperCase()).slice(-8)
|
|
})
|
|
return result
|
|
}
|
|
|
|
constructor(guid) {
|
|
if (guid?.constructor?.name === 'String') {
|
|
this.value = guid
|
|
} else if (guid?.constructor?.name === 'FGuid') {
|
|
this.value = guid.value
|
|
} else {
|
|
this.value = Guid.generateGuid(guid === true)
|
|
}
|
|
}
|
|
|
|
toString() {
|
|
return this.value
|
|
}
|
|
} |