Files
ueblueprint/js/Guid.js
2021-10-17 21:54:40 +02:00

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
}
}