@sapphire/snowflake 3.0.0-pr-160.676f855.0 → 3.0.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 +13 -14
- package/dist/index.js +59 -146
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -146
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +61 -148
- package/dist/index.umd.js.map +1 -1
- package/dist/lib/DiscordSnowflake.d.ts +2 -41
- package/dist/lib/DiscordSnowflake.d.ts.map +1 -1
- package/dist/lib/Snowflake.d.ts +32 -12
- package/dist/lib/Snowflake.d.ts.map +1 -1
- package/dist/lib/TwitterSnowflake.d.ts +2 -41
- package/dist/lib/TwitterSnowflake.d.ts.map +1 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
[](https://codecov.io/gh/sapphiredev/utilities)
|
|
11
11
|
[](https://bundlephobia.com/result?p=@sapphire/snowflake)
|
|
12
12
|
[](https://www.npmjs.com/package/@sapphire/snowflake)
|
|
13
|
-
[](https://depfu.com/github/sapphiredev/utilities?project_id=15195)
|
|
14
13
|
|
|
15
14
|
</div>
|
|
16
15
|
|
|
@@ -28,7 +27,6 @@
|
|
|
28
27
|
- [Snowflakes with custom epoch](#snowflakes-with-custom-epoch-1)
|
|
29
28
|
- [Snowflake with Discord epoch constant](#snowflake-with-discord-epoch-constant-1)
|
|
30
29
|
- [Snowflake with Twitter epoch constant](#snowflake-with-twitter-epoch-constant-1)
|
|
31
|
-
- [API Documentation](#api-documentation)
|
|
32
30
|
- [Buy us some doughnuts](#buy-us-some-doughnuts)
|
|
33
31
|
- [Contributors ✨](#contributors-%E2%9C%A8)
|
|
34
32
|
|
|
@@ -60,7 +58,7 @@ npm install @sapphire/snowflake
|
|
|
60
58
|
|
|
61
59
|
#### Snowflakes with custom epoch
|
|
62
60
|
|
|
63
|
-
```
|
|
61
|
+
```typescript
|
|
64
62
|
// Import the Snowflake class
|
|
65
63
|
const { Snowflake } = require('@sapphire/snowflake');
|
|
66
64
|
|
|
@@ -76,7 +74,7 @@ const uniqueId = snowflake.generate();
|
|
|
76
74
|
|
|
77
75
|
#### Snowflake with Discord epoch constant
|
|
78
76
|
|
|
79
|
-
```
|
|
77
|
+
```typescript
|
|
80
78
|
// Import the Snowflake class
|
|
81
79
|
const { DiscordSnowflake } = require('@sapphire/snowflake');
|
|
82
80
|
|
|
@@ -92,7 +90,7 @@ const uniqueId = DiscordSnowflake.generate();
|
|
|
92
90
|
|
|
93
91
|
#### Snowflake with Twitter epoch constant
|
|
94
92
|
|
|
95
|
-
```
|
|
93
|
+
```typescript
|
|
96
94
|
// Import the Snowflake class
|
|
97
95
|
const { TwitterSnowflake } = require('@sapphire/snowflake');
|
|
98
96
|
|
|
@@ -110,7 +108,7 @@ const uniqueId = TwitterSnowflake.generate();
|
|
|
110
108
|
|
|
111
109
|
#### Snowflakes with custom epoch
|
|
112
110
|
|
|
113
|
-
```
|
|
111
|
+
```typescript
|
|
114
112
|
// Import the Snowflake class
|
|
115
113
|
const { Snowflake } = require('@sapphire/snowflake');
|
|
116
114
|
|
|
@@ -126,7 +124,7 @@ const uniqueId = snowflake.deconstruct('3971046231244935168');
|
|
|
126
124
|
|
|
127
125
|
#### Snowflake with Discord epoch constant
|
|
128
126
|
|
|
129
|
-
```
|
|
127
|
+
```typescript
|
|
130
128
|
// Import the Snowflake class
|
|
131
129
|
const { DiscordSnowflake } = require('@sapphire/snowflake');
|
|
132
130
|
|
|
@@ -142,7 +140,7 @@ const uniqueId = DiscordSnowflake.deconstruct('3971046231244935168');
|
|
|
142
140
|
|
|
143
141
|
#### Snowflake with Twitter epoch constant
|
|
144
142
|
|
|
145
|
-
```
|
|
143
|
+
```typescript
|
|
146
144
|
// Import the Snowflake class
|
|
147
145
|
const { TwitterSnowflake } = require('@sapphire/snowflake');
|
|
148
146
|
|
|
@@ -158,10 +156,6 @@ const uniqueId = TwitterSnowflake.deconstruct('3971046231244935168');
|
|
|
158
156
|
|
|
159
157
|
---
|
|
160
158
|
|
|
161
|
-
## API Documentation
|
|
162
|
-
|
|
163
|
-
For the full API documentation please refer to the TypeDoc generated [documentation](https://sapphiredev.github.io/utilities/modules/_sapphire_snowflake.html).
|
|
164
|
-
|
|
165
159
|
## Buy us some doughnuts
|
|
166
160
|
|
|
167
161
|
Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!
|
|
@@ -196,17 +190,22 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
196
190
|
<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
191
|
<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
192
|
<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
193
|
<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
194
|
<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
195
|
<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>
|
|
196
|
+
<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
197
|
</tr>
|
|
204
198
|
<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
199
|
<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
200
|
<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
201
|
<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
202
|
<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>
|
|
203
|
+
<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>
|
|
204
|
+
<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>
|
|
205
|
+
<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> <a href="https://github.com/sapphiredev/utilities/commits?author=Lioness100" title="Code">💻</a></td>
|
|
206
|
+
</tr>
|
|
207
|
+
<tr>
|
|
208
|
+
<td align="center"><a href="https://gitlab.com/DavidPH/"><img src="https://avatars.githubusercontent.com/u/44669930?v=4?s=100" width="100px;" alt=""/><br /><sub><b>David</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=DavidPHH" title="Code">💻</a></td>
|
|
210
209
|
</tr>
|
|
211
210
|
</table>
|
|
212
211
|
|
package/dist/index.js
CHANGED
|
@@ -17,25 +17,35 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
17
17
|
PERFORMANCE OF THIS SOFTWARE.
|
|
18
18
|
***************************************************************************** */
|
|
19
19
|
|
|
20
|
-
function __classPrivateFieldGet(receiver,
|
|
21
|
-
if (!
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return privateMap.get(receiver);
|
|
20
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
21
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
22
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
23
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
function __classPrivateFieldSet(receiver,
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return value;
|
|
26
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
27
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
28
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
29
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
30
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
/* eslint-disable @typescript-eslint/explicit-member-accessibility */
|
|
36
34
|
var _Snowflake_increment, _Snowflake_epoch;
|
|
35
|
+
const ProcessId = 1n;
|
|
36
|
+
const WorkerId = 0n;
|
|
37
37
|
/**
|
|
38
|
-
* A class for
|
|
38
|
+
* A class for generating and deconstructing Twitter snowflakes.
|
|
39
|
+
*
|
|
40
|
+
* A {@link https://developer.twitter.com/en/docs/twitter-ids Twitter snowflake}
|
|
41
|
+
* is a 64-bit unsigned integer with 4 fields that have a fixed epoch value.
|
|
42
|
+
*
|
|
43
|
+
* If we have a snowflake `266241948824764416` we can represent it as binary:
|
|
44
|
+
* ```
|
|
45
|
+
* 64 22 17 12 0
|
|
46
|
+
* 000000111011000111100001101001000101000000 00001 00000 000000000000
|
|
47
|
+
* number of ms since epoch worker pid increment
|
|
48
|
+
* ```
|
|
39
49
|
*/
|
|
40
50
|
class Snowflake {
|
|
41
51
|
/**
|
|
@@ -62,44 +72,51 @@ class Snowflake {
|
|
|
62
72
|
writable: true,
|
|
63
73
|
value: this.deconstruct
|
|
64
74
|
});
|
|
65
|
-
__classPrivateFieldSet(this, _Snowflake_epoch, BigInt(epoch instanceof Date ? epoch.getTime() : epoch));
|
|
75
|
+
__classPrivateFieldSet(this, _Snowflake_epoch, BigInt(epoch instanceof Date ? epoch.getTime() : epoch), "f");
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The epoch for this snowflake.
|
|
79
|
+
*/
|
|
80
|
+
get epoch() {
|
|
81
|
+
return __classPrivateFieldGet(this, _Snowflake_epoch, "f");
|
|
66
82
|
}
|
|
67
83
|
/**
|
|
68
84
|
* Generates a snowflake given an epoch and optionally a timestamp
|
|
69
85
|
* @param options options to pass into the generator, see {@link SnowflakeGenerateOptions}
|
|
70
86
|
*
|
|
71
|
-
* **note** when increment is not provided it defaults to the private increment of the instance
|
|
87
|
+
* **note** when `increment` is not provided it defaults to the private `increment` of the instance
|
|
72
88
|
* @example
|
|
73
|
-
* ```
|
|
89
|
+
* ```typescript
|
|
74
90
|
* const epoch = new Date('2000-01-01T00:00:00.000Z');
|
|
75
91
|
* const snowflake = new Snowflake(epoch).generate();
|
|
76
92
|
* ```
|
|
77
93
|
* @returns A unique snowflake
|
|
78
94
|
*/
|
|
79
|
-
generate({ increment
|
|
80
|
-
|
|
81
|
-
timestamp: Date.now(),
|
|
82
|
-
workerID: 1n,
|
|
83
|
-
processID: 1n
|
|
84
|
-
}) {
|
|
95
|
+
generate({ increment, timestamp = Date.now(), workerId = WorkerId, processId = ProcessId } = {}) {
|
|
96
|
+
var _a, _b;
|
|
85
97
|
if (timestamp instanceof Date)
|
|
86
98
|
timestamp = BigInt(timestamp.getTime());
|
|
87
|
-
if (typeof timestamp === 'number'
|
|
99
|
+
else if (typeof timestamp === 'number')
|
|
88
100
|
timestamp = BigInt(timestamp);
|
|
89
|
-
if (typeof timestamp !== 'bigint') {
|
|
90
|
-
throw new TypeError(`"timestamp" argument must be a number,
|
|
101
|
+
else if (typeof timestamp !== 'bigint') {
|
|
102
|
+
throw new TypeError(`"timestamp" argument must be a number, bigint, or Date (received ${typeof timestamp})`);
|
|
91
103
|
}
|
|
92
|
-
if (increment >= 4095n)
|
|
104
|
+
if (typeof increment === 'bigint' && increment >= 4095n)
|
|
93
105
|
increment = 0n;
|
|
94
|
-
|
|
95
|
-
|
|
106
|
+
else {
|
|
107
|
+
increment = (__classPrivateFieldSet(this, _Snowflake_increment, (_b = __classPrivateFieldGet(this, _Snowflake_increment, "f"), _a = _b++, _b), "f"), _a);
|
|
108
|
+
if (__classPrivateFieldGet(this, _Snowflake_increment, "f") >= 4095n)
|
|
109
|
+
__classPrivateFieldSet(this, _Snowflake_increment, 0n, "f");
|
|
110
|
+
}
|
|
111
|
+
// timestamp, workerId, processId, increment
|
|
112
|
+
return ((timestamp - __classPrivateFieldGet(this, _Snowflake_epoch, "f")) << 22n) | ((workerId & 31n) << 17n) | ((processId & 31n) << 12n) | increment;
|
|
96
113
|
}
|
|
97
114
|
/**
|
|
98
115
|
* Deconstructs a snowflake given a snowflake ID
|
|
99
116
|
* @param id the snowflake to deconstruct
|
|
100
117
|
* @returns a deconstructed snowflake
|
|
101
118
|
* @example
|
|
102
|
-
* ```
|
|
119
|
+
* ```typescript
|
|
103
120
|
* const epoch = new Date('2000-01-01T00:00:00.000Z');
|
|
104
121
|
* const snowflake = new Snowflake(epoch).deconstruct('3971046231244935168');
|
|
105
122
|
* ```
|
|
@@ -108,13 +125,21 @@ class Snowflake {
|
|
|
108
125
|
const bigIntId = BigInt(id);
|
|
109
126
|
return {
|
|
110
127
|
id: bigIntId,
|
|
111
|
-
timestamp: (bigIntId >> 22n) + __classPrivateFieldGet(this, _Snowflake_epoch),
|
|
112
|
-
|
|
113
|
-
|
|
128
|
+
timestamp: (bigIntId >> 22n) + __classPrivateFieldGet(this, _Snowflake_epoch, "f"),
|
|
129
|
+
workerId: (bigIntId >> 17n) & 31n,
|
|
130
|
+
processId: (bigIntId >> 12n) & 31n,
|
|
114
131
|
increment: bigIntId & 4095n,
|
|
115
|
-
epoch: __classPrivateFieldGet(this, _Snowflake_epoch)
|
|
132
|
+
epoch: __classPrivateFieldGet(this, _Snowflake_epoch, "f")
|
|
116
133
|
};
|
|
117
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Retrieves the timestamp field's value from a snowflake.
|
|
137
|
+
* @param id The snowflake to get the timestamp value from.
|
|
138
|
+
* @returns The UNIX timestamp that is stored in `id`.
|
|
139
|
+
*/
|
|
140
|
+
timestampFrom(id) {
|
|
141
|
+
return Number((BigInt(id) >> 22n) + __classPrivateFieldGet(this, _Snowflake_epoch, "f"));
|
|
142
|
+
}
|
|
118
143
|
}
|
|
119
144
|
_Snowflake_increment = new WeakMap(), _Snowflake_epoch = new WeakMap();
|
|
120
145
|
|
|
@@ -123,126 +148,14 @@ _Snowflake_increment = new WeakMap(), _Snowflake_epoch = new WeakMap();
|
|
|
123
148
|
*
|
|
124
149
|
* Which is 2015-01-01 at 00:00:00.000 UTC+0, {@linkplain https://discord.com/developers/docs/reference#snowflakes}
|
|
125
150
|
*/
|
|
126
|
-
|
|
127
|
-
constructor() {
|
|
128
|
-
super(DiscordSnowflake.Epoch);
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Deconstructs a snowflake given a snowflake ID
|
|
132
|
-
* @param id the snowflake to deconstruct
|
|
133
|
-
* @returns a deconstructed snowflake
|
|
134
|
-
* @example
|
|
135
|
-
* ```ts
|
|
136
|
-
* const snowflake = DiscordSnowflake.deconstruct('3971046231244935168');
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
static deconstruct(id) {
|
|
140
|
-
return new DiscordSnowflake().deconstruct(id);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Generates a snowflake given an epoch and optionally a timestamp
|
|
144
|
-
* @param options {@link SnowflakeGenerateOptions} to pass into the generator
|
|
145
|
-
*
|
|
146
|
-
* **note** when increment is not provided it defaults to `0n`
|
|
147
|
-
* @example
|
|
148
|
-
* ```ts
|
|
149
|
-
* const snowflake = DiscordSnowflake.generate();
|
|
150
|
-
* ```
|
|
151
|
-
* @returns A unique snowflake
|
|
152
|
-
*/
|
|
153
|
-
static generate(options = { timestamp: Date.now() }) {
|
|
154
|
-
return new DiscordSnowflake().generate(options);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Discord epoch (`2015-01-01T00:00:00.000Z`)
|
|
159
|
-
* @see {@linkplain https://discord.com/developers/docs/reference#snowflakes}
|
|
160
|
-
*/
|
|
161
|
-
Object.defineProperty(DiscordSnowflake, "Epoch", {
|
|
162
|
-
enumerable: true,
|
|
163
|
-
configurable: true,
|
|
164
|
-
writable: true,
|
|
165
|
-
value: 1420070400000n
|
|
166
|
-
});
|
|
167
|
-
/**
|
|
168
|
-
* Deconstructs a snowflake given a snowflake ID
|
|
169
|
-
* @param id the snowflake to deconstruct
|
|
170
|
-
* @returns a deconstructed snowflake
|
|
171
|
-
* @example
|
|
172
|
-
* ```ts
|
|
173
|
-
* const snowflake = DiscordSnowflake.decode('3971046231244935168');
|
|
174
|
-
* ```
|
|
175
|
-
*/
|
|
176
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
177
|
-
Object.defineProperty(DiscordSnowflake, "decode", {
|
|
178
|
-
enumerable: true,
|
|
179
|
-
configurable: true,
|
|
180
|
-
writable: true,
|
|
181
|
-
value: DiscordSnowflake.deconstruct
|
|
182
|
-
});
|
|
151
|
+
const DiscordSnowflake = new Snowflake(1420070400000n);
|
|
183
152
|
|
|
184
153
|
/**
|
|
185
154
|
* A class for parsing snowflake ids using Twitter's snowflake epoch
|
|
186
155
|
*
|
|
187
156
|
* 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}
|
|
188
157
|
*/
|
|
189
|
-
|
|
190
|
-
constructor() {
|
|
191
|
-
super(TwitterSnowflake.Epoch);
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Deconstructs a snowflake given a snowflake ID
|
|
195
|
-
* @param id the snowflake to deconstruct
|
|
196
|
-
* @returns a deconstructed snowflake
|
|
197
|
-
* @example
|
|
198
|
-
* ```ts
|
|
199
|
-
* const snowflake = TwitterSnowflake.deconstruct('3971046231244935168');
|
|
200
|
-
* ```
|
|
201
|
-
*/
|
|
202
|
-
static deconstruct(id) {
|
|
203
|
-
return new TwitterSnowflake().deconstruct(id);
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Generates a snowflake given an epoch and optionally a timestamp
|
|
207
|
-
* @param options options to pass into the generator, see {@link SnowflakeGenerateOptions}
|
|
208
|
-
*
|
|
209
|
-
* **note** when increment is not provided it defaults to `0n`
|
|
210
|
-
* @example
|
|
211
|
-
* ```ts
|
|
212
|
-
* const snowflake = TwitterSnowflake.generate();
|
|
213
|
-
* ```
|
|
214
|
-
* @returns A unique snowflake
|
|
215
|
-
*/
|
|
216
|
-
static generate(options = { timestamp: Date.now() }) {
|
|
217
|
-
return new TwitterSnowflake().generate(options);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Twitter epoch (`2006-03-21T20:50:14.000Z`)
|
|
222
|
-
* @see {@linkplain https://twitter.com/jack/status/20}, first tweet ever made
|
|
223
|
-
*/
|
|
224
|
-
Object.defineProperty(TwitterSnowflake, "Epoch", {
|
|
225
|
-
enumerable: true,
|
|
226
|
-
configurable: true,
|
|
227
|
-
writable: true,
|
|
228
|
-
value: 1142974214000n
|
|
229
|
-
});
|
|
230
|
-
/**
|
|
231
|
-
* Deconstructs a snowflake given a snowflake ID
|
|
232
|
-
* @param id the snowflake to deconstruct
|
|
233
|
-
* @returns a deconstructed snowflake
|
|
234
|
-
* @example
|
|
235
|
-
* ```ts
|
|
236
|
-
* const snowflake = TwitterSnowflake.decode('3971046231244935168');
|
|
237
|
-
* ```
|
|
238
|
-
*/
|
|
239
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
240
|
-
Object.defineProperty(TwitterSnowflake, "decode", {
|
|
241
|
-
enumerable: true,
|
|
242
|
-
configurable: true,
|
|
243
|
-
writable: true,
|
|
244
|
-
value: TwitterSnowflake.deconstruct
|
|
245
|
-
});
|
|
158
|
+
const TwitterSnowflake = new Snowflake(1142974214000n);
|
|
246
159
|
|
|
247
160
|
exports.DiscordSnowflake = DiscordSnowflake;
|
|
248
161
|
exports.Snowflake = Snowflake;
|
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;QACZ,SAAS,EAAE,EAAE;KACb;QAED,IAAI,SAAS,YAAY,IAAI;YAAE,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;QACvE,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC;YAAE,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;QAE7F,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;YAClC,MAAM,IAAI,SAAS,CAClB,mEAAmE,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,KAAK,GAAG,OAAO,SAAS,GAAG,CACxH,CAAC;SACF;QAED,IAAI,SAAS,IAAI,KAAK;YAAE,SAAS,GAAG,EAAE,CAAC;;QAGvC,OAAO,CAAC,CAAC,SAAS,GAAG,uBAAA,IAAI,mBAAO,KAAK,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,SAAS,IAAI,GAAG,CAAC,GAAG,SAAS,EAAE,CAAC;KACjG;;;;;;;;;;;IAYM,WAAW,CAAC,EAAmB;QACrC,MAAM,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;QAC5B,OAAO;YACN,EAAE,EAAE,QAAQ;YACZ,SAAS,EAAE,CAAC,QAAQ,IAAI,GAAG,IAAI,uBAAA,IAAI,mBAAO;YAC1C,QAAQ,EAAE,CAAC,QAAQ,IAAI,GAAG,IAAI,GAAQ;YACtC,SAAS,EAAE,CAAC,QAAQ,IAAI,GAAG,IAAI,GAAQ;YACvC,SAAS,EAAE,QAAQ,GAAG,KAAe;YACrC,KAAK,EAAE,uBAAA,IAAI,mBAAO;SAClB,CAAC;KACF;CACD;;;ACrFD;;;;;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;;;;;;;"}
|
|
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\nconst ProcessId = 1n;\nconst WorkerId = 0n;\n\n/**\n * A class for generating and deconstructing Twitter snowflakes.\n *\n * A {@link https://developer.twitter.com/en/docs/twitter-ids Twitter snowflake}\n * is a 64-bit unsigned integer with 4 fields that have a fixed epoch value.\n *\n * If we have a snowflake `266241948824764416` we can represent it as binary:\n * ```\n * 64 22 17 12 0\n * 000000111011000111100001101001000101000000 00001 00000 000000000000\n * number of ms since epoch worker pid increment\n * ```\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 * The epoch for this snowflake.\n\t */\n\tpublic get epoch(): bigint {\n\t\treturn this.#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({ increment, timestamp = Date.now(), workerId = WorkerId, processId = ProcessId }: SnowflakeGenerateOptions = {}) {\n\t\tif (timestamp instanceof Date) timestamp = BigInt(timestamp.getTime());\n\t\telse if (typeof timestamp === 'number') timestamp = BigInt(timestamp);\n\t\telse if (typeof timestamp !== 'bigint') {\n\t\t\tthrow new TypeError(`\"timestamp\" argument must be a number, bigint, or Date (received ${typeof timestamp})`);\n\t\t}\n\n\t\tif (typeof increment === 'bigint' && increment >= 4095n) increment = 0n;\n\t\telse {\n\t\t\tincrement = this.#increment++;\n\t\t\tif (this.#increment >= 4095n) this.#increment = 0n;\n\t\t}\n\n\t\t// timestamp, workerId, processId, increment\n\t\treturn ((timestamp - this.#epoch) << 22n) | ((workerId & 0b11111n) << 17n) | ((processId & 0b11111n) << 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 * ```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\t/**\n\t * Retrieves the timestamp field's value from a snowflake.\n\t * @param id The snowflake to get the timestamp value from.\n\t * @returns The UNIX timestamp that is stored in `id`.\n\t */\n\tpublic timestampFrom(id: string | bigint): number {\n\t\treturn Number((BigInt(id) >> 22n) + this.#epoch);\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, will be truncated to 5 bits (0-31)\n\t * @default 0n\n\t */\n\tworkerId?: bigint;\n\n\t/**\n\t * The process ID to use, will be truncated to 5 bits (0-31)\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 { Snowflake } 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 const DiscordSnowflake = new Snowflake(1420070400000n);\n","import { Snowflake } 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 const TwitterSnowflake = new Snowflake(1142974214000n);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAEA,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,QAAQ,GAAG,EAAE,CAAC;AAEpB;;;;;;;;;;;;;MAaa,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,CAAC,MAAA,CAAC;KACtE;;;;IAKD,IAAW,KAAK;QACf,OAAO,uBAAA,IAAI,wBAAO,CAAC;KACnB;;;;;;;;;;;;;IAcM,QAAQ,CAAC,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,QAAQ,GAAG,QAAQ,EAAE,SAAS,GAAG,SAAS,KAA+B,EAAE;;QAC/H,IAAI,SAAS,YAAY,IAAI;YAAE,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;aAClE,IAAI,OAAO,SAAS,KAAK,QAAQ;YAAE,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;aACjE,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;YACvC,MAAM,IAAI,SAAS,CAAC,oEAAoE,OAAO,SAAS,GAAG,CAAC,CAAC;SAC7G;QAED,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,IAAI,KAAK;YAAE,SAAS,GAAG,EAAE,CAAC;aACnE;YACJ,SAAS,IAAG,oDAAA,4DAAe,EAAf,KAAA,IAAiB,IAAA,OAAA,IAAA,CAAA,CAAC;YAC9B,IAAI,uBAAA,IAAI,4BAAW,IAAI,KAAK;gBAAE,uBAAA,IAAI,wBAAc,EAAE,MAAA,CAAC;SACnD;;QAGD,OAAO,CAAC,CAAC,SAAS,GAAG,uBAAA,IAAI,wBAAO,KAAK,GAAG,KAAK,CAAC,QAAQ,GAAG,GAAQ,KAAK,GAAG,CAAC,IAAI,CAAC,SAAS,GAAG,GAAQ,KAAK,GAAG,CAAC,GAAG,SAAS,CAAC;KACzH;;;;;;;;;;;IAYM,WAAW,CAAC,EAAmB;QACrC,MAAM,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;QAC5B,OAAO;YACN,EAAE,EAAE,QAAQ;YACZ,SAAS,EAAE,CAAC,QAAQ,IAAI,GAAG,IAAI,uBAAA,IAAI,wBAAO;YAC1C,QAAQ,EAAE,CAAC,QAAQ,IAAI,GAAG,IAAI,GAAQ;YACtC,SAAS,EAAE,CAAC,QAAQ,IAAI,GAAG,IAAI,GAAQ;YACvC,SAAS,EAAE,QAAQ,GAAG,KAAe;YACrC,KAAK,EAAE,uBAAA,IAAI,wBAAO;SAClB,CAAC;KACF;;;;;;IAOM,aAAa,CAAC,EAAmB;QACvC,OAAO,MAAM,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,GAAG,IAAI,uBAAA,IAAI,wBAAO,CAAC,CAAC;KACjD;CACD;;;AC5GD;;;;;MAKa,gBAAgB,GAAG,IAAI,SAAS,CAAC,cAAc;;ACL5D;;;;;MAKa,gBAAgB,GAAG,IAAI,SAAS,CAAC,cAAc;;;;;;"}
|