harmony/src/types/snowflake.ts
Catry b7896756cd Fix typos
Co-Authored-By: yky4589 <8479056+yky4589@users.noreply.github.com>
Co-Authored-By: Choi Minseo <minseo0388@outlook.com>
Co-Authored-By: Aki <akiacode@users.noreply.github.com>
2020-10-22 15:48:43 +09:00

18 lines
446 B
TypeScript

export class Snowflake {
id: string
constructor(id: string) {
this.id = id
}
deconstruct() {
const snowflake = BigInt.asUintN(64, BigInt(this.id));
const res = {
timestamp: (snowflake << BigInt(22)) + BigInt(1420070400000),
workerId: (snowflake & BigInt(0x3E0000)) >> BigInt(17),
processId: (snowflake & BigInt(0x1F000)) >> BigInt(12),
increment: snowflake & BigInt(0xFFF),
}
return res
}
}