Socket
Socket
Sign inDemoInstall

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.2.3 to 0.2.4

2

lib/constants.js

@@ -5,5 +5,5 @@ "use strict";

URL: 'https://github.com/detritusjs/utils',
VERSION: '0.2.3',
VERSION: '0.2.4',
});
exports.DISCORD_SNOWFLAKE_EPOCH = 1420070400000;
exports.DISCORD_TOKEN_EPOCH = 1293840000000;

@@ -8,6 +8,15 @@ /// <reference types="node" />

*/
_events: any;
_events: {
[key: string]: any;
} | undefined;
/**
* @ignore
*/
_subscriptions: Array<EventSubscription> | undefined;
constructor();
hasEventListener(name: string): boolean;
subscribe(event: string | symbol, listener: (...args: any[]) => void): EventSubscription;
hasEventListener(name: string | symbol): boolean;
subscribe(name: string | symbol, listener: (...args: any[]) => void): EventSubscription;
removeSubscription(subscription: EventSubscription): void;
removeAllListeners(name: string | symbol | undefined): this;
removeAllSubscriptions(): this;
}

@@ -14,0 +23,0 @@ export declare class EventSubscription {

@@ -12,2 +12,6 @@ "use strict";

super();
/**
* @ignore
*/
this._subscriptions = undefined;
Object.defineProperties(this, {

@@ -17,2 +21,3 @@ _events: { enumerable: false },

_maxListeners: { enumerable: false },
_subscriptions: { enumerable: false },
});

@@ -23,7 +28,62 @@ }

}
subscribe(event, listener) {
const subscription = new EventSubscription(this, event, listener);
this.on(event, listener);
subscribe(name, listener) {
const subscription = new EventSubscription(this, name, listener);
this.on(name, listener);
if (!this._subscriptions) {
this._subscriptions = [];
}
this._subscriptions.push(subscription);
return subscription;
}
removeSubscription(subscription) {
if (subscription.listener) {
this.removeListener(subscription.name, subscription.listener);
}
if (this._subscriptions) {
const index = this._subscriptions.indexOf(subscription);
if (index !== 1) {
if (this._subscriptions.length === 1) {
this._subscriptions.pop();
}
else {
this._subscriptions.splice(index, 1);
}
}
if (!this._subscriptions.length) {
this._subscriptions = undefined;
}
}
}
removeAllListeners(name) {
if (this._subscriptions) {
if (name !== undefined) {
for (let subscription of this._subscriptions) {
if (subscription.name === name) {
subscription.remove();
}
}
}
else {
while (this._subscriptions.length) {
const subscription = this._subscriptions.shift();
if (subscription) {
subscription.listener = null;
subscription.spewer = null;
}
}
}
}
return super.removeAllListeners(name);
}
removeAllSubscriptions() {
if (this._subscriptions) {
while (this._subscriptions.length) {
const subscription = this._subscriptions.shift();
if (subscription) {
subscription.remove();
}
}
}
return this;
}
}

@@ -38,4 +98,4 @@ exports.EventSpewer = EventSpewer;

remove() {
if (this.listener && this.spewer) {
this.spewer.removeListener(this.name, this.listener);
if (this.spewer) {
this.spewer.removeSubscription(this);
}

@@ -42,0 +102,0 @@ this.listener = null;

{
"name": "detritus-utils",
"version": "0.2.3",
"version": "0.2.4",
"description": "Detritus Utils",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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