@chainfuse/helpers 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,5 +12,10 @@ export declare class DiscordHelpers {
12
12
  * @link https://discord.com/developers/docs/reference#snowflake-ids-in-pagination-generating-a-snowflake-id-from-a-timestamp-example
13
13
  */
14
14
  static dateToDiscordSnowflake(date?: Date): bigint;
15
+ /**
16
+ * Generate a date from a Discord Snowflake ID.
17
+ * @link https://discord.com/developers/docs/reference#snowflakes-snowflake-id-format-structure-left-to-right
18
+ */
19
+ static discordSnowflakeToDate(snowflakeRaw?: bigint | string): Date;
15
20
  static discordRest(apiKey: string, cacheTtl?: number, forceCache?: boolean, executionContext?: ExecutionContext, logger?: CustomLoging): REST;
16
21
  }
package/dist/discord.mjs CHANGED
@@ -22,6 +22,14 @@ export class DiscordHelpers {
22
22
  }
23
23
  return (BigInt(date.valueOf()) - this.discordEpoch) << BigInt(22);
24
24
  }
25
+ /**
26
+ * Generate a date from a Discord Snowflake ID.
27
+ * @link https://discord.com/developers/docs/reference#snowflakes-snowflake-id-format-structure-left-to-right
28
+ */
29
+ static discordSnowflakeToDate(snowflakeRaw = this.discordEpoch) {
30
+ const snowflake = BigInt(snowflakeRaw);
31
+ return new Date(Number((snowflake >> BigInt(22)) + this.discordEpoch));
32
+ }
25
33
  static discordRest(apiKey, cacheTtl = 24 * 60 * 60, forceCache = false, executionContext, logger = false) {
26
34
  return new REST({
27
35
  agent: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainfuse/helpers",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "",
5
5
  "author": "ChainFuse",
6
6
  "homepage": "https://github.com/ChainFuse/packages/tree/main/packages/helpers#readme",
@@ -55,8 +55,8 @@
55
55
  "uuid": "^11.0.3"
56
56
  },
57
57
  "devDependencies": {
58
- "@chainfuse/types": "^1.1.6",
59
- "@types/node": "^22.9.0"
58
+ "@chainfuse/types": "^1.1.8",
59
+ "@types/node": "^22.9.1"
60
60
  },
61
- "gitHead": "206ed795a068521dfec992e6ae3b6771c73a3c6a"
61
+ "gitHead": "50cb4ae5092e0c748de2c9e8a74f1afc79e0102e"
62
62
  }