/games - /help - reload and delete
This commit is contained in:
214
node_modules/@sapphire/snowflake/README.md
generated
vendored
Normal file
214
node_modules/@sapphire/snowflake/README.md
generated
vendored
Normal file
@@ -0,0 +1,214 @@
|
||||
<div align="center">
|
||||
|
||||

|
||||
|
||||
# @sapphire/snowflake
|
||||
|
||||
**Deconstruct and generate snowflake IDs using BigInts.**
|
||||
|
||||
[](https://github.com/sapphiredev/utilities/blob/main/LICENSE.md)
|
||||
[](https://codecov.io/gh/sapphiredev/utilities)
|
||||
[](https://bundlephobia.com/result?p=@sapphire/snowflake)
|
||||
[](https://www.npmjs.com/package/@sapphire/snowflake)
|
||||
|
||||
</div>
|
||||
|
||||
**Table of Contents**
|
||||
|
||||
- [Description](#description)
|
||||
- [Features](#features)
|
||||
- [Installation](#installation)
|
||||
- [Usage](#usage)
|
||||
- [Constructing snowflakes](#constructing-snowflakes)
|
||||
- [Snowflakes with custom epoch](#snowflakes-with-custom-epoch)
|
||||
- [Snowflake with Discord epoch constant](#snowflake-with-discord-epoch-constant)
|
||||
- [Snowflake with Twitter epoch constant](#snowflake-with-twitter-epoch-constant)
|
||||
- [Deconstructing snowflakes](#deconstructing-snowflakes)
|
||||
- [Snowflakes with custom epoch](#snowflakes-with-custom-epoch-1)
|
||||
- [Snowflake with Discord epoch constant](#snowflake-with-discord-epoch-constant-1)
|
||||
- [Snowflake with Twitter epoch constant](#snowflake-with-twitter-epoch-constant-1)
|
||||
- [Buy us some doughnuts](#buy-us-some-doughnuts)
|
||||
- [Contributors ✨](#contributors-%E2%9C%A8)
|
||||
|
||||
## Description
|
||||
|
||||
There is often a need to get a unique ID for entities, be that for Discord messages/channels/servers, keys in a database or many other similar examples. There are many ways to get such a unique ID, and one of those is using a so-called "snowflake". You can read more about snowflake IDs in [this Medium article](https://medium.com/better-programming/uuid-generation-snowflake-identifiers-unique-2aed8b1771bc).
|
||||
|
||||
## Features
|
||||
|
||||
- Written in TypeScript
|
||||
- Bundled with esbuild so it can be used in NodeJS and browsers
|
||||
- Offers CommonJS, ESM and UMD bundles
|
||||
- Offers predefined epochs for Discord and Twitter
|
||||
- Fully tested
|
||||
|
||||
## Installation
|
||||
|
||||
You can use the following command to install this package, or replace `npm install` with your package manager of choice.
|
||||
|
||||
```sh
|
||||
npm install @sapphire/snowflake
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
**Note:** While this section uses `require`, the imports match 1:1 with ESM imports. For example `const { Snowflake } = require('@sapphire/snowflake')` equals `import { Snowflake } from '@sapphire/snowflake'`.
|
||||
|
||||
### Constructing snowflakes
|
||||
|
||||
#### Snowflakes with custom epoch
|
||||
|
||||
```typescript
|
||||
// Import the Snowflake class
|
||||
const { Snowflake } = require('@sapphire/snowflake');
|
||||
|
||||
// Define a custom epoch
|
||||
const epoch = new Date('2000-01-01T00:00:00.000Z');
|
||||
|
||||
// Create an instance of Snowflake
|
||||
const snowflake = new Snowflake(epoch);
|
||||
|
||||
// Generate a snowflake with the given epoch
|
||||
const uniqueId = snowflake.generate();
|
||||
```
|
||||
|
||||
#### Snowflake with Discord epoch constant
|
||||
|
||||
```typescript
|
||||
// Import the Snowflake class
|
||||
const { DiscordSnowflake } = require('@sapphire/snowflake');
|
||||
|
||||
// Generate a snowflake with Discord's epoch
|
||||
const uniqueId = DiscordSnowflake.generate();
|
||||
|
||||
// Alternatively, you can use the method directly
|
||||
const uniqueId = DiscordSnowflake.generate();
|
||||
```
|
||||
|
||||
#### Snowflake with Twitter epoch constant
|
||||
|
||||
```typescript
|
||||
// Import the Snowflake class
|
||||
const { TwitterSnowflake } = require('@sapphire/snowflake');
|
||||
|
||||
// Generate a snowflake with Twitter's epoch
|
||||
const uniqueId = TwitterSnowflake.generate();
|
||||
|
||||
// Alternatively, you can use the method directly
|
||||
const uniqueId = TwitterSnowflake.generate();
|
||||
```
|
||||
|
||||
### Deconstructing snowflakes
|
||||
|
||||
#### Snowflakes with custom epoch
|
||||
|
||||
```typescript
|
||||
// Import the Snowflake class
|
||||
const { Snowflake } = require('@sapphire/snowflake');
|
||||
|
||||
// Define a custom epoch
|
||||
const epoch = new Date('2000-01-01T00:00:00.000Z');
|
||||
|
||||
// Create an instance of Snowflake
|
||||
const snowflake = new Snowflake(epoch);
|
||||
|
||||
// Deconstruct a snowflake with the given epoch
|
||||
const uniqueId = snowflake.deconstruct('3971046231244935168');
|
||||
```
|
||||
|
||||
#### Snowflake with Discord epoch constant
|
||||
|
||||
```typescript
|
||||
// Import the Snowflake class
|
||||
const { DiscordSnowflake } = require('@sapphire/snowflake');
|
||||
|
||||
// Deconstruct a snowflake with Discord's epoch
|
||||
const uniqueId = DiscordSnowflake.deconstruct('3971046231244935168');
|
||||
|
||||
// Alternatively, you can use the method directly
|
||||
const uniqueId = DiscordSnowflake.deconstruct('3971046231244935168');
|
||||
```
|
||||
|
||||
#### Snowflake with Twitter epoch constant
|
||||
|
||||
```typescript
|
||||
// Import the Snowflake class
|
||||
const { TwitterSnowflake } = require('@sapphire/snowflake');
|
||||
|
||||
// Deconstruct a snowflake with Twitter's epoch
|
||||
const uniqueId = TwitterSnowflake.deconstruct('3971046231244935168');
|
||||
|
||||
// Alternatively, you can use the method directly
|
||||
const uniqueId = TwitterSnowflake.deconstruct('3971046231244935168');
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Buy us some doughnuts
|
||||
|
||||
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!
|
||||
|
||||
We accept donations through Open Collective, Ko-fi, PayPal, Patreon and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.
|
||||
|
||||
| Donate With | Address |
|
||||
| :-------------: | :-------------------------------------------------: |
|
||||
| Open Collective | [Click Here](https://sapphirejs.dev/opencollective) |
|
||||
| Ko-fi | [Click Here](https://sapphirejs.dev/kofi) |
|
||||
| Patreon | [Click Here](https://sapphirejs.dev/patreon) |
|
||||
| PayPal | [Click Here](https://sapphirejs.dev/paypal) |
|
||||
|
||||
## Contributors ✨
|
||||
|
||||
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
||||
<!-- prettier-ignore-start -->
|
||||
<!-- markdownlint-disable -->
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center"><a href="https://favware.tech/"><img src="https://avatars3.githubusercontent.com/u/4019718?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jeroen Claassens</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Code">💻</a> <a href="#infra-favna" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#projectManagement-favna" title="Project Management">📆</a> <a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Documentation">📖</a> <a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Tests">⚠️</a></td>
|
||||
<td align="center"><a href="https://github.com/kyranet"><img src="https://avatars0.githubusercontent.com/u/24852502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Antonio Román</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=kyranet" title="Code">💻</a> <a href="#projectManagement-kyranet" title="Project Management">📆</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3Akyranet" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/sapphiredev/utilities/commits?author=kyranet" title="Tests">⚠️</a></td>
|
||||
<td align="center"><a href="https://github.com/PyroTechniac"><img src="https://avatars2.githubusercontent.com/u/39341355?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Gryffon Bellish</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=PyroTechniac" title="Code">💻</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3APyroTechniac" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/sapphiredev/utilities/commits?author=PyroTechniac" title="Tests">⚠️</a></td>
|
||||
<td align="center"><a href="https://github.com/vladfrangu"><img src="https://avatars3.githubusercontent.com/u/17960496?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vlad Frangu</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=vladfrangu" title="Code">💻</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3Avladfrangu" title="Bug reports">🐛</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3Avladfrangu" title="Reviewed Pull Requests">👀</a> <a href="#userTesting-vladfrangu" title="User Testing">📓</a> <a href="https://github.com/sapphiredev/utilities/commits?author=vladfrangu" title="Tests">⚠️</a></td>
|
||||
<td align="center"><a href="https://github.com/Stitch07"><img src="https://avatars0.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="#projectManagement-Stitch07" title="Project Management">📆</a> <a href="https://github.com/sapphiredev/utilities/commits?author=Stitch07" title="Tests">⚠️</a></td>
|
||||
<td align="center"><a href="https://github.com/apps/depfu"><img src="https://avatars3.githubusercontent.com/in/715?v=4?s=100" width="100px;" alt=""/><br /><sub><b>depfu[bot]</b></sub></a><br /><a href="#maintenance-depfu[bot]" title="Maintenance">🚧</a></td>
|
||||
<td align="center"><a href="https://github.com/apps/allcontributors"><img src="https://avatars0.githubusercontent.com/in/23186?v=4?s=100" width="100px;" alt=""/><br /><sub><b>allcontributors[bot]</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=allcontributors[bot]" title="Documentation">📖</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
</tr>
|
||||
<tr>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
</tr>
|
||||
<tr>
|
||||
<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>
|
||||
<td align="center"><a href="https://github.com/apps/renovate"><img src="https://avatars.githubusercontent.com/in/2740?v=4?s=100" width="100px;" alt=""/><br /><sub><b>renovate[bot]</b></sub></a><br /><a href="#maintenance-renovate[bot]" title="Maintenance">🚧</a></td>
|
||||
<td align="center"><a href="https://renovate.whitesourcesoftware.com/"><img src="https://avatars.githubusercontent.com/u/25180681?v=4?s=100" width="100px;" alt=""/><br /><sub><b>WhiteSource Renovate</b></sub></a><br /><a href="#maintenance-renovate-bot" title="Maintenance">🚧</a></td>
|
||||
<td align="center"><a href="https://fc5570.me/"><img src="https://avatars.githubusercontent.com/u/68158483?v=4?s=100" width="100px;" alt=""/><br /><sub><b>FC</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=FC5570" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/Tokipudi"><img src="https://avatars.githubusercontent.com/u/29551076?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jérémy de Saint Denis</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Tokipudi" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/ItsMrCube"><img src="https://avatars.githubusercontent.com/u/25201357?v=4?s=100" width="100px;" alt=""/><br /><sub><b>MrCube</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=ItsMrCube" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/bitomic"><img src="https://avatars.githubusercontent.com/u/35199700?v=4?s=100" width="100px;" alt=""/><br /><sub><b>bitomic</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=bitomic" title="Code">💻</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://c43721.dev/"><img src="https://avatars.githubusercontent.com/u/55610086?v=4?s=100" width="100px;" alt=""/><br /><sub><b>c43721</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=c43721" title="Code">💻</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- markdownlint-restore -->
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||
|
||||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
||||
4
node_modules/@sapphire/snowflake/dist/index.d.ts
generated
vendored
Normal file
4
node_modules/@sapphire/snowflake/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './lib/DiscordSnowflake';
|
||||
export * from './lib/Snowflake';
|
||||
export * from './lib/TwitterSnowflake';
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
124
node_modules/@sapphire/snowflake/dist/index.global.js
generated
vendored
Normal file
124
node_modules/@sapphire/snowflake/dist/index.global.js
generated
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
var SapphireSnowflake = (() => {
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
||||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __reExport = (target, module, copyDefault, desc) => {
|
||||
if (module && typeof module === "object" || typeof module === "function") {
|
||||
for (let key of __getOwnPropNames(module))
|
||||
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
||||
__defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
|
||||
}
|
||||
return target;
|
||||
};
|
||||
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
||||
return (module, temp) => {
|
||||
return cache && cache.get(module) || (temp = __reExport(__markAsModule({}), module, 1), cache && cache.set(module, temp), temp);
|
||||
};
|
||||
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
||||
var __publicField = (obj, key, value) => {
|
||||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
||||
return value;
|
||||
};
|
||||
var __accessCheck = (obj, member, msg) => {
|
||||
if (!member.has(obj))
|
||||
throw TypeError("Cannot " + msg);
|
||||
};
|
||||
var __privateGet = (obj, member, getter) => {
|
||||
__accessCheck(obj, member, "read from private field");
|
||||
return getter ? getter.call(obj) : member.get(obj);
|
||||
};
|
||||
var __privateAdd = (obj, member, value) => {
|
||||
if (member.has(obj))
|
||||
throw TypeError("Cannot add the same private member more than once");
|
||||
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
||||
};
|
||||
var __privateSet = (obj, member, value, setter) => {
|
||||
__accessCheck(obj, member, "write to private field");
|
||||
setter ? setter.call(obj, value) : member.set(obj, value);
|
||||
return value;
|
||||
};
|
||||
var __privateWrapper = (obj, member, setter, getter) => {
|
||||
return {
|
||||
set _(value) {
|
||||
__privateSet(obj, member, value, setter);
|
||||
},
|
||||
get _() {
|
||||
return __privateGet(obj, member, getter);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// src/index.ts
|
||||
var src_exports = {};
|
||||
__export(src_exports, {
|
||||
DiscordSnowflake: () => DiscordSnowflake,
|
||||
Snowflake: () => Snowflake,
|
||||
TwitterSnowflake: () => TwitterSnowflake
|
||||
});
|
||||
|
||||
// src/lib/Snowflake.ts
|
||||
var ProcessId = 1n;
|
||||
var WorkerId = 0n;
|
||||
var _increment, _epoch;
|
||||
var Snowflake = class {
|
||||
constructor(epoch) {
|
||||
__privateAdd(this, _increment, 0n);
|
||||
__privateAdd(this, _epoch, void 0);
|
||||
__publicField(this, "decode", this.deconstruct);
|
||||
__privateSet(this, _epoch, BigInt(epoch instanceof Date ? epoch.getTime() : epoch));
|
||||
}
|
||||
get epoch() {
|
||||
return __privateGet(this, _epoch);
|
||||
}
|
||||
generate({ increment, timestamp = Date.now(), workerId = WorkerId, processId = ProcessId } = {}) {
|
||||
if (timestamp instanceof Date)
|
||||
timestamp = BigInt(timestamp.getTime());
|
||||
else if (typeof timestamp === "number")
|
||||
timestamp = BigInt(timestamp);
|
||||
else if (typeof timestamp !== "bigint") {
|
||||
throw new TypeError(`"timestamp" argument must be a number, bigint, or Date (received ${typeof timestamp})`);
|
||||
}
|
||||
if (typeof increment === "bigint" && increment >= 4095n)
|
||||
increment = 0n;
|
||||
else {
|
||||
increment = __privateWrapper(this, _increment)._++;
|
||||
if (__privateGet(this, _increment) >= 4095n)
|
||||
__privateSet(this, _increment, 0n);
|
||||
}
|
||||
return timestamp - __privateGet(this, _epoch) << 22n | (workerId & 0b11111n) << 17n | (processId & 0b11111n) << 12n | increment;
|
||||
}
|
||||
deconstruct(id) {
|
||||
const bigIntId = BigInt(id);
|
||||
return {
|
||||
id: bigIntId,
|
||||
timestamp: (bigIntId >> 22n) + __privateGet(this, _epoch),
|
||||
workerId: bigIntId >> 17n & 0b11111n,
|
||||
processId: bigIntId >> 12n & 0b11111n,
|
||||
increment: bigIntId & 0b111111111111n,
|
||||
epoch: __privateGet(this, _epoch)
|
||||
};
|
||||
}
|
||||
timestampFrom(id) {
|
||||
return Number((BigInt(id) >> 22n) + __privateGet(this, _epoch));
|
||||
}
|
||||
};
|
||||
__name(Snowflake, "Snowflake");
|
||||
_increment = new WeakMap();
|
||||
_epoch = new WeakMap();
|
||||
|
||||
// src/lib/DiscordSnowflake.ts
|
||||
var DiscordSnowflake = new Snowflake(1420070400000n);
|
||||
|
||||
// src/lib/TwitterSnowflake.ts
|
||||
var TwitterSnowflake = new Snowflake(1142974214000n);
|
||||
return __toCommonJS(src_exports);
|
||||
})();
|
||||
//# sourceMappingURL=index.global.js.map
|
||||
1
node_modules/@sapphire/snowflake/dist/index.global.js.map
generated
vendored
Normal file
1
node_modules/@sapphire/snowflake/dist/index.global.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
129
node_modules/@sapphire/snowflake/dist/index.js
generated
vendored
Normal file
129
node_modules/@sapphire/snowflake/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
||||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __reExport = (target, module2, copyDefault, desc) => {
|
||||
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
||||
for (let key of __getOwnPropNames(module2))
|
||||
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
||||
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
||||
}
|
||||
return target;
|
||||
};
|
||||
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
||||
return (module2, temp) => {
|
||||
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
||||
};
|
||||
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
||||
var __publicField = (obj, key, value) => {
|
||||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
||||
return value;
|
||||
};
|
||||
var __accessCheck = (obj, member, msg) => {
|
||||
if (!member.has(obj))
|
||||
throw TypeError("Cannot " + msg);
|
||||
};
|
||||
var __privateGet = (obj, member, getter) => {
|
||||
__accessCheck(obj, member, "read from private field");
|
||||
return getter ? getter.call(obj) : member.get(obj);
|
||||
};
|
||||
var __privateAdd = (obj, member, value) => {
|
||||
if (member.has(obj))
|
||||
throw TypeError("Cannot add the same private member more than once");
|
||||
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
||||
};
|
||||
var __privateSet = (obj, member, value, setter) => {
|
||||
__accessCheck(obj, member, "write to private field");
|
||||
setter ? setter.call(obj, value) : member.set(obj, value);
|
||||
return value;
|
||||
};
|
||||
var __privateWrapper = (obj, member, setter, getter) => {
|
||||
return {
|
||||
set _(value) {
|
||||
__privateSet(obj, member, value, setter);
|
||||
},
|
||||
get _() {
|
||||
return __privateGet(obj, member, getter);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// src/index.ts
|
||||
var src_exports = {};
|
||||
__export(src_exports, {
|
||||
DiscordSnowflake: () => DiscordSnowflake,
|
||||
Snowflake: () => Snowflake,
|
||||
TwitterSnowflake: () => TwitterSnowflake
|
||||
});
|
||||
|
||||
// src/lib/Snowflake.ts
|
||||
var ProcessId = 1n;
|
||||
var WorkerId = 0n;
|
||||
var _increment, _epoch;
|
||||
var Snowflake = class {
|
||||
constructor(epoch) {
|
||||
__privateAdd(this, _increment, 0n);
|
||||
__privateAdd(this, _epoch, void 0);
|
||||
__publicField(this, "decode", this.deconstruct);
|
||||
__privateSet(this, _epoch, BigInt(epoch instanceof Date ? epoch.getTime() : epoch));
|
||||
}
|
||||
get epoch() {
|
||||
return __privateGet(this, _epoch);
|
||||
}
|
||||
generate({ increment, timestamp = Date.now(), workerId = WorkerId, processId = ProcessId } = {}) {
|
||||
if (timestamp instanceof Date)
|
||||
timestamp = BigInt(timestamp.getTime());
|
||||
else if (typeof timestamp === "number")
|
||||
timestamp = BigInt(timestamp);
|
||||
else if (typeof timestamp !== "bigint") {
|
||||
throw new TypeError(`"timestamp" argument must be a number, bigint, or Date (received ${typeof timestamp})`);
|
||||
}
|
||||
if (typeof increment === "bigint" && increment >= 4095n)
|
||||
increment = 0n;
|
||||
else {
|
||||
increment = __privateWrapper(this, _increment)._++;
|
||||
if (__privateGet(this, _increment) >= 4095n)
|
||||
__privateSet(this, _increment, 0n);
|
||||
}
|
||||
return timestamp - __privateGet(this, _epoch) << 22n | (workerId & 0b11111n) << 17n | (processId & 0b11111n) << 12n | increment;
|
||||
}
|
||||
deconstruct(id) {
|
||||
const bigIntId = BigInt(id);
|
||||
return {
|
||||
id: bigIntId,
|
||||
timestamp: (bigIntId >> 22n) + __privateGet(this, _epoch),
|
||||
workerId: bigIntId >> 17n & 0b11111n,
|
||||
processId: bigIntId >> 12n & 0b11111n,
|
||||
increment: bigIntId & 0b111111111111n,
|
||||
epoch: __privateGet(this, _epoch)
|
||||
};
|
||||
}
|
||||
timestampFrom(id) {
|
||||
return Number((BigInt(id) >> 22n) + __privateGet(this, _epoch));
|
||||
}
|
||||
};
|
||||
__name(Snowflake, "Snowflake");
|
||||
_increment = new WeakMap();
|
||||
_epoch = new WeakMap();
|
||||
|
||||
// src/lib/DiscordSnowflake.ts
|
||||
var DiscordSnowflake = new Snowflake(1420070400000n);
|
||||
|
||||
// src/lib/TwitterSnowflake.ts
|
||||
var TwitterSnowflake = new Snowflake(1142974214000n);
|
||||
module.exports = __toCommonJS(src_exports);
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
DiscordSnowflake,
|
||||
Snowflake,
|
||||
TwitterSnowflake
|
||||
});
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@sapphire/snowflake/dist/index.js.map
generated
vendored
Normal file
1
node_modules/@sapphire/snowflake/dist/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
97
node_modules/@sapphire/snowflake/dist/index.mjs
generated
vendored
Normal file
97
node_modules/@sapphire/snowflake/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
var __defProp = Object.defineProperty;
|
||||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
var __publicField = (obj, key, value) => {
|
||||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
||||
return value;
|
||||
};
|
||||
var __accessCheck = (obj, member, msg) => {
|
||||
if (!member.has(obj))
|
||||
throw TypeError("Cannot " + msg);
|
||||
};
|
||||
var __privateGet = (obj, member, getter) => {
|
||||
__accessCheck(obj, member, "read from private field");
|
||||
return getter ? getter.call(obj) : member.get(obj);
|
||||
};
|
||||
var __privateAdd = (obj, member, value) => {
|
||||
if (member.has(obj))
|
||||
throw TypeError("Cannot add the same private member more than once");
|
||||
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
||||
};
|
||||
var __privateSet = (obj, member, value, setter) => {
|
||||
__accessCheck(obj, member, "write to private field");
|
||||
setter ? setter.call(obj, value) : member.set(obj, value);
|
||||
return value;
|
||||
};
|
||||
var __privateWrapper = (obj, member, setter, getter) => {
|
||||
return {
|
||||
set _(value) {
|
||||
__privateSet(obj, member, value, setter);
|
||||
},
|
||||
get _() {
|
||||
return __privateGet(obj, member, getter);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// src/lib/Snowflake.ts
|
||||
var ProcessId = 1n;
|
||||
var WorkerId = 0n;
|
||||
var _increment, _epoch;
|
||||
var Snowflake = class {
|
||||
constructor(epoch) {
|
||||
__privateAdd(this, _increment, 0n);
|
||||
__privateAdd(this, _epoch, void 0);
|
||||
__publicField(this, "decode", this.deconstruct);
|
||||
__privateSet(this, _epoch, BigInt(epoch instanceof Date ? epoch.getTime() : epoch));
|
||||
}
|
||||
get epoch() {
|
||||
return __privateGet(this, _epoch);
|
||||
}
|
||||
generate({ increment, timestamp = Date.now(), workerId = WorkerId, processId = ProcessId } = {}) {
|
||||
if (timestamp instanceof Date)
|
||||
timestamp = BigInt(timestamp.getTime());
|
||||
else if (typeof timestamp === "number")
|
||||
timestamp = BigInt(timestamp);
|
||||
else if (typeof timestamp !== "bigint") {
|
||||
throw new TypeError(`"timestamp" argument must be a number, bigint, or Date (received ${typeof timestamp})`);
|
||||
}
|
||||
if (typeof increment === "bigint" && increment >= 4095n)
|
||||
increment = 0n;
|
||||
else {
|
||||
increment = __privateWrapper(this, _increment)._++;
|
||||
if (__privateGet(this, _increment) >= 4095n)
|
||||
__privateSet(this, _increment, 0n);
|
||||
}
|
||||
return timestamp - __privateGet(this, _epoch) << 22n | (workerId & 0b11111n) << 17n | (processId & 0b11111n) << 12n | increment;
|
||||
}
|
||||
deconstruct(id) {
|
||||
const bigIntId = BigInt(id);
|
||||
return {
|
||||
id: bigIntId,
|
||||
timestamp: (bigIntId >> 22n) + __privateGet(this, _epoch),
|
||||
workerId: bigIntId >> 17n & 0b11111n,
|
||||
processId: bigIntId >> 12n & 0b11111n,
|
||||
increment: bigIntId & 0b111111111111n,
|
||||
epoch: __privateGet(this, _epoch)
|
||||
};
|
||||
}
|
||||
timestampFrom(id) {
|
||||
return Number((BigInt(id) >> 22n) + __privateGet(this, _epoch));
|
||||
}
|
||||
};
|
||||
__name(Snowflake, "Snowflake");
|
||||
_increment = new WeakMap();
|
||||
_epoch = new WeakMap();
|
||||
|
||||
// src/lib/DiscordSnowflake.ts
|
||||
var DiscordSnowflake = new Snowflake(1420070400000n);
|
||||
|
||||
// src/lib/TwitterSnowflake.ts
|
||||
var TwitterSnowflake = new Snowflake(1142974214000n);
|
||||
export {
|
||||
DiscordSnowflake,
|
||||
Snowflake,
|
||||
TwitterSnowflake
|
||||
};
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
1
node_modules/@sapphire/snowflake/dist/index.mjs.map
generated
vendored
Normal file
1
node_modules/@sapphire/snowflake/dist/index.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
8
node_modules/@sapphire/snowflake/dist/lib/DiscordSnowflake.d.ts
generated
vendored
Normal file
8
node_modules/@sapphire/snowflake/dist/lib/DiscordSnowflake.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Snowflake } from './Snowflake';
|
||||
/**
|
||||
* A class for parsing snowflake ids using Discord's snowflake epoch
|
||||
*
|
||||
* Which is 2015-01-01 at 00:00:00.000 UTC+0, {@linkplain https://discord.com/developers/docs/reference#snowflakes}
|
||||
*/
|
||||
export declare const DiscordSnowflake: Snowflake;
|
||||
//# sourceMappingURL=DiscordSnowflake.d.ts.map
|
||||
114
node_modules/@sapphire/snowflake/dist/lib/Snowflake.d.ts
generated
vendored
Normal file
114
node_modules/@sapphire/snowflake/dist/lib/Snowflake.d.ts
generated
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* A class for generating and deconstructing Twitter snowflakes.
|
||||
*
|
||||
* A {@link https://developer.twitter.com/en/docs/twitter-ids Twitter snowflake}
|
||||
* is a 64-bit unsigned integer with 4 fields that have a fixed epoch value.
|
||||
*
|
||||
* If we have a snowflake `266241948824764416` we can represent it as binary:
|
||||
* ```
|
||||
* 64 22 17 12 0
|
||||
* 000000111011000111100001101001000101000000 00001 00000 000000000000
|
||||
* number of ms since epoch worker pid increment
|
||||
* ```
|
||||
*/
|
||||
export declare class Snowflake {
|
||||
#private;
|
||||
/**
|
||||
* Alias for {@link deconstruct}
|
||||
*/
|
||||
decode: (id: string | bigint) => DeconstructedSnowflake;
|
||||
/**
|
||||
* @param epoch the epoch to use
|
||||
*/
|
||||
constructor(epoch: number | bigint | Date);
|
||||
/**
|
||||
* The epoch for this snowflake.
|
||||
*/
|
||||
get epoch(): bigint;
|
||||
/**
|
||||
* Generates a snowflake given an epoch and optionally a timestamp
|
||||
* @param options options to pass into the generator, see {@link SnowflakeGenerateOptions}
|
||||
*
|
||||
* **note** when `increment` is not provided it defaults to the private `increment` of the instance
|
||||
* @example
|
||||
* ```typescript
|
||||
* const epoch = new Date('2000-01-01T00:00:00.000Z');
|
||||
* const snowflake = new Snowflake(epoch).generate();
|
||||
* ```
|
||||
* @returns A unique snowflake
|
||||
*/
|
||||
generate({ increment, timestamp, workerId, processId }?: SnowflakeGenerateOptions): bigint;
|
||||
/**
|
||||
* Deconstructs a snowflake given a snowflake ID
|
||||
* @param id the snowflake to deconstruct
|
||||
* @returns a deconstructed snowflake
|
||||
* @example
|
||||
* ```typescript
|
||||
* const epoch = new Date('2000-01-01T00:00:00.000Z');
|
||||
* const snowflake = new Snowflake(epoch).deconstruct('3971046231244935168');
|
||||
* ```
|
||||
*/
|
||||
deconstruct(id: string | bigint): DeconstructedSnowflake;
|
||||
/**
|
||||
* Retrieves the timestamp field's value from a snowflake.
|
||||
* @param id The snowflake to get the timestamp value from.
|
||||
* @returns The UNIX timestamp that is stored in `id`.
|
||||
*/
|
||||
timestampFrom(id: string | bigint): number;
|
||||
}
|
||||
/**
|
||||
* Options for Snowflake#generate
|
||||
*/
|
||||
export interface SnowflakeGenerateOptions {
|
||||
/**
|
||||
* Timestamp or date of the snowflake to generate
|
||||
* @default Date.now()
|
||||
*/
|
||||
timestamp?: number | bigint | Date;
|
||||
/**
|
||||
* The increment to use
|
||||
* @default 0n
|
||||
* @remark keep in mind that this bigint is auto-incremented between generate calls
|
||||
*/
|
||||
increment?: bigint;
|
||||
/**
|
||||
* The worker ID to use, will be truncated to 5 bits (0-31)
|
||||
* @default 0n
|
||||
*/
|
||||
workerId?: bigint;
|
||||
/**
|
||||
* The process ID to use, will be truncated to 5 bits (0-31)
|
||||
* @default 1n
|
||||
*/
|
||||
processId?: bigint;
|
||||
}
|
||||
/**
|
||||
* Object returned by Snowflake#deconstruct
|
||||
*/
|
||||
export interface DeconstructedSnowflake {
|
||||
/**
|
||||
* The id in BigInt form
|
||||
*/
|
||||
id: bigint;
|
||||
/**
|
||||
* The timestamp stored in the snowflake
|
||||
*/
|
||||
timestamp: bigint;
|
||||
/**
|
||||
* The worker id stored in the snowflake
|
||||
*/
|
||||
workerId: bigint;
|
||||
/**
|
||||
* The process id stored in the snowflake
|
||||
*/
|
||||
processId: bigint;
|
||||
/**
|
||||
* The increment stored in the snowflake
|
||||
*/
|
||||
increment: bigint;
|
||||
/**
|
||||
* The epoch to use in the snowflake
|
||||
*/
|
||||
epoch: bigint;
|
||||
}
|
||||
//# sourceMappingURL=Snowflake.d.ts.map
|
||||
8
node_modules/@sapphire/snowflake/dist/lib/TwitterSnowflake.d.ts
generated
vendored
Normal file
8
node_modules/@sapphire/snowflake/dist/lib/TwitterSnowflake.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Snowflake } from './Snowflake';
|
||||
/**
|
||||
* A class for parsing snowflake ids using Twitter's snowflake epoch
|
||||
*
|
||||
* 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}
|
||||
*/
|
||||
export declare const TwitterSnowflake: Snowflake;
|
||||
//# sourceMappingURL=TwitterSnowflake.d.ts.map
|
||||
55
node_modules/@sapphire/snowflake/package.json
generated
vendored
Normal file
55
node_modules/@sapphire/snowflake/package.json
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"name": "@sapphire/snowflake",
|
||||
"version": "3.2.0",
|
||||
"description": "Deconstructs and generates snoflake IDs using BigInts",
|
||||
"author": "@sapphire",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.mjs",
|
||||
"browser": "dist/index.global.js",
|
||||
"unpkg": "dist/index.global.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"typedocMain": "src/index.ts",
|
||||
"exports": {
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/snowflake",
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
|
||||
"build": "tsup && tsc -b src",
|
||||
"prepublishOnly": "yarn build"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sapphiredev/utilities.git",
|
||||
"directory": "packages/snowflake"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"!dist/*.tsbuildinfo"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=v14.0.0",
|
||||
"npm": ">=7.0.0"
|
||||
},
|
||||
"keywords": [
|
||||
"@sapphire/snowflake",
|
||||
"bot",
|
||||
"typescript",
|
||||
"ts",
|
||||
"yarn",
|
||||
"discord",
|
||||
"sapphire",
|
||||
"standalone"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/sapphiredev/utilities/issues"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user