@sapphire/snowflake 2.1.2 → 2.1.3-next.aeb3ee63.0

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.
package/README.md CHANGED
@@ -59,7 +59,7 @@ npm install @sapphire/snowflake
59
59
 
60
60
  #### Snowflakes with custom epoch
61
61
 
62
- ```ts
62
+ ```typescript
63
63
  // Import the Snowflake class
64
64
  const { Snowflake } = require('@sapphire/snowflake');
65
65
 
@@ -75,7 +75,7 @@ const uniqueId = snowflake.generate();
75
75
 
76
76
  #### Snowflake with Discord epoch constant
77
77
 
78
- ```ts
78
+ ```typescript
79
79
  // Import the Snowflake class
80
80
  const { DiscordSnowflake } = require('@sapphire/snowflake');
81
81
 
@@ -91,7 +91,7 @@ const uniqueId = DiscordSnowflake.generate();
91
91
 
92
92
  #### Snowflake with Twitter epoch constant
93
93
 
94
- ```ts
94
+ ```typescript
95
95
  // Import the Snowflake class
96
96
  const { TwitterSnowflake } = require('@sapphire/snowflake');
97
97
 
@@ -109,7 +109,7 @@ const uniqueId = TwitterSnowflake.generate();
109
109
 
110
110
  #### Snowflakes with custom epoch
111
111
 
112
- ```ts
112
+ ```typescript
113
113
  // Import the Snowflake class
114
114
  const { Snowflake } = require('@sapphire/snowflake');
115
115
 
@@ -125,7 +125,7 @@ const uniqueId = snowflake.deconstruct('3971046231244935168');
125
125
 
126
126
  #### Snowflake with Discord epoch constant
127
127
 
128
- ```ts
128
+ ```typescript
129
129
  // Import the Snowflake class
130
130
  const { DiscordSnowflake } = require('@sapphire/snowflake');
131
131
 
@@ -141,7 +141,7 @@ const uniqueId = DiscordSnowflake.deconstruct('3971046231244935168');
141
141
 
142
142
  #### Snowflake with Twitter epoch constant
143
143
 
144
- ```ts
144
+ ```typescript
145
145
  // Import the Snowflake class
146
146
  const { TwitterSnowflake } = require('@sapphire/snowflake');
147
147
 
@@ -207,6 +207,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
207
207
  <td align="center"><a href="https://github.com/nandhagk"><img src="https://avatars.githubusercontent.com/u/62976649?v=4?s=100" width="100px;" alt=""/><br /><sub><b>nandhagk</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/issues?q=author%3Anandhagk" title="Bug reports">🐛</a></td>
208
208
  <td align="center"><a href="https://megatank58.me/"><img src="https://avatars.githubusercontent.com/u/51410502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Megatank58</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Megatank58" title="Code">💻</a></td>
209
209
  <td align="center"><a href="https://github.com/UndiedGamer"><img src="https://avatars.githubusercontent.com/u/84702365?v=4?s=100" width="100px;" alt=""/><br /><sub><b>UndiedGamer</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=UndiedGamer" title="Code">💻</a></td>
210
+ <td align="center"><a href="https://github.com/Lioness100"><img src="https://avatars.githubusercontent.com/u/65814829?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lioness100</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Lioness100" title="Documentation">📖</a></td>
210
211
  </tr>
211
212
  </table>
212
213
 
