mirror of
https://github.com/xHyroM/roles-bot.git
synced 2024-11-10 03:08:06 +01:00
15 lines
441 B
TypeScript
15 lines
441 B
TypeScript
|
export const toSnowflake = (snowflake: number, epoch = DISCORD_EPOCH) => {
|
||
|
return new Date(snowflake / 4194304 + epoch)
|
||
|
}
|
||
|
|
||
|
export const DISCORD_EPOCH = 1420070400000;
|
||
|
|
||
|
export const isSnowflake = (snowflake: number, epoch?: number) => {
|
||
|
if (!Number.isInteger(+snowflake)) return false;
|
||
|
if (snowflake < 4194304) return false;
|
||
|
|
||
|
const timestamp = toSnowflake(snowflake, epoch);
|
||
|
if (isNaN(timestamp.getTime())) return false;
|
||
|
|
||
|
return true;
|
||
|
}
|