enso/app/gui2/shared/uuid.ts
somebody1234 168e222fcc
Read custom visualizations (#8180)
- Closes #8077

# Important Notes
Tests are still WIP
2023-11-03 20:09:45 +00:00

13 lines
517 B
TypeScript

import type { Uuid } from './yjsModel'
export function uuidFromBits(leastSigBits: bigint, mostSigBits: bigint): Uuid {
const bits = (mostSigBits << 64n) | leastSigBits
const string = bits.toString(16).padStart(32, '0')
return string.replace(/(........)(....)(....)(....)(............)/, '$1-$2-$3-$4-$5') as Uuid
}
export function uuidToBits(uuid: string): [leastSigBits: bigint, mostSigBits: bigint] {
const bits = BigInt('0x' + uuid.replace(/-/g, ''))
return [bits & 0xffffffffffffffffn, bits >> 64n]
}