package/dist/index.js CHANGED
@@ -70,7 +70,7 @@ class Snowflake {
70
70
  *
71
71
  * **note** when increment is not provided it defaults to the private increment of the instance
72
72
  * @example
73
- * ```ts
73
+ * ```typescript
74
74
  * const epoch = new Date('2000-01-01T00:00:00.000Z');
75
75
  * const snowflake = new Snowflake(epoch).generate();
76
76
  * ```
@@ -101,7 +101,7 @@ class Snowflake {
101
101
  * @param id the snowflake to deconstruct
102
102
  * @returns a deconstructed snowflake
103
103
  * @example
104
- * ```ts
104
+ * ```typescript
105
105
  * const epoch = new Date('2000-01-01T00:00:00.000Z');
106
106
  * const snowflake = new Snowflake(epoch).deconstruct('3971046231244935168');
107
107
  * ```
@@ -134,7 +134,7 @@ class DiscordSnowflake extends Snowflake {
134
134
  * @param id the snowflake to deconstruct
135
135
  * @returns a deconstructed snowflake
136
136
  * @example
137
- * ```ts
137
+ * ```typescript
138
138
  * const snowflake = DiscordSnowflake.deconstruct('3971046231244935168');
139
139
  * ```
140
140
  */
@@ -147,7 +147,7 @@ class DiscordSnowflake extends Snowflake {
147
147
  *
148
148
  * **note** when increment is not provided it defaults to `0n`
149
149
  * @example
150
- * ```ts
150
+ * ```typescript
151
151
  * const snowflake = DiscordSnowflake.generate();
152
152
  * ```
153
153
  * @returns A unique snowflake
@@ -171,7 +171,7 @@ Object.defineProperty(DiscordSnowflake, "Epoch", {
171
171
  * @param id the snowflake to deconstruct
172
172
  * @returns a deconstructed snowflake
173
173
  * @example
174
- * ```ts
174
+ * ```typescript
175
175
  * const snowflake = DiscordSnowflake.decode('3971046231244935168');
176
176
  * ```
177
177
  */
@@ -197,7 +197,7 @@ class TwitterSnowflake extends Snowflake {
197
197
  * @param id the snowflake to deconstruct
198
198
  * @returns a deconstructed snowflake
199
199
  * @example
200
- * ```ts
200
+ * ```typescript
201
201
  * const snowflake = TwitterSnowflake.deconstruct('3971046231244935168');
202
202
  * ```
203
203
  */
@@ -210,7 +210,7 @@ class TwitterSnowflake extends Snowflake {
210
210
  *
211
211
  * **note** when increment is not provided it defaults to `0n`
212
212
  * @example
213
- * ```ts
213
+ * ```typescript
214
214
  * const snowflake = TwitterSnowflake.generate();
215
215
  * ```
216
216
  * @returns A unique snowflake
@@ -234,7 +234,7 @@ Object.defineProperty(TwitterSnowflake, "Epoch", {
234
234
  * @param id the snowflake to deconstruct
235
235
  * @returns a deconstructed snowflake
236
236
  * @example
237
- * ```ts
237
+ * ```typescript
238
238
  * const snowflake = TwitterSnowflake.decode('3971046231244935168');
239
239
  * ```
240
240
  */
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/lib/Snowflake.ts","../src/lib/DiscordSnowflake.ts","../src/lib/TwitterSnowflake.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/explicit-member-accessibility */\n\n/**\n * A class for parsing snowflake ids\n */\nexport class Snowflake {\n\t/**\n\t * Internal incrementor for generating snowflakes\n\t * @internal\n\t */\n\t#increment = 0n;\n\n\t/**\n\t * Internal reference of the epoch passed in the constructor\n\t * @internal\n\t */\n\t#epoch: bigint;\n\n\t/**\n\t * Alias for {@link deconstruct}\n\t */\n\t// eslint-disable-next-line @typescript-eslint/unbound-method, @typescript-eslint/no-invalid-this\n\tpublic decode = this.deconstruct;\n\n\t/**\n\t * @param epoch the epoch to use\n\t */\n\tpublic constructor(epoch: number | bigint | Date) {\n\t\tthis.#epoch = BigInt(epoch instanceof Date ? epoch.getTime() : epoch);\n\t}\n\n\t/**\n\t * Generates a snowflake given an epoch and optionally a timestamp\n\t * @param options options to pass into the generator, see {@link SnowflakeGenerateOptions}\n\t *\n\t * **note** when increment is not provided it defaults to the private increment of the instance\n\t * @example\n\t * ```ts\n\t * const epoch = new Date('2000-01-01T00:00:00.000Z');\n\t * const snowflake = new Snowflake(epoch).generate();\n\t * ```\n\t * @returns A unique snowflake\n\t */\n\tpublic generate(\n\t\t{ increment, timestamp = Date.now(), workerID = 1n, processID = 1n }: SnowflakeGenerateOptions = {\n\t\t\ttimestamp: Date.now(),\n\t\t\tworkerID: 1n,\n\t\t\tprocessID: 1n\n\t\t}\n\t) {\n\t\tif (timestamp instanceof Date) timestamp = BigInt(timestamp.getTime());\n\t\tif (typeof timestamp === 'number' && !Number.isNaN(timestamp)) timestamp = BigInt(timestamp);\n\n\t\tif (typeof timestamp !== 'bigint') {\n\t\t\tthrow new TypeError(\n\t\t\t\t`\"timestamp\" argument must be a number, BigInt or Date (received ${Number.isNaN(timestamp) ? 'NaN' : typeof timestamp})`\n\t\t\t);\n\t\t}\n\n\t\tif (increment !== undefined && increment >= 4095n) increment = 0n;\n\t\tif (this.#increment >= 4095n) this.#increment = 0n;\n\n\t\t// timestamp, workerID, processID, increment\n\t\treturn (\n\t\t\t((timestamp - this.#epoch) << 22n) | (workerID << 17n) | (processID << 12n) | (increment === undefined ? this.#increment++ : increment++)\n\t\t);\n\t}\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```ts\n\t * const epoch = new Date('2000-01-01T00:00:00.000Z');\n\t * const snowflake = new Snowflake(epoch).deconstruct('3971046231244935168');\n\t * ```\n\t */\n\tpublic deconstruct(id: string | bigint): DeconstructedSnowflake {\n\t\tconst bigIntId = BigInt(id);\n\t\treturn {\n\t\t\tid: bigIntId,\n\t\t\ttimestamp: (bigIntId >> 22n) + this.#epoch,\n\t\t\tworkerID: (bigIntId >> 17n) & 0b11111n,\n\t\t\tprocessID: (bigIntId >> 12n) & 0b11111n,\n\t\t\tincrement: bigIntId & 0b111111111111n,\n\t\t\tepoch: this.#epoch\n\t\t};\n\t}\n}\n\n/**\n * Options for Snowflake#generate\n */\nexport interface SnowflakeGenerateOptions {\n\t/**\n\t * Timestamp or date of the snowflake to generate\n\t * @default Date.now()\n\t */\n\ttimestamp?: number | bigint | Date;\n\n\t/**\n\t * The increment to use\n\t * @default 0n\n\t * @remark keep in mind that this bigint is auto-incremented between generate calls\n\t */\n\tincrement?: bigint;\n\n\t/**\n\t * The worker ID to use\n\t * @default 1n\n\t */\n\tworkerID?: bigint;\n\n\t/**\n\t * The process ID to use\n\t * @default 1n\n\t */\n\tprocessID?: bigint;\n}\n\n/**\n * Object returned by Snowflake#deconstruct\n */\nexport interface DeconstructedSnowflake {\n\t/**\n\t * The id in BigInt form\n\t */\n\tid: bigint;\n\n\t/**\n\t * The timestamp stored in the snowflake\n\t */\n\ttimestamp: bigint;\n\n\t/**\n\t * The worker id stored in the snowflake\n\t */\n\tworkerID: bigint;\n\n\t/**\n\t * The process id stored in the snowflake\n\t */\n\tprocessID: bigint;\n\n\t/**\n\t * The increment stored in the snowflake\n\t */\n\tincrement: bigint;\n\n\t/**\n\t * The epoch to use in the snowflake\n\t */\n\tepoch: bigint;\n}\n","import { DeconstructedSnowflake, Snowflake, SnowflakeGenerateOptions } from './Snowflake';\n\n/**\n * A class for parsing snowflake ids using Discord's snowflake epoch\n *\n * Which is 2015-01-01 at 00:00:00.000 UTC+0, {@linkplain https://discord.com/developers/docs/reference#snowflakes}\n */\nexport class DiscordSnowflake extends Snowflake {\n\tpublic constructor() {\n\t\tsuper(DiscordSnowflake.Epoch);\n\t}\n\n\t/**\n\t * Discord epoch (`2015-01-01T00:00:00.000Z`)\n\t * @see {@linkplain https://discord.com/developers/docs/reference#snowflakes}\n\t */\n\tpublic static readonly Epoch = 1420070400000n;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```ts\n\t * const snowflake = DiscordSnowflake.decode('3971046231244935168');\n\t * ```\n\t */\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tpublic static decode = DiscordSnowflake.deconstruct;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```ts\n\t * const snowflake = DiscordSnowflake.deconstruct('3971046231244935168');\n\t * ```\n\t */\n\tpublic static deconstruct(id: string | bigint): DeconstructedSnowflake {\n\t\treturn new DiscordSnowflake().deconstruct(id);\n\t}\n\n\t/**\n\t * Generates a snowflake given an epoch and optionally a timestamp\n\t * @param options {@link SnowflakeGenerateOptions} to pass into the generator\n\t *\n\t * **note** when increment is not provided it defaults to `0n`\n\t * @example\n\t * ```ts\n\t * const snowflake = DiscordSnowflake.generate();\n\t * ```\n\t * @returns A unique snowflake\n\t */\n\tpublic static generate(options: SnowflakeGenerateOptions = { timestamp: Date.now() }) {\n\t\treturn new DiscordSnowflake().generate(options);\n\t}\n}\n","import { DeconstructedSnowflake, Snowflake, SnowflakeGenerateOptions } from './Snowflake';\n\n/**\n * A class for parsing snowflake ids using Twitter's snowflake epoch\n *\n * Which is 2006-03-21 at 20:50:14.000 UTC+0, the time and date of the first tweet ever made {@linkplain https://twitter.com/jack/status/20}\n */\nexport class TwitterSnowflake extends Snowflake {\n\tpublic constructor() {\n\t\tsuper(TwitterSnowflake.Epoch);\n\t}\n\n\t/**\n\t * Twitter epoch (`2006-03-21T20:50:14.000Z`)\n\t * @see {@linkplain https://twitter.com/jack/status/20}, first tweet ever made\n\t */\n\tpublic static readonly Epoch = 1142974214000n;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```ts\n\t * const snowflake = TwitterSnowflake.decode('3971046231244935168');\n\t * ```\n\t */\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tpublic static decode = TwitterSnowflake.deconstruct;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```ts\n\t * const snowflake = TwitterSnowflake.deconstruct('3971046231244935168');\n\t * ```\n\t */\n\tpublic static deconstruct(id: string | bigint): DeconstructedSnowflake {\n\t\treturn new TwitterSnowflake().deconstruct(id);\n\t}\n\n\t/**\n\t * Generates a snowflake given an epoch and optionally a timestamp\n\t * @param options options to pass into the generator, see {@link SnowflakeGenerateOptions}\n\t *\n\t * **note** when increment is not provided it defaults to `0n`\n\t * @example\n\t * ```ts\n\t * const snowflake = TwitterSnowflake.generate();\n\t * ```\n\t * @returns A unique snowflake\n\t */\n\tpublic static generate(options: SnowflakeGenerateOptions = { timestamp: Date.now() }) {\n\t\treturn new TwitterSnowflake().generate(options);\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAEA;;;MAGa,SAAS;;;;IAsBrB,YAAmB,KAA6B;;;;;QAjBhD,+BAAa,EAAE,EAAC;;;;;QAMhB,mCAAe;;;;;QAMf;;;;mBAAgB,IAAI,CAAC,WAAW;WAAC;QAMhC,uBAAA,IAAI,oBAAU,MAAM,CAAC,KAAK,Y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;GAAC;AAE9C;;;;;;;;;AASA;AACA;;;;WAAuB,gBAAgB,CAAC,WAAW;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/lib/Snowflake.ts","../src/lib/DiscordSnowflake.ts","../src/lib/TwitterSnowflake.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/explicit-member-accessibility */\n\n/**\n * A class for parsing snowflake ids\n */\nexport class Snowflake {\n\t/**\n\t * Internal incrementor for generating snowflakes\n\t * @internal\n\t */\n\t#increment = 0n;\n\n\t/**\n\t * Internal reference of the epoch passed in the constructor\n\t * @internal\n\t */\n\t#epoch: bigint;\n\n\t/**\n\t * Alias for {@link deconstruct}\n\t */\n\t// eslint-disable-next-line @typescript-eslint/unbound-method, @typescript-eslint/no-invalid-this\n\tpublic decode = this.deconstruct;\n\n\t/**\n\t * @param epoch the epoch to use\n\t */\n\tpublic constructor(epoch: number | bigint | Date) {\n\t\tthis.#epoch = BigInt(epoch instanceof Date ? epoch.getTime() : epoch);\n\t}\n\n\t/**\n\t * Generates a snowflake given an epoch and optionally a timestamp\n\t * @param options options to pass into the generator, see {@link SnowflakeGenerateOptions}\n\t *\n\t * **note** when increment is not provided it defaults to the private increment of the instance\n\t * @example\n\t * ```typescript\n\t * const epoch = new Date('2000-01-01T00:00:00.000Z');\n\t * const snowflake = new Snowflake(epoch).generate();\n\t * ```\n\t * @returns A unique snowflake\n\t */\n\tpublic generate(\n\t\t{ increment, timestamp = Date.now(), workerID = 1n, processID = 1n }: SnowflakeGenerateOptions = {\n\t\t\ttimestamp: Date.now(),\n\t\t\tworkerID: 1n,\n\t\t\tprocessID: 1n\n\t\t}\n\t) {\n\t\tif (timestamp instanceof Date) timestamp = BigInt(timestamp.getTime());\n\t\tif (typeof timestamp === 'number' && !Number.isNaN(timestamp)) timestamp = BigInt(timestamp);\n\n\t\tif (typeof timestamp !== 'bigint') {\n\t\t\tthrow new TypeError(\n\t\t\t\t`\"timestamp\" argument must be a number, BigInt or Date (received ${Number.isNaN(timestamp) ? 'NaN' : typeof timestamp})`\n\t\t\t);\n\t\t}\n\n\t\tif (increment !== undefined && increment >= 4095n) increment = 0n;\n\t\tif (this.#increment >= 4095n) this.#increment = 0n;\n\n\t\t// timestamp, workerID, processID, increment\n\t\treturn (\n\t\t\t((timestamp - this.#epoch) << 22n) | (workerID << 17n) | (processID << 12n) | (increment === undefined ? this.#increment++ : increment++)\n\t\t);\n\t}\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```typescript\n\t * const epoch = new Date('2000-01-01T00:00:00.000Z');\n\t * const snowflake = new Snowflake(epoch).deconstruct('3971046231244935168');\n\t * ```\n\t */\n\tpublic deconstruct(id: string | bigint): DeconstructedSnowflake {\n\t\tconst bigIntId = BigInt(id);\n\t\treturn {\n\t\t\tid: bigIntId,\n\t\t\ttimestamp: (bigIntId >> 22n) + this.#epoch,\n\t\t\tworkerID: (bigIntId >> 17n) & 0b11111n,\n\t\t\tprocessID: (bigIntId >> 12n) & 0b11111n,\n\t\t\tincrement: bigIntId & 0b111111111111n,\n\t\t\tepoch: this.#epoch\n\t\t};\n\t}\n}\n\n/**\n * Options for Snowflake#generate\n */\nexport interface SnowflakeGenerateOptions {\n\t/**\n\t * Timestamp or date of the snowflake to generate\n\t * @default Date.now()\n\t */\n\ttimestamp?: number | bigint | Date;\n\n\t/**\n\t * The increment to use\n\t * @default 0n\n\t * @remark keep in mind that this bigint is auto-incremented between generate calls\n\t */\n\tincrement?: bigint;\n\n\t/**\n\t * The worker ID to use\n\t * @default 1n\n\t */\n\tworkerID?: bigint;\n\n\t/**\n\t * The process ID to use\n\t * @default 1n\n\t */\n\tprocessID?: bigint;\n}\n\n/**\n * Object returned by Snowflake#deconstruct\n */\nexport interface DeconstructedSnowflake {\n\t/**\n\t * The id in BigInt form\n\t */\n\tid: bigint;\n\n\t/**\n\t * The timestamp stored in the snowflake\n\t */\n\ttimestamp: bigint;\n\n\t/**\n\t * The worker id stored in the snowflake\n\t */\n\tworkerID: bigint;\n\n\t/**\n\t * The process id stored in the snowflake\n\t */\n\tprocessID: bigint;\n\n\t/**\n\t * The increment stored in the snowflake\n\t */\n\tincrement: bigint;\n\n\t/**\n\t * The epoch to use in the snowflake\n\t */\n\tepoch: bigint;\n}\n","import { DeconstructedSnowflake, Snowflake, SnowflakeGenerateOptions } from './Snowflake';\n\n/**\n * A class for parsing snowflake ids using Discord's snowflake epoch\n *\n * Which is 2015-01-01 at 00:00:00.000 UTC+0, {@linkplain https://discord.com/developers/docs/reference#snowflakes}\n */\nexport class DiscordSnowflake extends Snowflake {\n\tpublic constructor() {\n\t\tsuper(DiscordSnowflake.Epoch);\n\t}\n\n\t/**\n\t * Discord epoch (`2015-01-01T00:00:00.000Z`)\n\t * @see {@linkplain https://discord.com/developers/docs/reference#snowflakes}\n\t */\n\tpublic static readonly Epoch = 1420070400000n;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```typescript\n\t * const snowflake = DiscordSnowflake.decode('3971046231244935168');\n\t * ```\n\t */\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tpublic static decode = DiscordSnowflake.deconstruct;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```typescript\n\t * const snowflake = DiscordSnowflake.deconstruct('3971046231244935168');\n\t * ```\n\t */\n\tpublic static deconstruct(id: string | bigint): DeconstructedSnowflake {\n\t\treturn new DiscordSnowflake().deconstruct(id);\n\t}\n\n\t/**\n\t * Generates a snowflake given an epoch and optionally a timestamp\n\t * @param options {@link SnowflakeGenerateOptions} to pass into the generator\n\t *\n\t * **note** when increment is not provided it defaults to `0n`\n\t * @example\n\t * ```typescript\n\t * const snowflake = DiscordSnowflake.generate();\n\t * ```\n\t * @returns A unique snowflake\n\t */\n\tpublic static generate(options: SnowflakeGenerateOptions = { timestamp: Date.now() }) {\n\t\treturn new DiscordSnowflake().generate(options);\n\t}\n}\n","import { DeconstructedSnowflake, Snowflake, SnowflakeGenerateOptions } from './Snowflake';\n\n/**\n * A class for parsing snowflake ids using Twitter's snowflake epoch\n *\n * Which is 2006-03-21 at 20:50:14.000 UTC+0, the time and date of the first tweet ever made {@linkplain https://twitter.com/jack/status/20}\n */\nexport class TwitterSnowflake extends Snowflake {\n\tpublic constructor() {\n\t\tsuper(TwitterSnowflake.Epoch);\n\t}\n\n\t/**\n\t * Twitter epoch (`2006-03-21T20:50:14.000Z`)\n\t * @see {@linkplain https://twitter.com/jack/status/20}, first tweet ever made\n\t */\n\tpublic static readonly Epoch = 1142974214000n;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```typescript\n\t * const snowflake = TwitterSnowflake.decode('3971046231244935168');\n\t * ```\n\t */\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tpublic static decode = TwitterSnowflake.deconstruct;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```typescript\n\t * const snowflake = TwitterSnowflake.deconstruct('3971046231244935168');\n\t * ```\n\t */\n\tpublic static deconstruct(id: string | bigint): DeconstructedSnowflake {\n\t\treturn new TwitterSnowflake().deconstruct(id);\n\t}\n\n\t/**\n\t * Generates a snowflake given an epoch and optionally a timestamp\n\t * @param options options to pass into the generator, see {@link SnowflakeGenerateOptions}\n\t *\n\t * **note** when increment is not provided it defaults to `0n`\n\t * @example\n\t * ```typescript\n\t * const snowflake = TwitterSnowflake.generate();\n\t * ```\n\t * @returns A unique snowflake\n\t */\n\tpublic static generate(options: SnowflakeGenerateOptions = { timestamp: Date.now() }) {\n\t\treturn new TwitterSnowflake().generate(options);\n\t}\n}\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gB,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;KAC9C;;;;;;;;;;;;IAaM,OAAO,QAAQ,CAAC,UAAoC,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE;QACnF,OAAO,IAAI,gBAAgB,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;KAChD;;AA5CD;;;;AAIA;;;;WAA+B,cAAc;GAAC;AAE9C;;;;;;;;;AASA;AACA;;;;WAAuB,gBAAgB,CAAC,WAAW;;;;;;;"}
package/dist/index.mjs CHANGED
@@ -66,7 +66,7 @@ class Snowflake {
66
66
  *
67
67
  * **note** when increment is not provided it defaults to the private increment of the instance
68
68
  * @example
69
- * ```ts
69
+ * ```typescript
70
70
  * const epoch = new Date('2000-01-01T00:00:00.000Z');
71
71
  * const snowflake = new Snowflake(epoch).generate();
72
72
  * ```
@@ -97,7 +97,7 @@ class Snowflake {
97
97
  * @param id the snowflake to deconstruct
98
98
  * @returns a deconstructed snowflake
99
99
  * @example
100
- * ```ts
100
+ * ```typescript
101
101
  * const epoch = new Date('2000-01-01T00:00:00.000Z');
102
102
  * const snowflake = new Snowflake(epoch).deconstruct('3971046231244935168');
103
103
  * ```
@@ -130,7 +130,7 @@ class DiscordSnowflake extends Snowflake {
130
130
  * @param id the snowflake to deconstruct
131
131
  * @returns a deconstructed snowflake
132
132
  * @example
133
- * ```ts
133
+ * ```typescript
134
134
  * const snowflake = DiscordSnowflake.deconstruct('3971046231244935168');
135
135
  * ```
136
136
  */
@@ -143,7 +143,7 @@ class DiscordSnowflake extends Snowflake {
143
143
  *
144
144
  * **note** when increment is not provided it defaults to `0n`
145
145
  * @example
146
- * ```ts
146
+ * ```typescript
147
147
  * const snowflake = DiscordSnowflake.generate();
148
148
  * ```
149
149
  * @returns A unique snowflake
@@ -167,7 +167,7 @@ Object.defineProperty(DiscordSnowflake, "Epoch", {
167
167
  * @param id the snowflake to deconstruct
168
168
  * @returns a deconstructed snowflake
169
169
  * @example
170
- * ```ts
170
+ * ```typescript
171
171
  * const snowflake = DiscordSnowflake.decode('3971046231244935168');
172
172
  * ```
173
173
  */
@@ -193,7 +193,7 @@ class TwitterSnowflake extends Snowflake {
193
193
  * @param id the snowflake to deconstruct
194
194
  * @returns a deconstructed snowflake
195
195
  * @example
196
- * ```ts
196
+ * ```typescript
197
197
  * const snowflake = TwitterSnowflake.deconstruct('3971046231244935168');
198
198
  * ```
199
199
  */
@@ -206,7 +206,7 @@ class TwitterSnowflake extends Snowflake {
206
206
  *
207
207
  * **note** when increment is not provided it defaults to `0n`
208
208
  * @example
209
- * ```ts
209
+ * ```typescript
210
210
  * const snowflake = TwitterSnowflake.generate();
211
211
  * ```
212
212
  * @returns A unique snowflake
@@ -230,7 +230,7 @@ Object.defineProperty(TwitterSnowflake, "Epoch", {
230
230
  * @param id the snowflake to deconstruct
231
231
  * @returns a deconstructed snowflake
232
232
  * @example
233
- * ```ts
233
+ * ```typescript
234
234
  * const snowflake = TwitterSnowflake.decode('3971046231244935168');
235
235
  * ```
236
236
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/lib/Snowflake.ts","../src/lib/DiscordSnowflake.ts","../src/lib/TwitterSnowflake.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/explicit-member-accessibility */\n\n/**\n * A class for parsing snowflake ids\n */\nexport class Snowflake {\n\t/**\n\t * Internal incrementor for generating snowflakes\n\t * @internal\n\t */\n\t#increment = 0n;\n\n\t/**\n\t * Internal reference of the epoch passed in the constructor\n\t * @internal\n\t */\n\t#epoch: bigint;\n\n\t/**\n\t * Alias for {@link deconstruct}\n\t */\n\t// eslint-disable-next-line @typescript-eslint/unbound-method, @typescript-eslint/no-invalid-this\n\tpublic decode = this.deconstruct;\n\n\t/**\n\t * @param epoch the epoch to use\n\t */\n\tpublic constructor(epoch: number | bigint | Date) {\n\t\tthis.#epoch = BigInt(epoch instanceof Date ? epoch.getTime() : epoch);\n\t}\n\n\t/**\n\t * Generates a snowflake given an epoch and optionally a timestamp\n\t * @param options options to pass into the generator, see {@link SnowflakeGenerateOptions}\n\t *\n\t * **note** when increment is not provided it defaults to the private increment of the instance\n\t * @example\n\t * ```ts\n\t * const epoch = new Date('2000-01-01T00:00:00.000Z');\n\t * const snowflake = new Snowflake(epoch).generate();\n\t * ```\n\t * @returns A unique snowflake\n\t */\n\tpublic generate(\n\t\t{ increment, timestamp = Date.now(), workerID = 1n, processID = 1n }: SnowflakeGenerateOptions = {\n\t\t\ttimestamp: Date.now(),\n\t\t\tworkerID: 1n,\n\t\t\tprocessID: 1n\n\t\t}\n\t) {\n\t\tif (timestamp instanceof Date) timestamp = BigInt(timestamp.getTime());\n\t\tif (typeof timestamp === 'number' && !Number.isNaN(timestamp)) timestamp = BigInt(timestamp);\n\n\t\tif (typeof timestamp !== 'bigint') {\n\t\t\tthrow new TypeError(\n\t\t\t\t`\"timestamp\" argument must be a number, BigInt or Date (received ${Number.isNaN(timestamp) ? 'NaN' : typeof timestamp})`\n\t\t\t);\n\t\t}\n\n\t\tif (increment !== undefined && increment >= 4095n) increment = 0n;\n\t\tif (this.#increment >= 4095n) this.#increment = 0n;\n\n\t\t// timestamp, workerID, processID, increment\n\t\treturn (\n\t\t\t((timestamp - this.#epoch) << 22n) | (workerID << 17n) | (processID << 12n) | (increment === undefined ? this.#increment++ : increment++)\n\t\t);\n\t}\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```ts\n\t * const epoch = new Date('2000-01-01T00:00:00.000Z');\n\t * const snowflake = new Snowflake(epoch).deconstruct('3971046231244935168');\n\t * ```\n\t */\n\tpublic deconstruct(id: string | bigint): DeconstructedSnowflake {\n\t\tconst bigIntId = BigInt(id);\n\t\treturn {\n\t\t\tid: bigIntId,\n\t\t\ttimestamp: (bigIntId >> 22n) + this.#epoch,\n\t\t\tworkerID: (bigIntId >> 17n) & 0b11111n,\n\t\t\tprocessID: (bigIntId >> 12n) & 0b11111n,\n\t\t\tincrement: bigIntId & 0b111111111111n,\n\t\t\tepoch: this.#epoch\n\t\t};\n\t}\n}\n\n/**\n * Options for Snowflake#generate\n */\nexport interface SnowflakeGenerateOptions {\n\t/**\n\t * Timestamp or date of the snowflake to generate\n\t * @default Date.now()\n\t */\n\ttimestamp?: number | bigint | Date;\n\n\t/**\n\t * The increment to use\n\t * @default 0n\n\t * @remark keep in mind that this bigint is auto-incremented between generate calls\n\t */\n\tincrement?: bigint;\n\n\t/**\n\t * The worker ID to use\n\t * @default 1n\n\t */\n\tworkerID?: bigint;\n\n\t/**\n\t * The process ID to use\n\t * @default 1n\n\t */\n\tprocessID?: bigint;\n}\n\n/**\n * Object returned by Snowflake#deconstruct\n */\nexport interface DeconstructedSnowflake {\n\t/**\n\t * The id in BigInt form\n\t */\n\tid: bigint;\n\n\t/**\n\t * The timestamp stored in the snowflake\n\t */\n\ttimestamp: bigint;\n\n\t/**\n\t * The worker id stored in the snowflake\n\t */\n\tworkerID: bigint;\n\n\t/**\n\t * The process id stored in the snowflake\n\t */\n\tprocessID: bigint;\n\n\t/**\n\t * The increment stored in the snowflake\n\t */\n\tincrement: bigint;\n\n\t/**\n\t * The epoch to use in the snowflake\n\t */\n\tepoch: bigint;\n}\n","import { DeconstructedSnowflake, Snowflake, SnowflakeGenerateOptions } from './Snowflake';\n\n/**\n * A class for parsing snowflake ids using Discord's snowflake epoch\n *\n * Which is 2015-01-01 at 00:00:00.000 UTC+0, {@linkplain https://discord.com/developers/docs/reference#snowflakes}\n */\nexport class DiscordSnowflake extends Snowflake {\n\tpublic constructor() {\n\t\tsuper(DiscordSnowflake.Epoch);\n\t}\n\n\t/**\n\t * Discord epoch (`2015-01-01T00:00:00.000Z`)\n\t * @see {@linkplain https://discord.com/developers/docs/reference#snowflakes}\n\t */\n\tpublic static readonly Epoch = 1420070400000n;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```ts\n\t * const snowflake = DiscordSnowflake.decode('3971046231244935168');\n\t * ```\n\t */\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tpublic static decode = DiscordSnowflake.deconstruct;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```ts\n\t * const snowflake = DiscordSnowflake.deconstruct('3971046231244935168');\n\t * ```\n\t */\n\tpublic static deconstruct(id: string | bigint): DeconstructedSnowflake {\n\t\treturn new DiscordSnowflake().deconstruct(id);\n\t}\n\n\t/**\n\t * Generates a snowflake given an epoch and optionally a timestamp\n\t * @param options {@link SnowflakeGenerateOptions} to pass into the generator\n\t *\n\t * **note** when increment is not provided it defaults to `0n`\n\t * @example\n\t * ```ts\n\t * const snowflake = DiscordSnowflake.generate();\n\t * ```\n\t * @returns A unique snowflake\n\t */\n\tpublic static generate(options: SnowflakeGenerateOptions = { timestamp: Date.now() }) {\n\t\treturn new DiscordSnowflake().generate(options);\n\t}\n}\n","import { DeconstructedSnowflake, Snowflake, SnowflakeGenerateOptions } from './Snowflake';\n\n/**\n * A class for parsing snowflake ids using Twitter's snowflake epoch\n *\n * Which is 2006-03-21 at 20:50:14.000 UTC+0, the time and date of the first tweet ever made {@linkplain https://twitter.com/jack/status/20}\n */\nexport class TwitterSnowflake extends Snowflake {\n\tpublic constructor() {\n\t\tsuper(TwitterSnowflake.Epoch);\n\t}\n\n\t/**\n\t * Twitter epoch (`2006-03-21T20:50:14.000Z`)\n\t * @see {@linkplain https://twitter.com/jack/status/20}, first tweet ever made\n\t */\n\tpublic static readonly Epoch = 1142974214000n;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```ts\n\t * const snowflake = TwitterSnowflake.decode('3971046231244935168');\n\t * ```\n\t */\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tpublic static decode = TwitterSnowflake.deconstruct;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```ts\n\t * const snowflake = TwitterSnowflake.deconstruct('3971046231244935168');\n\t * ```\n\t */\n\tpublic static deconstruct(id: string | bigint): DeconstructedSnowflake {\n\t\treturn new TwitterSnowflake().deconstruct(id);\n\t}\n\n\t/**\n\t * Generates a snowflake given an epoch and optionally a timestamp\n\t * @param options options to pass into the generator, see {@link SnowflakeGenerateOptions}\n\t *\n\t * **note** when increment is not provided it defaults to `0n`\n\t * @example\n\t * ```ts\n\t * const snowflake = TwitterSnowflake.generate();\n\t * ```\n\t * @returns A unique snowflake\n\t */\n\tpublic static generate(options: SnowflakeGenerateOptions = { timestamp: Date.now() }) {\n\t\treturn new TwitterSnowflake().generate(options);\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAEA;;;MAGa,SAAS;;;;IAsBrB,YAAmB,KAA6B;;;;;QAjBhD,+BAAa,EAAE,EAAC;;;;;QAMhB,mCAAe;;;;;QAMf;;;;mBAAgB,IAAI,CAAC,WAAW;WAAC;QAMhC,uBAAA,IAAI,oBAAU,MAAM,CAAC,KAAK,YAAY,IAAI,GAAG,KAAK,CAAC,OAAO,EAAE,GAAG,KAAK,EAAC,CAAC;KACtE;;;;;;;;;;;;;IAcM,QAAQ,CACd,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,QAAQ,GAAG,EAAE,EAAE,SAAS,GAAG,EAAE,KAA+B;QAChG,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,QAAQ,EAAE,EAAE;QACZ,SAAS,EAAE,EAAE;KACb;;QAED,IAAI,SAAS,YAAY,IAAI;YAAE,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC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CAAC;KAC9B;;;;;;;;;;IA6BM,OAAO,WAAW,CAAC,EAAmB;QAC5C,OAAO,IAAI,gBAAgB,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;KAC9C;;;;;;;;;;;;IAaM,OAAO,QAAQ,CAAC,UAAoC,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE;QACnF,OAAO,IAAI,gBAAgB,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;KAChD;;AA5CD;;;;AAIA;;;;WAA+B,cAAc;GAAC;AAE9C;;;;;;;;;AASA;AACA;;;;WAAuB,gBAAgB,CAAC,WAAW;;;AC1BpD;;;;;MAKa,gBAAiB,SAAQ,SAAS;IAC9C;QACC,KAAK,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;KAC9B;;;;;;;;;;IA6BM,OAAO,WAAW,CAAC,EAAmB;QAC5C,OAAO,IAAI,gBAAgB,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;KAC9C;;;;;;;;;;;;IAaM,OAAO,QAAQ,CAAC,UAAoC,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE;QACnF,OAAO,IAAI,gBAAgB,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;KAChD;;AA5CD;;;;AAIA;;;;WAA+B,cAAc;GAAC;AAE9C;;;;;;;;;AASA;AACA;;;;WAAuB,gBAAgB,CAAC,WAAW;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/lib/Snowflake.ts","../src/lib/DiscordSnowflake.ts","../src/lib/TwitterSnowflake.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/explicit-member-accessibility */\n\n/**\n * A class for parsing snowflake ids\n */\nexport class Snowflake {\n\t/**\n\t * Internal incrementor for generating snowflakes\n\t * @internal\n\t */\n\t#increment = 0n;\n\n\t/**\n\t * Internal reference of the epoch passed in the constructor\n\t * @internal\n\t */\n\t#epoch: bigint;\n\n\t/**\n\t * Alias for {@link deconstruct}\n\t */\n\t// eslint-disable-next-line @typescript-eslint/unbound-method, @typescript-eslint/no-invalid-this\n\tpublic decode = this.deconstruct;\n\n\t/**\n\t * @param epoch the epoch to use\n\t */\n\tpublic constructor(epoch: number | bigint | Date) {\n\t\tthis.#epoch = BigInt(epoch instanceof Date ? epoch.getTime() : epoch);\n\t}\n\n\t/**\n\t * Generates a snowflake given an epoch and optionally a timestamp\n\t * @param options options to pass into the generator, see {@link SnowflakeGenerateOptions}\n\t *\n\t * **note** when increment is not provided it defaults to the private increment of the instance\n\t * @example\n\t * ```typescript\n\t * const epoch = new Date('2000-01-01T00:00:00.000Z');\n\t * const snowflake = new Snowflake(epoch).generate();\n\t * ```\n\t * @returns A unique snowflake\n\t */\n\tpublic generate(\n\t\t{ increment, timestamp = Date.now(), workerID = 1n, processID = 1n }: SnowflakeGenerateOptions = {\n\t\t\ttimestamp: Date.now(),\n\t\t\tworkerID: 1n,\n\t\t\tprocessID: 1n\n\t\t}\n\t) {\n\t\tif (timestamp instanceof Date) timestamp = BigInt(timestamp.getTime());\n\t\tif (typeof timestamp === 'number' && !Number.isNaN(timestamp)) timestamp = BigInt(timestamp);\n\n\t\tif (typeof timestamp !== 'bigint') {\n\t\t\tthrow new TypeError(\n\t\t\t\t`\"timestamp\" argument must be a number, BigInt or Date (received ${Number.isNaN(timestamp) ? 'NaN' : typeof timestamp})`\n\t\t\t);\n\t\t}\n\n\t\tif (increment !== undefined && increment >= 4095n) increment = 0n;\n\t\tif (this.#increment >= 4095n) this.#increment = 0n;\n\n\t\t// timestamp, workerID, processID, increment\n\t\treturn (\n\t\t\t((timestamp - this.#epoch) << 22n) | (workerID << 17n) | (processID << 12n) | (increment === undefined ? this.#increment++ : increment++)\n\t\t);\n\t}\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```typescript\n\t * const epoch = new Date('2000-01-01T00:00:00.000Z');\n\t * const snowflake = new Snowflake(epoch).deconstruct('3971046231244935168');\n\t * ```\n\t */\n\tpublic deconstruct(id: string | bigint): DeconstructedSnowflake {\n\t\tconst bigIntId = BigInt(id);\n\t\treturn {\n\t\t\tid: bigIntId,\n\t\t\ttimestamp: (bigIntId >> 22n) + this.#epoch,\n\t\t\tworkerID: (bigIntId >> 17n) & 0b11111n,\n\t\t\tprocessID: (bigIntId >> 12n) & 0b11111n,\n\t\t\tincrement: bigIntId & 0b111111111111n,\n\t\t\tepoch: this.#epoch\n\t\t};\n\t}\n}\n\n/**\n * Options for Snowflake#generate\n */\nexport interface SnowflakeGenerateOptions {\n\t/**\n\t * Timestamp or date of the snowflake to generate\n\t * @default Date.now()\n\t */\n\ttimestamp?: number | bigint | Date;\n\n\t/**\n\t * The increment to use\n\t * @default 0n\n\t * @remark keep in mind that this bigint is auto-incremented between generate calls\n\t */\n\tincrement?: bigint;\n\n\t/**\n\t * The worker ID to use\n\t * @default 1n\n\t */\n\tworkerID?: bigint;\n\n\t/**\n\t * The process ID to use\n\t * @default 1n\n\t */\n\tprocessID?: bigint;\n}\n\n/**\n * Object returned by Snowflake#deconstruct\n */\nexport interface DeconstructedSnowflake {\n\t/**\n\t * The id in BigInt form\n\t */\n\tid: bigint;\n\n\t/**\n\t * The timestamp stored in the snowflake\n\t */\n\ttimestamp: bigint;\n\n\t/**\n\t * The worker id stored in the snowflake\n\t */\n\tworkerID: bigint;\n\n\t/**\n\t * The process id stored in the snowflake\n\t */\n\tprocessID: bigint;\n\n\t/**\n\t * The increment stored in the snowflake\n\t */\n\tincrement: bigint;\n\n\t/**\n\t * The epoch to use in the snowflake\n\t */\n\tepoch: bigint;\n}\n","import { DeconstructedSnowflake, Snowflake, SnowflakeGenerateOptions } from './Snowflake';\n\n/**\n * A class for parsing snowflake ids using Discord's snowflake epoch\n *\n * Which is 2015-01-01 at 00:00:00.000 UTC+0, {@linkplain https://discord.com/developers/docs/reference#snowflakes}\n */\nexport class DiscordSnowflake extends Snowflake {\n\tpublic constructor() {\n\t\tsuper(DiscordSnowflake.Epoch);\n\t}\n\n\t/**\n\t * Discord epoch (`2015-01-01T00:00:00.000Z`)\n\t * @see {@linkplain https://discord.com/developers/docs/reference#snowflakes}\n\t */\n\tpublic static readonly Epoch = 1420070400000n;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```typescript\n\t * const snowflake = DiscordSnowflake.decode('3971046231244935168');\n\t * ```\n\t */\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tpublic static decode = DiscordSnowflake.deconstruct;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```typescript\n\t * const snowflake = DiscordSnowflake.deconstruct('3971046231244935168');\n\t * ```\n\t */\n\tpublic static deconstruct(id: string | bigint): DeconstructedSnowflake {\n\t\treturn new DiscordSnowflake().deconstruct(id);\n\t}\n\n\t/**\n\t * Generates a snowflake given an epoch and optionally a timestamp\n\t * @param options {@link SnowflakeGenerateOptions} to pass into the generator\n\t *\n\t * **note** when increment is not provided it defaults to `0n`\n\t * @example\n\t * ```typescript\n\t * const snowflake = DiscordSnowflake.generate();\n\t * ```\n\t * @returns A unique snowflake\n\t */\n\tpublic static generate(options: SnowflakeGenerateOptions = { timestamp: Date.now() }) {\n\t\treturn new DiscordSnowflake().generate(options);\n\t}\n}\n","import { DeconstructedSnowflake, Snowflake, SnowflakeGenerateOptions } from './Snowflake';\n\n/**\n * A class for parsing snowflake ids using Twitter's snowflake epoch\n *\n * Which is 2006-03-21 at 20:50:14.000 UTC+0, the time and date of the first tweet ever made {@linkplain https://twitter.com/jack/status/20}\n */\nexport class TwitterSnowflake extends Snowflake {\n\tpublic constructor() {\n\t\tsuper(TwitterSnowflake.Epoch);\n\t}\n\n\t/**\n\t * Twitter epoch (`2006-03-21T20:50:14.000Z`)\n\t * @see {@linkplain https://twitter.com/jack/status/20}, first tweet ever made\n\t */\n\tpublic static readonly Epoch = 1142974214000n;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```typescript\n\t * const snowflake = TwitterSnowflake.decode('3971046231244935168');\n\t * ```\n\t */\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tpublic static decode = TwitterSnowflake.deconstruct;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```typescript\n\t * const snowflake = TwitterSnowflake.deconstruct('3971046231244935168');\n\t * ```\n\t */\n\tpublic static deconstruct(id: string | bigint): DeconstructedSnowflake {\n\t\treturn new TwitterSnowflake().deconstruct(id);\n\t}\n\n\t/**\n\t * Generates a snowflake given an epoch and optionally a timestamp\n\t * @param options options to pass into the generator, see {@link SnowflakeGenerateOptions}\n\t *\n\t * **note** when increment is not provided it defaults to `0n`\n\t * @example\n\t * ```typescript\n\t * const snowflake = TwitterSnowflake.generate();\n\t * ```\n\t * @returns A unique snowflake\n\t */\n\tpublic static generate(options: SnowflakeGenerateOptions = { timestamp: Date.now() }) {\n\t\treturn new TwitterSnowflake().generate(options);\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAEA;;;MAGa,SAAS;;;;IAsBrB,YAAmB,KAA6B;;;;;QAjBhD,+BAAa,EAAE,EAAC;;;;;QAMhB,mCAAe;;;;;QAMf;;;;mBAAgB,IAAI,CAAC,WAAW;WAAC;QAMhC,uBAAA,IAAI,oBAAU,MAAM,CAAC,KAAK,YAAY,IAAI,GAAG,KAAK,CAAC,OAAO,EAAE,GAAG,KAAK,EAAC,CAAC;KACtE;;;;;;;;;;;;;IAcM,QAAQ,CACd,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC,GA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private increment of the instance
74
74
  * @example
75
- * ```ts
75
+ * ```typescript
76
76
  * const epoch = new Date('2000-01-01T00:00:00.000Z');
77
77
  * const snowflake = new Snowflake(epoch).generate();
78
78
  * ```
@@ -103,7 +103,7 @@
103
103
  * @param id the snowflake to deconstruct
104
104
  * @returns a deconstructed snowflake
105
105
  * @example
106
- * ```ts
106
+ * ```typescript
107
107
  * const epoch = new Date('2000-01-01T00:00:00.000Z');
108
108
  * const snowflake = new Snowflake(epoch).deconstruct('3971046231244935168');
109
109
  * ```
@@ -136,7 +136,7 @@
136
136
  * @param id the snowflake to deconstruct
137
137
  * @returns a deconstructed snowflake
138
138
  * @example
139
- * ```ts
139
+ * ```typescript
140
140
  * const snowflake = DiscordSnowflake.deconstruct('3971046231244935168');
141
141
  * ```
142
142
  */
@@ -149,7 +149,7 @@
149
149
  *
150
150
  * **note** when increment is not provided it defaults to `0n`
151
151
  * @example
152
- * ```ts
152
+ * ```typescript
153
153
  * const snowflake = DiscordSnowflake.generate();
154
154
  * ```
155
155
  * @returns A unique snowflake
@@ -173,7 +173,7 @@
173
173
  * @param id the snowflake to deconstruct
174
174
  * @returns a deconstructed snowflake
175
175
  * @example
176
- * ```ts
176
+ * ```typescript
177
177
  * const snowflake = DiscordSnowflake.decode('3971046231244935168');
178
178
  * ```
179
179
  */
@@ -199,7 +199,7 @@
199
199
  * @param id the snowflake to deconstruct
200
200
  * @returns a deconstructed snowflake
201
201
  * @example
202
- * ```ts
202
+ * ```typescript
203
203
  * const snowflake = TwitterSnowflake.deconstruct('3971046231244935168');
204
204
  * ```
205
205
  */
@@ -212,7 +212,7 @@
212
212
  *
213
213
  * **note** when increment is not provided it defaults to `0n`
214
214
  * @example
215
- * ```ts
215
+ * ```typescript
216
216
  * const snowflake = TwitterSnowflake.generate();
217
217
  * ```
218
218
  * @returns A unique snowflake
@@ -236,7 +236,7 @@
236
236
  * @param id the snowflake to deconstruct
237
237
  * @returns a deconstructed snowflake
238
238
  * @example
239
- * ```ts
239
+ * ```typescript
240
240
  * const snowflake = TwitterSnowflake.decode('3971046231244935168');
241
241
  * ```
242
242
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/lib/Snowflake.ts","../src/lib/DiscordSnowflake.ts","../src/lib/TwitterSnowflake.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/explicit-member-accessibility */\n\n/**\n * A class for parsing snowflake ids\n */\nexport class Snowflake {\n\t/**\n\t * Internal incrementor for generating snowflakes\n\t * @internal\n\t */\n\t#increment = 0n;\n\n\t/**\n\t * Internal reference of the epoch passed in the constructor\n\t * @internal\n\t */\n\t#epoch: bigint;\n\n\t/**\n\t * Alias for {@link deconstruct}\n\t */\n\t// eslint-disable-next-line @typescript-eslint/unbound-method, @typescript-eslint/no-invalid-this\n\tpublic decode = this.deconstruct;\n\n\t/**\n\t * @param epoch the epoch to use\n\t */\n\tpublic constructor(epoch: number | bigint | Date) {\n\t\tthis.#epoch = BigInt(epoch instanceof Date ? epoch.getTime() : epoch);\n\t}\n\n\t/**\n\t * Generates a snowflake given an epoch and optionally a timestamp\n\t * @param options options to pass into the generator, see {@link SnowflakeGenerateOptions}\n\t *\n\t * **note** when increment is not provided it defaults to the private increment of the instance\n\t * @example\n\t * ```ts\n\t * const epoch = new Date('2000-01-01T00:00:00.000Z');\n\t * const snowflake = new Snowflake(epoch).generate();\n\t * ```\n\t * @returns A unique snowflake\n\t */\n\tpublic generate(\n\t\t{ increment, timestamp = Date.now(), workerID = 1n, processID = 1n }: SnowflakeGenerateOptions = {\n\t\t\ttimestamp: Date.now(),\n\t\t\tworkerID: 1n,\n\t\t\tprocessID: 1n\n\t\t}\n\t) {\n\t\tif (timestamp instanceof Date) timestamp = BigInt(timestamp.getTime());\n\t\tif (typeof timestamp === 'number' && !Number.isNaN(timestamp)) timestamp = BigInt(timestamp);\n\n\t\tif (typeof timestamp !== 'bigint') {\n\t\t\tthrow new TypeError(\n\t\t\t\t`\"timestamp\" argument must be a number, BigInt or Date (received ${Number.isNaN(timestamp) ? 'NaN' : typeof timestamp})`\n\t\t\t);\n\t\t}\n\n\t\tif (increment !== undefined && increment >= 4095n) increment = 0n;\n\t\tif (this.#increment >= 4095n) this.#increment = 0n;\n\n\t\t// timestamp, workerID, processID, increment\n\t\treturn (\n\t\t\t((timestamp - this.#epoch) << 22n) | (workerID << 17n) | (processID << 12n) | (increment === undefined ? this.#increment++ : increment++)\n\t\t);\n\t}\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```ts\n\t * const epoch = new Date('2000-01-01T00:00:00.000Z');\n\t * const snowflake = new Snowflake(epoch).deconstruct('3971046231244935168');\n\t * ```\n\t */\n\tpublic deconstruct(id: string | bigint): DeconstructedSnowflake {\n\t\tconst bigIntId = BigInt(id);\n\t\treturn {\n\t\t\tid: bigIntId,\n\t\t\ttimestamp: (bigIntId >> 22n) + this.#epoch,\n\t\t\tworkerID: (bigIntId >> 17n) & 0b11111n,\n\t\t\tprocessID: (bigIntId >> 12n) & 0b11111n,\n\t\t\tincrement: bigIntId & 0b111111111111n,\n\t\t\tepoch: this.#epoch\n\t\t};\n\t}\n}\n\n/**\n * Options for Snowflake#generate\n */\nexport interface SnowflakeGenerateOptions {\n\t/**\n\t * Timestamp or date of the snowflake to generate\n\t * @default Date.now()\n\t */\n\ttimestamp?: number | bigint | Date;\n\n\t/**\n\t * The increment to use\n\t * @default 0n\n\t * @remark keep in mind that this bigint is auto-incremented between generate calls\n\t */\n\tincrement?: bigint;\n\n\t/**\n\t * The worker ID to use\n\t * @default 1n\n\t */\n\tworkerID?: bigint;\n\n\t/**\n\t * The process ID to use\n\t * @default 1n\n\t */\n\tprocessID?: bigint;\n}\n\n/**\n * Object returned by Snowflake#deconstruct\n */\nexport interface DeconstructedSnowflake {\n\t/**\n\t * The id in BigInt form\n\t */\n\tid: bigint;\n\n\t/**\n\t * The timestamp stored in the snowflake\n\t */\n\ttimestamp: bigint;\n\n\t/**\n\t * The worker id stored in the snowflake\n\t */\n\tworkerID: bigint;\n\n\t/**\n\t * The process id stored in the snowflake\n\t */\n\tprocessID: bigint;\n\n\t/**\n\t * The increment stored in the snowflake\n\t */\n\tincrement: bigint;\n\n\t/**\n\t * The epoch to use in the snowflake\n\t */\n\tepoch: bigint;\n}\n","import { DeconstructedSnowflake, Snowflake, SnowflakeGenerateOptions } from './Snowflake';\n\n/**\n * A class for parsing snowflake ids using Discord's snowflake epoch\n *\n * Which is 2015-01-01 at 00:00:00.000 UTC+0, {@linkplain https://discord.com/developers/docs/reference#snowflakes}\n */\nexport class DiscordSnowflake extends Snowflake {\n\tpublic constructor() {\n\t\tsuper(DiscordSnowflake.Epoch);\n\t}\n\n\t/**\n\t * Discord epoch (`2015-01-01T00:00:00.000Z`)\n\t * @see {@linkplain https://discord.com/developers/docs/reference#snowflakes}\n\t */\n\tpublic static readonly Epoch = 1420070400000n;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```ts\n\t * const snowflake = DiscordSnowflake.decode('3971046231244935168');\n\t * ```\n\t */\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tpublic static decode = DiscordSnowflake.deconstruct;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```ts\n\t * const snowflake = DiscordSnowflake.deconstruct('3971046231244935168');\n\t * ```\n\t */\n\tpublic static deconstruct(id: string | bigint): DeconstructedSnowflake {\n\t\treturn new DiscordSnowflake().deconstruct(id);\n\t}\n\n\t/**\n\t * Generates a snowflake given an epoch and optionally a timestamp\n\t * @param options {@link SnowflakeGenerateOptions} to pass into the generator\n\t *\n\t * **note** when increment is not provided it defaults to `0n`\n\t * @example\n\t * ```ts\n\t * const snowflake = DiscordSnowflake.generate();\n\t * ```\n\t * @returns A unique snowflake\n\t */\n\tpublic static generate(options: SnowflakeGenerateOptions = { timestamp: Date.now() }) {\n\t\treturn new DiscordSnowflake().generate(options);\n\t}\n}\n","import { DeconstructedSnowflake, Snowflake, SnowflakeGenerateOptions } from './Snowflake';\n\n/**\n * A class for parsing snowflake ids using Twitter's snowflake epoch\n *\n * Which is 2006-03-21 at 20:50:14.000 UTC+0, the time and date of the first tweet ever made {@linkplain https://twitter.com/jack/status/20}\n */\nexport class TwitterSnowflake extends Snowflake {\n\tpublic constructor() {\n\t\tsuper(TwitterSnowflake.Epoch);\n\t}\n\n\t/**\n\t * Twitter epoch (`2006-03-21T20:50:14.000Z`)\n\t * @see {@linkplain https://twitter.com/jack/status/20}, first tweet ever made\n\t */\n\tpublic static readonly Epoch = 1142974214000n;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```ts\n\t * const snowflake = TwitterSnowflake.decode('3971046231244935168');\n\t * ```\n\t */\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tpublic static decode = TwitterSnowflake.deconstruct;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```ts\n\t * const snowflake = TwitterSnowflake.deconstruct('3971046231244935168');\n\t * ```\n\t */\n\tpublic static deconstruct(id: string | bigint): DeconstructedSnowflake {\n\t\treturn new TwitterSnowflake().deconstruct(id);\n\t}\n\n\t/**\n\t * Generates a snowflake given an epoch and optionally a timestamp\n\t * @param options options to pass into the generator, see {@link SnowflakeGenerateOptions}\n\t *\n\t * **note** when increment is not provided it defaults to `0n`\n\t * @example\n\t * ```ts\n\t * const snowflake = TwitterSnowflake.generate();\n\t * ```\n\t * @returns A unique snowflake\n\t */\n\tpublic static generate(options: SnowflakeGenerateOptions = { timestamp: Date.now() }) {\n\t\treturn new TwitterSnowflake().generate(options);\n\t}\n}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OAAO,IAAI,gBAAgB,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;SAC9C;;;;;;;;;;;;QAaM,OAAO,QAAQ,CAAC,UAAoC,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE;YACnF,OAAO,IAAI,gBAAgB,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;SAChD;;IA5CD;;;;IAIA;;;;eAA+B,cAAc;OAAC;IAE9C;;;;;;;;;IASA;IACA;;;;eAAuB,gBAAgB,CAAC,WAAW;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.umd.js","sources":["../src/lib/Snowflake.ts","../src/lib/DiscordSnowflake.ts","../src/lib/TwitterSnowflake.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/explicit-member-accessibility */\n\n/**\n * A class for parsing snowflake ids\n */\nexport class Snowflake {\n\t/**\n\t * Internal incrementor for generating snowflakes\n\t * @internal\n\t */\n\t#increment = 0n;\n\n\t/**\n\t * Internal reference of the epoch passed in the constructor\n\t * @internal\n\t */\n\t#epoch: bigint;\n\n\t/**\n\t * Alias for {@link deconstruct}\n\t */\n\t// eslint-disable-next-line @typescript-eslint/unbound-method, @typescript-eslint/no-invalid-this\n\tpublic decode = this.deconstruct;\n\n\t/**\n\t * @param epoch the epoch to use\n\t */\n\tpublic constructor(epoch: number | bigint | Date) {\n\t\tthis.#epoch = BigInt(epoch instanceof Date ? epoch.getTime() : epoch);\n\t}\n\n\t/**\n\t * Generates a snowflake given an epoch and optionally a timestamp\n\t * @param options options to pass into the generator, see {@link SnowflakeGenerateOptions}\n\t *\n\t * **note** when increment is not provided it defaults to the private increment of the instance\n\t * @example\n\t * ```typescript\n\t * const epoch = new Date('2000-01-01T00:00:00.000Z');\n\t * const snowflake = new Snowflake(epoch).generate();\n\t * ```\n\t * @returns A unique snowflake\n\t */\n\tpublic generate(\n\t\t{ increment, timestamp = Date.now(), workerID = 1n, processID = 1n }: SnowflakeGenerateOptions = {\n\t\t\ttimestamp: Date.now(),\n\t\t\tworkerID: 1n,\n\t\t\tprocessID: 1n\n\t\t}\n\t) {\n\t\tif (timestamp instanceof Date) timestamp = BigInt(timestamp.getTime());\n\t\tif (typeof timestamp === 'number' && !Number.isNaN(timestamp)) timestamp = BigInt(timestamp);\n\n\t\tif (typeof timestamp !== 'bigint') {\n\t\t\tthrow new TypeError(\n\t\t\t\t`\"timestamp\" argument must be a number, BigInt or Date (received ${Number.isNaN(timestamp) ? 'NaN' : typeof timestamp})`\n\t\t\t);\n\t\t}\n\n\t\tif (increment !== undefined && increment >= 4095n) increment = 0n;\n\t\tif (this.#increment >= 4095n) this.#increment = 0n;\n\n\t\t// timestamp, workerID, processID, increment\n\t\treturn (\n\t\t\t((timestamp - this.#epoch) << 22n) | (workerID << 17n) | (processID << 12n) | (increment === undefined ? this.#increment++ : increment++)\n\t\t);\n\t}\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```typescript\n\t * const epoch = new Date('2000-01-01T00:00:00.000Z');\n\t * const snowflake = new Snowflake(epoch).deconstruct('3971046231244935168');\n\t * ```\n\t */\n\tpublic deconstruct(id: string | bigint): DeconstructedSnowflake {\n\t\tconst bigIntId = BigInt(id);\n\t\treturn {\n\t\t\tid: bigIntId,\n\t\t\ttimestamp: (bigIntId >> 22n) + this.#epoch,\n\t\t\tworkerID: (bigIntId >> 17n) & 0b11111n,\n\t\t\tprocessID: (bigIntId >> 12n) & 0b11111n,\n\t\t\tincrement: bigIntId & 0b111111111111n,\n\t\t\tepoch: this.#epoch\n\t\t};\n\t}\n}\n\n/**\n * Options for Snowflake#generate\n */\nexport interface SnowflakeGenerateOptions {\n\t/**\n\t * Timestamp or date of the snowflake to generate\n\t * @default Date.now()\n\t */\n\ttimestamp?: number | bigint | Date;\n\n\t/**\n\t * The increment to use\n\t * @default 0n\n\t * @remark keep in mind that this bigint is auto-incremented between generate calls\n\t */\n\tincrement?: bigint;\n\n\t/**\n\t * The worker ID to use\n\t * @default 1n\n\t */\n\tworkerID?: bigint;\n\n\t/**\n\t * The process ID to use\n\t * @default 1n\n\t */\n\tprocessID?: bigint;\n}\n\n/**\n * Object returned by Snowflake#deconstruct\n */\nexport interface DeconstructedSnowflake {\n\t/**\n\t * The id in BigInt form\n\t */\n\tid: bigint;\n\n\t/**\n\t * The timestamp stored in the snowflake\n\t */\n\ttimestamp: bigint;\n\n\t/**\n\t * The worker id stored in the snowflake\n\t */\n\tworkerID: bigint;\n\n\t/**\n\t * The process id stored in the snowflake\n\t */\n\tprocessID: bigint;\n\n\t/**\n\t * The increment stored in the snowflake\n\t */\n\tincrement: bigint;\n\n\t/**\n\t * The epoch to use in the snowflake\n\t */\n\tepoch: bigint;\n}\n","import { DeconstructedSnowflake, Snowflake, SnowflakeGenerateOptions } from './Snowflake';\n\n/**\n * A class for parsing snowflake ids using Discord's snowflake epoch\n *\n * Which is 2015-01-01 at 00:00:00.000 UTC+0, {@linkplain https://discord.com/developers/docs/reference#snowflakes}\n */\nexport class DiscordSnowflake extends Snowflake {\n\tpublic constructor() {\n\t\tsuper(DiscordSnowflake.Epoch);\n\t}\n\n\t/**\n\t * Discord epoch (`2015-01-01T00:00:00.000Z`)\n\t * @see {@linkplain https://discord.com/developers/docs/reference#snowflakes}\n\t */\n\tpublic static readonly Epoch = 1420070400000n;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```typescript\n\t * const snowflake = DiscordSnowflake.decode('3971046231244935168');\n\t * ```\n\t */\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tpublic static decode = DiscordSnowflake.deconstruct;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```typescript\n\t * const snowflake = DiscordSnowflake.deconstruct('3971046231244935168');\n\t * ```\n\t */\n\tpublic static deconstruct(id: string | bigint): DeconstructedSnowflake {\n\t\treturn new DiscordSnowflake().deconstruct(id);\n\t}\n\n\t/**\n\t * Generates a snowflake given an epoch and optionally a timestamp\n\t * @param options {@link SnowflakeGenerateOptions} to pass into the generator\n\t *\n\t * **note** when increment is not provided it defaults to `0n`\n\t * @example\n\t * ```typescript\n\t * const snowflake = DiscordSnowflake.generate();\n\t * ```\n\t * @returns A unique snowflake\n\t */\n\tpublic static generate(options: SnowflakeGenerateOptions = { timestamp: Date.now() }) {\n\t\treturn new DiscordSnowflake().generate(options);\n\t}\n}\n","import { DeconstructedSnowflake, Snowflake, SnowflakeGenerateOptions } from './Snowflake';\n\n/**\n * A class for parsing snowflake ids using Twitter's snowflake epoch\n *\n * Which is 2006-03-21 at 20:50:14.000 UTC+0, the time and date of the first tweet ever made {@linkplain https://twitter.com/jack/status/20}\n */\nexport class TwitterSnowflake extends Snowflake {\n\tpublic constructor() {\n\t\tsuper(TwitterSnowflake.Epoch);\n\t}\n\n\t/**\n\t * Twitter epoch (`2006-03-21T20:50:14.000Z`)\n\t * @see {@linkplain https://twitter.com/jack/status/20}, first tweet ever made\n\t */\n\tpublic static readonly Epoch = 1142974214000n;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```typescript\n\t * const snowflake = TwitterSnowflake.decode('3971046231244935168');\n\t * ```\n\t */\n\t// eslint-disable-next-line @typescript-eslint/unbound-method\n\tpublic static decode = TwitterSnowflake.deconstruct;\n\n\t/**\n\t * Deconstructs a snowflake given a snowflake ID\n\t * @param id the snowflake to deconstruct\n\t * @returns a deconstructed snowflake\n\t * @example\n\t * ```typescript\n\t * const snowflake = TwitterSnowflake.deconstruct('3971046231244935168');\n\t * ```\n\t */\n\tpublic static deconstruct(id: string | bigint): DeconstructedSnowflake {\n\t\treturn new TwitterSnowflake().deconstruct(id);\n\t}\n\n\t/**\n\t * Generates a snowflake given an epoch and optionally a timestamp\n\t * @param options options to pass into the generator, see {@link SnowflakeGenerateOptions}\n\t *\n\t * **note** when increment is not provided it defaults to `0n`\n\t * @example\n\t * ```typescript\n\t * const snowflake = TwitterSnowflake.generate();\n\t * ```\n\t * @returns A unique snowflake\n\t */\n\tpublic static generate(options: SnowflakeGenerateOptions = { timestamp: Date.now() }) {\n\t\treturn new TwitterSnowflake().generate(options);\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAA;;IAEA;;;UAGa,SAAS;;;;QAsBrB,YAAmB,KAA6B;;;;;YAjBhD,+BAAa,EAAE,EAAC;;;;;YAMhB,mCAAe;;;;;YAMf;;;;uBAAgB,IAAI,CAAC,WAAW;eAAC;YAMhC,uBAAA,IAAI,oBAAU,MAAM,CAAC,KAAK,YAAY,IAAI,GAAG,KAAK,CAAC,OAAO,EAAE,GAAG,KAAK,EAAC,CAAC;SACtE;;;;;;;;;;;;;QAcM,QAAQ,CACd,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,QAAQ,GAAG,EAAE,EAAE,SAAS,GAAG,EAAE,KAA+B;YAChG,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,QAAQ,EAAE,EAAE;YACZ,SAAS,EAAE,EAAE;SACb;;YAED,IAAI,SAAS,YAAY,IAAI;gBAAE,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;YACvE,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC;gBAAE,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;YAE7F,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;gBAClC,MAAM,IAAI,SAAS,CAClB,mEAAmE,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,KAAK,GAAG,OAAO,SA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C,OAAO,CAAC,CAAC;SAChD;;IA5CD;;;;IAIA;;;;eAA+B,cAAc;OAAC;IAE9C;;;;;;;;;IASA;IACA;;;;eAAuB,gBAAgB,CAAC,WAAW;;;IC1BpD;;;;;UAKa,gBAAiB,SAAQ,SAAS;QAC9C;YACC,KAAK,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;SAC9B;;;;;;;;;;QA6BM,OAAO,WAAW,CAAC,EAAmB;YAC5C,OAAO,IAAI,gBAAgB,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;SAC9C;;;;;;;;;;;;QAaM,OAAO,QAAQ,CAAC,UAAoC,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE;YACnF,OAAO,IAAI,gBAAgB,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;SAChD;;IA5CD;;;;IAIA;;;;eAA+B,cAAc;OAAC;IAE9C;;;;;;;;;IASA;IACA;;;;eAAuB,gBAAgB,CAAC,WAAW;;;;;;;;;;;;;"}
@@ -16,7 +16,7 @@ export declare class DiscordSnowflake extends Snowflake {
16
16
  * @param id the snowflake to deconstruct
17
17
  * @returns a deconstructed snowflake
18
18
  * @example
19
- * ```ts
19
+ * ```typescript
20
20
  * const snowflake = DiscordSnowflake.decode('3971046231244935168');
21
21
  * ```
22
22
  */
@@ -26,7 +26,7 @@ export declare class DiscordSnowflake extends Snowflake {
26
26
  * @param id the snowflake to deconstruct
27
27
  * @returns a deconstructed snowflake
28
28
  * @example
29
- * ```ts
29
+ * ```typescript
30
30
  * const snowflake = DiscordSnowflake.deconstruct('3971046231244935168');
31
31
  * ```
32
32
  */
@@ -37,7 +37,7 @@ export declare class DiscordSnowflake extends Snowflake {
37
37
  *
38
38
  * **note** when increment is not provided it defaults to `0n`
39
39
  * @example
40
- * ```ts
40
+ * ```typescript
41
41
  * const snowflake = DiscordSnowflake.generate();
42
42
  * ```
43
43
  * @returns A unique snowflake
@@ -17,7 +17,7 @@ export declare class Snowflake {
17
17
  *
18
18
  * **note** when increment is not provided it defaults to the private increment of the instance
19
19
  * @example
20
- * ```ts
20
+ * ```typescript
21
21
  * const epoch = new Date('2000-01-01T00:00:00.000Z');
22
22
  * const snowflake = new Snowflake(epoch).generate();
23
23
  * ```
@@ -29,7 +29,7 @@ export declare class Snowflake {
29
29
  * @param id the snowflake to deconstruct
30
30
  * @returns a deconstructed snowflake
31
31
  * @example
32
- * ```ts
32
+ * ```typescript
33
33
  * const epoch = new Date('2000-01-01T00:00:00.000Z');
34
34
  * const snowflake = new Snowflake(epoch).deconstruct('3971046231244935168');
35
35
  * ```
@@ -16,7 +16,7 @@ export declare class TwitterSnowflake extends Snowflake {
16
16
  * @param id the snowflake to deconstruct
17
17
  * @returns a deconstructed snowflake
18
18
  * @example
19
- * ```ts
19
+ * ```typescript
20
20
  * const snowflake = TwitterSnowflake.decode('3971046231244935168');
21
21
  * ```
22
22
  */
@@ -26,7 +26,7 @@ export declare class TwitterSnowflake extends Snowflake {
26
26
  * @param id the snowflake to deconstruct
27
27
  * @returns a deconstructed snowflake
28
28
  * @example
29
- * ```ts
29
+ * ```typescript
30
30
  * const snowflake = TwitterSnowflake.deconstruct('3971046231244935168');
31
31
  * ```
32
32
  */
@@ -37,7 +37,7 @@ export declare class TwitterSnowflake extends Snowflake {
37
37
  *
38
38
  * **note** when increment is not provided it defaults to `0n`
39
39
  * @example
40
- * ```ts
40
+ * ```typescript
41
41
  * const snowflake = TwitterSnowflake.generate();
42
42
  * ```
43
43
  * @returns A unique snowflake
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sapphire/snowflake",
3
- "version": "2.1.2",
3
+ "version": "2.1.3-next.aeb3ee63.0",
4
4
  "description": "Deconstructs and generates snoflake IDs using BigInts",
5
5
  "author": "@sapphire",
6
6
  "license": "MIT",
@@ -52,5 +52,5 @@
52
52
  "publishConfig": {
53
53
  "access": "public"
54
54
  },
55
- "gitHead": "5fd5cce8a2a6bd88604c959f20176ef86f5fed6a"
55
+ "gitHead": "aeb3ee6309013652f9f1c0a6a87397de6586abf8"
56
56
  }