harmony/src/types/snowflake.ts
Helloyunho ca7d143ddc Finally got somewhat working 👍
Co-Authored-By: Aki <71239005+AkiaCode@users.noreply.github.com>
Co-Authored-By: Lee Hyun <ink0416@naver.com>
Co-Authored-By: khk4912 <30457148+khk4912@users.noreply.github.com>
Co-Authored-By: Choi Minseo <minseo0388@outlook.com>
Co-Authored-By: Junseo Park <wonderlandpark@callisto.team>
Co-Authored-By: Y <8479056+yky4589@users.noreply.github.com>
2020-10-23 00:50:47 +09:00

23 lines
648 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)).toString(),
workerId: ((snowflake & BigInt(0x3e0000)) >> BigInt(17)).toString(),
processId: ((snowflake & BigInt(0x1f000)) >> BigInt(12)).toString(),
increment: (snowflake & BigInt(0xfff)).toString()
}
return res
}
}
// BigInt라서 이걸 어케 할까 고심끝에 나온게 toString 읍
// 엄...
// deconstruct가 소멸자임? 색 봐서는 아닌거같은데