@sapphire/snowflake 2.1.0-pr-159.fae7a606.0 → 2.1.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
@@ -10,7 +10,6 @@
10
10
  [![codecov](https://codecov.io/gh/sapphiredev/utilities/branch/main/graph/badge.svg?token=OEGIV6RFDO)](https://codecov.io/gh/sapphiredev/utilities)
11
11
  [![npm bundle size](https://img.shields.io/bundlephobia/min/@sapphire/snowflake?logo=webpack&style=flat-square)](https://bundlephobia.com/result?p=@sapphire/snowflake)
12
12
  [![npm](https://img.shields.io/npm/v/@sapphire/snowflake?color=crimson&logo=npm&style=flat-square)](https://www.npmjs.com/package/@sapphire/snowflake)
13
- [![Depfu](https://badges.depfu.com/badges/ec42ff3d6bae55eee1de4749960852b3/count.svg)](https://depfu.com/github/sapphiredev/utilities?project_id=15195)
14
13
 
15
14
  </div>
16
15
 
@@ -196,17 +195,18 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
196
195
  <td align="center"><a href="https://github.com/Nytelife26"><img src="https://avatars1.githubusercontent.com/u/22531310?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tyler J Russell</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Nytelife26" title="Documentation">📖</a></td>
197
196
  <td align="center"><a href="https://github.com/Alcremie"><img src="https://avatars0.githubusercontent.com/u/54785334?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ivan Lieder</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Alcremie" title="Code">💻</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3AAlcremie" title="Bug reports">🐛</a></td>
198
197
  <td align="center"><a href="https://github.com/RealShadowNova"><img src="https://avatars3.githubusercontent.com/u/46537907?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Hezekiah Hendry</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=RealShadowNova" title="Code">💻</a></td>
199
- <td align="center"><a href="https://github.com/Stitch07"><img src="https://avatars.githubusercontent.com/u/29275227?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Stitch07</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Stitch07" title="Code">💻</a> <a href="https://github.com/sapphiredev/utilities/commits?author=Stitch07" title="Tests">⚠️</a></td>
200
198
  <td align="center"><a href="https://github.com/Vetlix"><img src="https://avatars.githubusercontent.com/u/31412314?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vetlix</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Vetlix" title="Code">💻</a></td>
201
199
  <td align="center"><a href="https://github.com/ethamitc"><img src="https://avatars.githubusercontent.com/u/27776796?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ethan Mitchell</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=ethamitc" title="Documentation">📖</a></td>
202
200
  <td align="center"><a href="https://github.com/noftaly"><img src="https://avatars.githubusercontent.com/u/34779161?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Elliot</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=noftaly" title="Code">💻</a></td>
201
+ <td align="center"><a href="https://jurien.dev"><img src="https://avatars.githubusercontent.com/u/5418114?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jurien Hamaker</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=jurienhamaker" title="Code">💻</a></td>
203
202
  </tr>
204
203
  <tr>
205
- <td align="center"><a href="https://jurien.dev"><img src="https://avatars.githubusercontent.com/u/5418114?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jurien Hamaker</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=jurienhamaker" title="Code">💻</a></td>
206
204
  <td align="center"><a href="https://fanoulis.dev/"><img src="https://avatars.githubusercontent.com/u/38255093?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Charalampos Fanoulis</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=cfanoulis" title="Documentation">📖</a></td>
207
205
  <td align="center"><a href="https://github.com/apps/dependabot"><img src="https://avatars.githubusercontent.com/in/29110?v=4?s=100" width="100px;" alt=""/><br /><sub><b>dependabot[bot]</b></sub></a><br /><a href="#maintenance-dependabot[bot]" title="Maintenance">🚧</a></td>
208
206
  <td align="center"><a href="https://kaname.netlify.app/"><img src="https://avatars.githubusercontent.com/u/56084970?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kaname</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=kaname-png" title="Code">💻</a></td>
209
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
+ <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
+ <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
210
  </tr>
211
211
  </table>
212
212
 
package/dist/index.js CHANGED
@@ -76,12 +76,12 @@ class Snowflake {
76
76
  * ```
77
77
  * @returns A unique snowflake
78
78
  */
79
- generate({ increment = __classPrivateFieldGet(this, _Snowflake_increment), timestamp = Date.now(), workerID = 1n, processID = 1n } = {
80
- increment: __classPrivateFieldGet(this, _Snowflake_increment),
79
+ generate({ increment, timestamp = Date.now(), workerID = 1n, processID = 1n } = {
81
80
  timestamp: Date.now(),
82
81
  workerID: 1n,
83
82
  processID: 1n
84
83
  }) {
84
+ var _a, _b;
85
85
  if (timestamp instanceof Date)
86
86
  timestamp = BigInt(timestamp.getTime());
87
87
  if (typeof timestamp === 'number' && !Number.isNaN(timestamp))
@@ -89,10 +89,12 @@ class Snowflake {
89
89
  if (typeof timestamp !== 'bigint') {
90
90
  throw new TypeError(`"timestamp" argument must be a number, BigInt or Date (received ${Number.isNaN(timestamp) ? 'NaN' : typeof timestamp})`);
91
91
  }
92
- if (increment >= 4095n)
92
+ if (increment !== undefined && increment >= 4095n)
93
93
  increment = 0n;
94
+ if (__classPrivateFieldGet(this, _Snowflake_increment) >= 4095n)
95
+ __classPrivateFieldSet(this, _Snowflake_increment, 0n);
94
96
  // timestamp, workerID, processID, increment
95
- return ((timestamp - __classPrivateFieldGet(this, _Snowflake_epoch)) << 22n) | (workerID << 17n) | (processID << 12n) | increment++;
97
+ return (((timestamp - __classPrivateFieldGet(this, _Snowflake_epoch)) << 22n) | (workerID << 17n) | (processID << 12n) | (increment === undefined ? (__classPrivateFieldSet(this, _Snowflake_increment, (_b = __classPrivateFieldGet(this, _Snowflake_increment), _a = _b++, _b)), _a) : increment++));
96
98
  }
97
99
  /**
98
100
  * Deconstructs a snowflake given a snowflake ID
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 = this.#increment, timestamp = Date.now(), workerID = 1n, processID = 1n }: SnowflakeGenerateOptions = {\n\t\t\tincrement: this.#increment,\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 >= 4095n) increment = 0n;\n\n\t\t// timestamp, workerID, processID, increment\n\t\treturn ((timestamp - this.#epoch) << 22n) | (workerID << 17n) | (processID << 12n) | increment++;\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,GAAG,uBAAA,IAAI,uBAAW,EAAE,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,QAAQ,GAAG,EAAE,EAAE,SAAS,GAAG,EAAE,KAA+B;QAClH,SAAS,EAAE,uBAAA,IAAI,uBAAW;QAC1B,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,QAAQ,EAAE,EAAE;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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.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,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,EA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AAQ,GAAG,KAAe;YACrC,KAAK,EAAE,uBAAA,IAAI,mBAAO;SAClB,CAAC;KACF;CACD;;;ACvFD;;;;;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;;;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;;;;;;;"}
package/dist/index.mjs CHANGED
@@ -72,12 +72,12 @@ class Snowflake {
72
72
  * ```
73
73
  * @returns A unique snowflake
74
74
  */
75
- generate({ increment = __classPrivateFieldGet(this, _Snowflake_increment), timestamp = Date.now(), workerID = 1n, processID = 1n } = {
76
- increment: __classPrivateFieldGet(this, _Snowflake_increment),
75
+ generate({ increment, timestamp = Date.now(), workerID = 1n, processID = 1n } = {
77
76
  timestamp: Date.now(),
78
77
  workerID: 1n,
79
78
  processID: 1n
80
79
  }) {
80
+ var _a, _b;
81
81
  if (timestamp instanceof Date)
82
82
  timestamp = BigInt(timestamp.getTime());
83
83
  if (typeof timestamp === 'number' && !Number.isNaN(timestamp))
@@ -85,10 +85,12 @@ class Snowflake {
85
85
  if (typeof timestamp !== 'bigint') {
86
86
  throw new TypeError(`"timestamp" argument must be a number, BigInt or Date (received ${Number.isNaN(timestamp) ? 'NaN' : typeof timestamp})`);
87
87
  }
88
- if (increment >= 4095n)
88
+ if (increment !== undefined && increment >= 4095n)
89
89
  increment = 0n;
90
+ if (__classPrivateFieldGet(this, _Snowflake_increment) >= 4095n)
91
+ __classPrivateFieldSet(this, _Snowflake_increment, 0n);
90
92
  // timestamp, workerID, processID, increment
91
- return ((timestamp - __classPrivateFieldGet(this, _Snowflake_epoch)) << 22n) | (workerID << 17n) | (processID << 12n) | increment++;
93
+ return (((timestamp - __classPrivateFieldGet(this, _Snowflake_epoch)) << 22n) | (workerID << 17n) | (processID << 12n) | (increment === undefined ? (__classPrivateFieldSet(this, _Snowflake_increment, (_b = __classPrivateFieldGet(this, _Snowflake_increment), _a = _b++, _b)), _a) : increment++));
92
94
  }
93
95
  /**
94
96
  * Deconstructs a snowflake given a snowflake ID
@@ -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 = this.#increment, timestamp = Date.now(), workerID = 1n, processID = 1n }: SnowflakeGenerateOptions = {\n\t\t\tincrement: this.#increment,\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 >= 4095n) increment = 0n;\n\n\t\t// timestamp, workerID, processID, increment\n\t\treturn ((timestamp - this.#epoch) << 22n) | (workerID << 17n) | (processID << 12n) | increment++;\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,GAAG,uBAAA,IAAI,uBAAW,EAAE,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,QAAQ,GAAG,EAAE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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;;;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 * ```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,QA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@@ -2,7 +2,7 @@
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
3
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.SapphireSnowflake = {}));
5
- }(this, (function (exports) { 'use strict';
5
+ })(this, (function (exports) { 'use strict';
6
6
 
7
7
  /*! *****************************************************************************
8
8
  Copyright (c) Microsoft Corporation.
@@ -78,12 +78,12 @@
78
78
  * ```
79
79
  * @returns A unique snowflake
80
80
  */
81
- generate({ increment = __classPrivateFieldGet(this, _Snowflake_increment), timestamp = Date.now(), workerID = 1n, processID = 1n } = {
82
- increment: __classPrivateFieldGet(this, _Snowflake_increment),
81
+ generate({ increment, timestamp = Date.now(), workerID = 1n, processID = 1n } = {
83
82
  timestamp: Date.now(),
84
83
  workerID: 1n,
85
84
  processID: 1n
86
85
  }) {
86
+ var _a, _b;
87
87
  if (timestamp instanceof Date)
88
88
  timestamp = BigInt(timestamp.getTime());
89
89
  if (typeof timestamp === 'number' && !Number.isNaN(timestamp))
@@ -91,10 +91,12 @@
91
91
  if (typeof timestamp !== 'bigint') {
92
92
  throw new TypeError(`"timestamp" argument must be a number, BigInt or Date (received ${Number.isNaN(timestamp) ? 'NaN' : typeof timestamp})`);
93
93
  }
94
- if (increment >= 4095n)
94
+ if (increment !== undefined && increment >= 4095n)
95
95
  increment = 0n;
96
+ if (__classPrivateFieldGet(this, _Snowflake_increment) >= 4095n)
97
+ __classPrivateFieldSet(this, _Snowflake_increment, 0n);
96
98
  // timestamp, workerID, processID, increment
97
- return ((timestamp - __classPrivateFieldGet(this, _Snowflake_epoch)) << 22n) | (workerID << 17n) | (processID << 12n) | increment++;
99
+ return (((timestamp - __classPrivateFieldGet(this, _Snowflake_epoch)) << 22n) | (workerID << 17n) | (processID << 12n) | (increment === undefined ? (__classPrivateFieldSet(this, _Snowflake_increment, (_b = __classPrivateFieldGet(this, _Snowflake_increment), _a = _b++, _b)), _a) : increment++));
98
100
  }
99
101
  /**
100
102
  * Deconstructs a snowflake given a snowflake ID
@@ -252,5 +254,5 @@
252
254
 
253
255
  Object.defineProperty(exports, '__esModule', { value: true });
254
256
 
255
- })));
257
+ }));
256
258
  //# sourceMappingURL=index.umd.js.map
@@ -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 = this.#increment, timestamp = Date.now(), workerID = 1n, processID = 1n }: SnowflakeGenerateOptions = {\n\t\t\tincrement: this.#increment,\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 >= 4095n) increment = 0n;\n\n\t\t// timestamp, workerID, processID, increment\n\t\treturn ((timestamp - this.#epoch) << 22n) | (workerID << 17n) | (processID << 12n) | increment++;\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.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AaM,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 * ```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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,SAAS,GAAG,CACxH,CAAC;aACF;YAED,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,IAAI,KAAK;gBAAE,SAAS,G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;IAEjB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACd"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sapphire/snowflake",
3
- "version": "2.1.0-pr-159.fae7a606.0",
3
+ "version": "2.1.0",
4
4
  "description": "Deconstructs and generates snoflake IDs using BigInts",
5
5
  "author": "@sapphire",
6
6
  "license": "MIT",
@@ -9,6 +9,7 @@
9
9
  "browser": "dist/index.umd.js",
10
10
  "unpkg": "dist/index.umd.js",
11
11
  "types": "dist/index.d.ts",
12
+ "typedocMain": "src/index.ts",
12
13
  "exports": {
13
14
  "import": "./dist/index.mjs",
14
15
  "require": "./dist/index.js"
@@ -19,7 +20,7 @@
19
20
  "test": "jest",
20
21
  "lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
21
22
  "build": "rollup -c",
22
- "start": "yarn build -w",
23
+ "watch": "yarn build -w",
23
24
  "prepublishOnly": "yarn build"
24
25
  },
25
26
  "repository": {
@@ -32,8 +33,8 @@
32
33
  "!dist/*.tsbuildinfo"
33
34
  ],
34
35
  "engines": {
35
- "node": ">=14",
36
- "npm": ">=6"
36
+ "node": ">=v14.18.0",
37
+ "npm": ">=7.24.1"
37
38
  },
38
39
  "keywords": [
39
40
  "@sapphire/snowflake",
@@ -51,5 +52,5 @@
51
52
  "publishConfig": {
52
53
  "access": "public"
53
54
  },
54
- "gitHead": "fae7a606b5af80cbe079304ab440584a981ea4d8"
55
+ "gitHead": "18e0df218137b1c05c22fc3c066619e635ffb8dc"
55
56
  }