mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 04:53:30 +01:00
Detardify snowflake docs/organisation
This commit is contained in:
@@ -4,20 +4,10 @@ const Long = require('long');
|
|||||||
const EPOCH = 1420070400000;
|
const EPOCH = 1420070400000;
|
||||||
let INCREMENT = 0;
|
let INCREMENT = 0;
|
||||||
|
|
||||||
function pad(v, n, c = '0') {
|
/**
|
||||||
return String(v).length >= n ? String(v) : (String(c).repeat(n) + v).slice(-n);
|
* A container for useful snowflake-related methods
|
||||||
}
|
*/
|
||||||
|
class Snowflake {
|
||||||
/**
|
|
||||||
* A deconstructed snowflake
|
|
||||||
* @typedef {Object} DeconstructedSnowflake
|
|
||||||
* @property {Date} date Date in the snowflake
|
|
||||||
* @property {number} workerID Worker id in the snowflake
|
|
||||||
* @property {number} processID Process id in the snowflake
|
|
||||||
* @property {number} increment Increment in the snowflake
|
|
||||||
* @property {string} binary Binary representation of the snowflake
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Twitter snowflake, except the epoch is 2015-01-01T00:00:00.000Z
|
* A Twitter snowflake, except the epoch is 2015-01-01T00:00:00.000Z
|
||||||
* ```
|
* ```
|
||||||
@@ -29,9 +19,8 @@ function pad(v, n, c = '0') {
|
|||||||
* ```
|
* ```
|
||||||
* Note: this generator hardcodes the worker id as 1 and the process id as 0
|
* Note: this generator hardcodes the worker id as 1 and the process id as 0
|
||||||
* @typedef {string} Snowflake
|
* @typedef {string} Snowflake
|
||||||
* @class Snowflake
|
|
||||||
*/
|
*/
|
||||||
class Snowflake {
|
|
||||||
/**
|
/**
|
||||||
* Generate a Discord snowflake
|
* Generate a Discord snowflake
|
||||||
* @returns {Snowflake} The generated snowflake
|
* @returns {Snowflake} The generated snowflake
|
||||||
@@ -42,6 +31,16 @@ class Snowflake {
|
|||||||
return Long.fromString(BINARY, 2).toString();
|
return Long.fromString(BINARY, 2).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A deconstructed snowflake
|
||||||
|
* @typedef {Object} DeconstructedSnowflake
|
||||||
|
* @property {Date} date Date in the snowflake
|
||||||
|
* @property {number} workerID Worker id in the snowflake
|
||||||
|
* @property {number} processID Process id in the snowflake
|
||||||
|
* @property {number} increment Increment in the snowflake
|
||||||
|
* @property {string} binary Binary representation of the snowflake
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deconstruct a Discord snowflake
|
* Deconstruct a Discord snowflake
|
||||||
* @param {Snowflake} snowflake Snowflake to deconstruct
|
* @param {Snowflake} snowflake Snowflake to deconstruct
|
||||||
@@ -59,4 +58,8 @@ class Snowflake {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pad(v, n, c = '0') {
|
||||||
|
return String(v).length >= n ? String(v) : (String(c).repeat(n) + v).slice(-n);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Snowflake;
|
module.exports = Snowflake;
|
||||||
|
|||||||
Reference in New Issue
Block a user