Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

detritus-utils

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

detritus-utils - npm Package Compare versions

Comparing version 0.0.5 to 0.1.0

lib/constants.d.ts

334

lib/constants.js

@@ -1,326 +0,8 @@

module.exports = {
Discord: {
ActivityActionTypes: {
JOIN: 1,
SPECTATE: 2,
LISTEN: 3,
WATCH: 4,
JOIN_REQUEST: 5
},
ActivityFlags: {
INSTANCE: 1 << 0,
JOIN: 1 << 1,
SPECTATE: 1 << 2,
JOIN_REQUEST: 1 << 3,
SYNC: 1 << 4,
PLAY: 1 << 5
},
ActivityTypes: {
PLAYING: 0,
STREAMING: 1,
LISTENING: 2,
WATCHING: 3
},
AllowedEncodings: {
ETF: 'etf',
JSON: 'json'
},
ChannelTypes: {
BASE: -1,
GUILD_TEXT: 0,
DM: 1,
GUILD_VOICE: 2,
GROUP_DM: 3,
GUILD_CATEGORY: 4
},
EmbedTypes: {
ARTICLE: 'article',
GIFV: 'gifv',
IMAGE: 'image',
LINK: 'link',
RICH: 'rich',
TWEET: 'tweet',
VIDEO: 'video'
},
Epoch: {
SNOWFLAKE: 1420070400000,
TOKEN: 1293840000
},
ExplicitContentFilterTypes: {
DISABLED: 0,
NON_FRIENDS: 1,
FRIENDS_AND_NON_FRIENDS: 2
},
LibraryApplicationFlags: {
HIDDEN: 1,
PRIVATE: 2,
OVERLAY_DISABLED: 4
},
LobbyTypes: {
PRIVATE: 1,
PUBLIC: 2
},
LobbyErrors: {
NO_ERROR: 0,
UNKNOWN_ERROR: 1,
SERVICE_UNAVAILABLE: 2,
NOT_FOUND: 3,
INVALID_SECRET: 4,
FULL: 5,
LOBBY_LIMIT_REACHED: 6
},
MFALevels: {
NONE: 0,
ELEVATED: 1
},
MessageTypes: {
BASE: -1,
DEFAULT: 0,
RECIPIENT_ADD: 1,
RECIPIENT_REMOVE: 2,
CALL: 3,
CHANNEL_NAME_CHANGE: 4,
CHANNEL_ICON_CHANGE: 5,
CHANNEL_PINNED_MESSAGE: 6,
GUILD_MEMBER_JOIN: 7
},
OpCodes: {
Gateway: {
DISPATCH: 0,
HEARTBEAT: 1,
IDENTIFY: 2,
STATUS_UPDATE: 3,
VOICE_STATE_UPDATE: 4,
VOICE_SERVER_PING: 5,
RESUME: 6,
RECONNECT: 7,
REQUEST_GUILD_MEMBERS: 8,
INVALID_SESSION: 9,
HELLO: 10,
HEARTBEAT_ACK: 11,
SYNC_GUILD: 12,
CALL_CONNECT: 13,
GUILD_SUBSCRIPTION: 14
},
Voice: {
IDENTIFY: 0,
SELECT_PROTOCOL: 1,
READY: 2,
HEARTBEAT: 3,
SESSION_DESCRIPTION: 4,
SPEAKING: 5,
HEARTBEAT_ACK: 6,
RESUME: 7,
HELLO: 8,
RESUMED: 9,
SIGNAL: 10,
CLIENT_CONNECT: 12,
CLIENT_DISCONNECT: 13,
CODECS: 14
}
},
RoleColors: {
DEFAULT: 10070709,
LIGHT_GREEN: 3066993,
MEDIUM_GREEN: 1752220,
DARK_GREEN: 2067276,
DARKER_GREEN: 1146986,
LIGHT_TEAL: 3447003,
DARK_TEAL: 2123412,
LIGHT_PURPLE: 10181046,
DARK_PURPLE: 7419530,
LIGHT_RED: 15277667,
DARK_RED: 11342935,
LIGHT_YELLOW: 15844367,
DARK_YELLOW: 12745742,
LIGHT_PEACH: 15105570,
DARK_PEACH: 11027200,
LIGHT_ORANGE: 15158332,
DARK_ORANGE: 10038562,
LIGHT_GREY: 9807270,
DARK_GREY: 9936031,
LIGHT_GRAYPLE: 6323595,
DARK_GRAYPLE: 5533306
},
PaymentStatusTypes: {
PENDING: 0,
COMPLETED: 1,
FAILED: 2,
REVERSED: 3,
REFUNDED: 4
},
Permissions: {
CREATE_INSTANT_INVITES: 1 << 0,
KICK_MEMBERS: 1 << 1,
BAN_MEMBERS: 1 << 2,
ADMINISTRATOR: 1 << 3,
MANAGE_CHANNELS: 1 << 4,
MANAGE_GUILD: 1 << 5,
ADD_REACTIONS: 1 << 6,
VIEW_AUDIT_LOGS: 1 << 7,
VIEW_CHANNEL: 1 << 10,
SEND_MESSAGES: 1 << 11,
SEND_TTS_MESSAGES: 1 << 12,
MANAGE_MESSAGES: 1 << 13,
EMBED_LINKS: 1 << 14,
ATTACH_FILES: 1 << 15,
READ_MESSAGE_HISTORY: 1 << 16,
MENTION_EVERYONE: 1 << 17,
EXTERNAL_EMOJIS: 1 << 18,
VOICE_CONNECT: 1 << 20,
VOICE_SPEAK: 1 << 21,
VOICE_MUTE_MEMBERS: 1 << 22,
VOICE_DEAFEN_MEMBERS: 1 << 23,
VOICE_MOVE_MEMBERS: 1 << 24,
VOICE_USE_VAD: 1 << 25,
CHANGE_NICKNAME: 1 << 26,
MANAGE_NICKNAMES: 1 << 27,
MANAGE_ROLES: 1 << 28,
MANAGE_WEBHOOKS: 1 << 29,
MANAGE_EMOJIS: 1 << 30
},
PremiumStatusTypes: {
UNPAID: 0,
ACTIVE: 1,
PAST_DUE: 2,
CANCELED: 3
},
ProviderIds: {
BATTLENET: 'battlenet',
FACEBOOK: 'facebook',
LEAGUE_OF_LEGENDS: 'leagueoflegends',
REDDIT: 'reddit',
SKYPE: 'skype',
SPOTIFY: 'spotify',
STEAM: 'steam',
TWITCH: 'twitch',
TWITTER: 'twitter',
XBOX: 'xbox',
YOUTUBE: 'youtube'
},
Regex: {
EMOJI: /<a?:(\w+):(\d+)>/,
MENTION_CHANNEL: /<#(\d+)>/,
MENTION_ROLE: /<@&(\d+)>/,
MENTION_USER: /<@!?(\d+)>$/,
TEXT_BOLD: /\*\*([\s\S]+?)\*\*/,
TEXT_CODEBLOCK: /```(([A-z0-9-]+?)\n+)?\n*([^]+?)\n*```/,
TEXT_CODESTRING: /`([\s\S]+?)`/,
TEXT_ITALICS: /_([\s\S]+?)_|\*([\s\S]+?)\*/,
TEXT_SNOWFLAKE: /(\d+)/,
TEXT_STRIKE: /~~([\s\S]+?)~~(?!_)/,
TEXT_UNDERLINE: /__([\s\S]+?)__/,
TEXT_URL: /((?:https?|steam):\/\/[^\s<]+[^<.,:;"'\]\s])/
},
Relationships: {
NONE: 0,
FRIEND: 1,
BLOCKED: 2,
PENDING_INCOMING: 3,
PENDING_OUTGOING: 4,
IMPLICIT: 5
},
SpeakingFlags: {
NONE: 0,
VOICE: 1 << 0,
SOUNDSHARE: 1 << 1
},
Status: {
ONLINE: 'online',
DND: 'dnd',
IDLE: 'idle',
INVISIBLE: 'invisible',
OFFLINE: 'offline'
},
SystemMessages: {
CallMissed: 'You missed a call from :user:.',
CallStarted: ':user: started a call.',
ChannelIconChange: ':user: changed the channel name: **:name:**',
ChannelNameChange: ':user: changed the channel icon.',
PinnedMessage: ':user: pinned a message to this channel.',
RecipientAdd: ':user: added :user2: to the group.',
RecipientRemove: ':user: removed :user2: from the group.',
RecipientRemoveSelf: ':user: left the group.',
GuildMemberJoin: [
":user: just joined the server - glhf!",
":user: just joined. Everyone, look busy!",
":user: just joined. Can I get a heal?",
":user: joined your party.",
":user: joined. You must construct additional pylons.",
"Ermagherd. :user: is here.",
"Welcome, :user:. Stay awhile and listen.",
"Welcome, :user:. We were expecting you ( ͡° ͜ʖ ͡°)",
"Welcome, :user:. We hope you brought pizza.",
"Welcome :user:. Leave your weapons by the door.",
"A wild :user: appeared.",
"Swoooosh. :user: just landed.",
"Brace yourselves. :user: just joined the server.",
":user: just joined. Hide your bananas.",
":user: just arrived. Seems OP - please nerf.",
":user: just slid into the server.",
"A :user: has spawned in the server.",
"Big :user: showed up!",
"Where’s :user:? In the server!",
":user: hopped into the server. Kangaroo!!",
":user: just showed up. Hold my beer.",
"Challenger approaching - :user: has appeared!",
"It's a bird! It's a plane! Nevermind, it's just :user:.",
"It's :user:! Praise the sun! \\\\[T]/",
"Never gonna give :user: up. Never gonna let :user: down.",
"Ha! :user: has joined! You activated my trap card!",
"Cheers, love! :user:'s here!",
"Hey! Listen! :user: has joined!",
"We've been expecting you :user:",
"It's dangerous to go alone, take :user:!",
":user: has joined the server! It's super effective!",
"Cheers, love! :user: is here!",
":user: is here, as the prophecy foretold.",
":user: has arrived. Party's over.",
"Ready player :user:",
":user: is here to kick butt and chew bubblegum. And :user: is all out of gum.",
"Hello. Is it :user: you're looking for?",
":user: has joined. Stay a while and listen!",
"Roses are red, violets are blue, :user: joined this server with you",
]
},
UserFlags: {
STAFF: 1 << 0,
PARTNER: 1 << 1,
HYPESQUAD: 1 << 2,
BUG_HUNTER: 1 << 3,
MFA_SMS: 1 << 4,
PREMIUM_PROMO_DISMISSED: 1 << 5
},
VerificationLevels: {
NONE: 0,
LOW: 1,
MEDIUM: 2,
HIGH: 3,
VERY_HIGH: 4
},
Voice: {
Opus: {
SAMPLE_RATE: 48000,
CHANNELS: 2
}
}
},
Encoders: {
Opus: {
Applications: {
VOIP: 2048,
AUDIO: 2049,
RESTRICTED_LOWDELAY: 2051
},
CTL: {
BITRATE: 4002,
FEC: 4012,
PLP: 4014
},
SAMPLE_RATES: [8000, 12000, 16000, 24000, 48000]
}
}
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Package = Object.freeze({
URL: 'https://github.com/detritusjs/utils',
VERSION: '0.1.0',
});
exports.DISCORD_SNOWFLAKE_EPOCH = 1420070400000;
exports.DISCORD_TOKEN_EPOCH = 1293840000000;

@@ -1,8 +0,21 @@

let emitter;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
let Emitter = require('events').EventEmitter;
try {
emitter = require('eventemitter3');
} catch(e) {
emitter = require('events').EventEmitter;
Emitter = require('eventemitter3');
}
module.exports = emitter;
catch (e) { }
class EventEmitter extends Emitter {
constructor() {
super();
Object.defineProperties(this, {
_events: { enumerable: false },
_eventsCount: { enumerable: false },
_maxListeners: { enumerable: false },
});
}
hasEventListener(name) {
return this._events && (name in this._events);
}
}
exports.EventEmitter = EventEmitter;

@@ -1,10 +0,12 @@

module.exports = {
AudioFormat: require('./audioformat'),
Buckets: require('./buckets'),
Constants: require('./constants'),
Encoders: require('./encoders'),
EventEmitter: require('./eventemitter'),
Permissions: require('./permissions'),
Snowflake: require('./snowflake'),
Tools: require('./tools')
};
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
const Constants = require("./constants");
exports.Constants = Constants;
const Snowflake = require("./snowflake");
exports.Snowflake = Snowflake;
const Timers = require("./timers");
exports.Timers = Timers;
__export(require("./eventemitter"));

@@ -1,95 +0,109 @@

const Epoch = require('./constants').Discord.Epoch;
const bits = {
workerId: 5,
processId: 5,
sequence: 12
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("./constants");
const bits = Object.freeze({
processId: 5,
workerId: 5,
sequence: 12,
});
const max = Object.freeze({
timestamp: 0x40000000000,
middle: -1 ^ (-1 << (bits.workerId + bits.processId + bits.sequence)),
processId: -1 ^ (-1 << bits.processId),
sequence: -1 ^ (-1 << bits.sequence),
workerId: -1 ^ (-1 << bits.workerId),
});
const cache = {
sequence: 0,
};
const max = {
timestamp: 0x40000000000,
workerId: -1 ^ (-1 << bits.workerId),
processId: -1 ^ (-1 << bits.processId),
sequence: -1 ^ (-1 << bits.sequence),
middle: -1 ^ (-1 << (bits.workerId + bits.processId + bits.sequence))
};
const cache = {sequence: 0};
const defaults = {
epoch: Epoch.SNOWFLAKE,
workerId: 0,
processId: 0
};
module.exports = {
generate(options) {
options = Object.assign({timestamp: Date.now()}, defaults, options);
const snowflake = {id: ''};
snowflake.timestamp = (options.timestamp - options.epoch) % max.timestamp;
snowflake.workerId = options.workerId & max.workerId;
snowflake.processId = options.processId & max.processId;
if (options.sequence === undefined) {
snowflake.sequence = cache.sequence = ++cache.sequence & max.sequence;
} else {
snowflake.sequence = options.sequence & max.sequence;
}
let timestamp = snowflake.timestamp.toString(2).padStart(42, '0');
let workerId = snowflake.workerId.toString(2).padStart(5, '0');
let processId = snowflake.processId.toString(2).padStart(5, '0');
let sequence = snowflake.sequence.toString(2).padStart(12, '0');
let binary = snowflake.binary = timestamp + workerId + processId + sequence;
//thanks discord.js
while (binary.length > 50) {
const high = parseInt(binary.slice(0, -32), 2);
const low = parseInt((high % 10).toString(2) + binary.slice(-32), 2);
snowflake.id = (low % 10).toString() + snowflake.id;
binary = Math.floor(high / 10).toString(2) + Math.floor(low / 10).toString(2).padStart(32, '0');
}
binary = parseInt(binary, 2);
while (binary > 0) {
snowflake.id = (binary % 10).toString() + snowflake.id;
binary = Math.floor(binary / 10);
}
return snowflake;
},
deconstruct(id, options) {
options = Object.assign({epoch: defaults.epoch}, options);
const snowflake = {id};
snowflake.binary = '';
//thanks discord.js
let high = parseInt(id.slice(0, -10)) || 0;
let low = parseInt(id.slice(-10));
while (low > 0 || high > 0) {
snowflake.binary = (low & 1).toString() + snowflake.binary;
low = Math.floor(low / 2);
if (high > 0) {
low += 5000000000 * (high % 2);
high = Math.floor(high / 2);
}
}
snowflake.binary = snowflake.binary.toString(2).padStart(64, '0');
snowflake.timestamp = parseInt(snowflake.binary.slice(0, 42), 2) + options.epoch;
snowflake.workerId = parseInt(snowflake.binary.slice(42, 47), 2);
snowflake.processId = parseInt(snowflake.binary.slice(47, 52), 2);
snowflake.sequence = parseInt(snowflake.binary.slice(52, 64), 2);
return snowflake;
},
timestamp(id, options) {
options = Object.assign({epoch: defaults.epoch}, options);
return (id) ? parseInt((+id / max.middle) + options.epoch) : 0;
}
};
function generate(options = {}) {
options = Object.assign({}, options);
if (options.epoch === undefined) {
options.epoch = constants_1.DISCORD_SNOWFLAKE_EPOCH;
}
if (options.processId === undefined) {
options.processId = 0;
}
if (options.timestamp === undefined) {
options.timestamp = Date.now();
}
if (options.workerId === undefined) {
options.workerId = 0;
}
const snowflake = {
binary: '',
id: '',
processId: options.processId & max.processId,
sequence: 0,
timestamp: (options.timestamp - options.epoch) % max.timestamp,
workerId: options.workerId & max.workerId,
};
if (options.sequence === undefined) {
snowflake.sequence = cache.sequence = ++cache.sequence & max.sequence;
}
else {
snowflake.sequence = options.sequence & max.sequence;
}
let processId = snowflake.processId.toString(2).padStart(5, '0');
let sequence = snowflake.sequence.toString(2).padStart(12, '0');
let timestamp = snowflake.timestamp.toString(2).padStart(42, '0');
let workerId = snowflake.workerId.toString(2).padStart(5, '0');
let binary = snowflake.binary = timestamp + workerId + processId + sequence;
//thanks discord.js
while (binary.length > 50) {
const high = parseInt(binary.slice(0, -32), 2);
const low = parseInt((high % 10).toString(2) + binary.slice(-32), 2);
snowflake.id = (low % 10).toString() + snowflake.id;
binary = Math.floor(high / 10).toString(2) + Math.floor(low / 10).toString(2).padStart(32, '0');
}
let binaryNumber = parseInt(binary, 2);
while (0 < binaryNumber) {
snowflake.id = (binaryNumber % 10).toString() + snowflake.id;
binaryNumber = Math.floor(binaryNumber / 10);
}
return snowflake;
}
exports.generate = generate;
function deconstruct(id, options = {}) {
options = Object.assign({}, options);
if (options.epoch === undefined) {
options.epoch = constants_1.DISCORD_SNOWFLAKE_EPOCH;
}
const snowflake = {
binary: '',
id,
processId: 0,
sequence: 0,
timestamp: 0,
workerId: 0,
};
//thanks discord.js
let high = parseInt(id.slice(0, -10)) || 0;
let low = parseInt(id.slice(-10));
while (low > 0 || high > 0) {
snowflake.binary = (low & 1).toString() + snowflake.binary;
low = Math.floor(low / 2);
if (high > 0) {
low += 5000000000 * (high % 2);
high = Math.floor(high / 2);
}
}
snowflake.binary = snowflake.binary.padStart(64, '0');
snowflake.timestamp = parseInt(snowflake.binary.slice(0, 42), 2) + options.epoch;
snowflake.workerId = parseInt(snowflake.binary.slice(42, 47), 2);
snowflake.processId = parseInt(snowflake.binary.slice(47, 52), 2);
snowflake.sequence = parseInt(snowflake.binary.slice(52, 64), 2);
return snowflake;
}
exports.deconstruct = deconstruct;
function timestamp(id, options = {}) {
options = Object.assign({}, options);
if (options.epoch === undefined) {
options.epoch = constants_1.DISCORD_SNOWFLAKE_EPOCH;
}
if (id) {
return Math.round((parseInt(id) / max.middle) + options.epoch);
}
return 0;
}
exports.timestamp = timestamp;
{
"name": "detritus-utils",
"version": "0.0.5",
"description": "all of detritus's reused util things",
"main": "./lib/index.js",
"directories": {
"lib": "lib"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/detritusjs/utils.git"
},
"keywords": [
"nodejs",
"discord",
"utils"
],
"author": "cakedan",
"license": "MIT",
"bugs": {
"url": "https://github.com/detritusjs/utils/issues"
},
"homepage": "https://github.com/detritusjs/utils#readme",
"dependencies": {},
"devDependencies": {},
"peerDependencies": {}
}
"name": "detritus-utils",
"version": "0.1.0",
"description": "Detritus Utils",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib/**/*"
],
"dependencies": {},
"devDependencies": {
"@types/node": "^12.0.10"
},
"peerDependencies": {
"eventemitter3": "^4.0.0"
},
"scripts": {
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "npm run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/detritusjs/utils.git"
},
"keywords": [
"rest",
"detritus",
"nodejs",
"typescript",
"discord",
"utils"
],
"author": "cakedan",
"license": "MIT",
"bugs": {
"url": "https://github.com/detritusjs/utils/issues"
},
"homepage": "https://github.com/detritusjs/utils#readme"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc