Bump packages to fix linter

This commit is contained in:
Henry Mercer 2023-01-18 20:50:03 +00:00
parent ed9506bbaf
commit 0a11e3fdd9
6063 changed files with 378752 additions and 306784 deletions

188
node_modules/emittery/index.d.ts generated vendored
View file

@ -1,11 +1,9 @@
/* eslint-disable no-redeclare */
/**
Emittery accepts strings, symbols, and numbers as event names.
Symbol event names are preferred given that they can be used to avoid name collisions when your classes are extended, especially for internal events.
*/
type EventName = PropertyKey;
export type EventName = PropertyKey;
// Helper type for turning the passed `EventData` type map into a list of string keys that don't require data alongside the event name when emitting. Uses the same trick that `Omit` does internally to filter keys by building a map of keys to keys we want to keep, and then accessing all the keys to return just the list of keys we want to keep.
type DatalessEventNames<EventData> = {
@ -14,7 +12,7 @@ type DatalessEventNames<EventData> = {
declare const listenerAdded: unique symbol;
declare const listenerRemoved: unique symbol;
type _OmnipresentEventData = {[listenerAdded]: Emittery.ListenerChangedData; [listenerRemoved]: Emittery.ListenerChangedData};
type OmnipresentEventData = {[listenerAdded]: ListenerChangedData; [listenerRemoved]: ListenerChangedData};
/**
Emittery can collect and log debug information.
@ -23,12 +21,12 @@ To enable this feature set the `DEBUG` environment variable to `emittery` or `*`
See API for more information on how debugging works.
*/
type DebugLogger<EventData, Name extends keyof EventData> = (type: string, debugName: string, eventName?: Name, eventData?: EventData[Name]) => void;
export type DebugLogger<EventData, Name extends keyof EventData> = (type: string, debugName: string, eventName?: Name, eventData?: EventData[Name]) => void;
/**
Configure debug options of an instance.
*/
interface DebugOptions<EventData> {
export type DebugOptions<EventData> = {
/**
Define a name for the instance of Emittery to use when outputting debug data.
@ -36,7 +34,7 @@ interface DebugOptions<EventData> {
@example
```
import Emittery = require('emittery');
import Emittery from 'emittery';
Emittery.isDebugEnabled = true;
@ -60,7 +58,7 @@ interface DebugOptions<EventData> {
@example
```
import Emittery = require('emittery');
import Emittery from 'emittery';
const emitter1 = new Emittery({debug: {name: 'emitter1', enabled: true}});
const emitter2 = new Emittery({debug: {name: 'emitter2'}});
@ -80,7 +78,7 @@ interface DebugOptions<EventData> {
emitter2.emit('test');
```
*/
enabled?: boolean;
readonly enabled?: boolean;
/**
Function that handles debug data.
@ -102,9 +100,11 @@ interface DebugOptions<EventData> {
@example
```
import Emittery = require('emittery');
import Emittery from 'emittery';
const myLogger = (type, debugName, eventName, eventData) => console.log(`[${type}]: ${eventName}`);
const myLogger = (type, debugName, eventName, eventData) => {
console.log(`[${type}]: ${eventName}`);
};
const emitter = new Emittery({
debug: {
@ -122,15 +122,42 @@ interface DebugOptions<EventData> {
//=> [subscribe]: test
```
*/
logger?: DebugLogger<EventData, keyof EventData>;
}
readonly logger?: DebugLogger<EventData, keyof EventData>;
};
/**
Configuration options for Emittery.
*/
interface Options<EventData> {
debug?: DebugOptions<EventData>;
}
export type Options<EventData> = {
readonly debug?: DebugOptions<EventData>;
};
/**
A promise returned from `emittery.once` with an extra `off` method to cancel your subscription.
*/
export type EmitteryOncePromise<T> = {
off(): void;
} & Promise<T>;
/**
Removes an event subscription.
*/
export type UnsubscribeFunction = () => void;
/**
The data provided as `eventData` when listening for `Emittery.listenerAdded` or `Emittery.listenerRemoved`.
*/
export type ListenerChangedData = {
/**
The listener that was added or removed.
*/
listener: (eventData?: unknown) => (void | Promise<void>);
/**
The name of the event that was added or removed if `.on()` or `.off()` was used, or `undefined` if `.onAny()` or `.offAny()` was used.
*/
eventName?: EventName;
};
/**
Emittery is a strictly typed, fully async EventEmitter implementation. Event listeners can be registered with `on` or `once`, and events can be emitted with `emit`.
@ -139,7 +166,7 @@ Emittery is a strictly typed, fully async EventEmitter implementation. Event lis
@example
```
import Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery<
// Pass `{[eventName: <string | symbol | number>]: undefined | <eventArg>}` as the first type argument for events that pass data to their listeners.
@ -163,10 +190,10 @@ emitter.emit('open', 1);
emitter.emit('other');
```
*/
declare class Emittery<
EventData = Record<EventName, any>,
AllEventData = EventData & _OmnipresentEventData,
DatalessEvents = DatalessEventNames<EventData>
export default class Emittery<
EventData = Record<EventName, any>, // TODO: Use `unknown` instead of `any`.
AllEventData = EventData & OmnipresentEventData,
DatalessEvents = DatalessEventNames<EventData>,
> {
/**
Toggle debug mode for all instances.
@ -175,7 +202,7 @@ declare class Emittery<
@example
```
import Emittery = require('emittery');
import Emittery from 'emittery';
Emittery.isDebugEnabled = true;
@ -208,7 +235,7 @@ declare class Emittery<
@example
```
import Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery();
@ -234,7 +261,7 @@ declare class Emittery<
@example
```
import Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery();
@ -255,24 +282,12 @@ declare class Emittery<
*/
static readonly listenerRemoved: typeof listenerRemoved;
/**
Debugging options for the current instance.
*/
debug: DebugOptions<EventData>;
/**
Create a new Emittery instance with the specified options.
@returns An instance of Emittery that you can use to listen for and emit events.
*/
constructor(options?: Options<EventData>);
/**
In TypeScript, it returns a decorator which mixins `Emittery` as property `emitteryPropertyName` and `methodNames`, or all `Emittery` methods if `methodNames` is not defined, into the target class.
@example
```
import Emittery = require('emittery');
import Emittery from 'emittery';
@Emittery.mixin('emittery')
class MyClass {}
@ -285,7 +300,19 @@ declare class Emittery<
static mixin(
emitteryPropertyName: string | symbol,
methodNames?: readonly string[]
): <T extends {new (): any}>(klass: T) => T; // eslint-disable-line @typescript-eslint/prefer-function-type
): <T extends {new (...arguments_: readonly any[]): any}>(klass: T) => T; // eslint-disable-line @typescript-eslint/prefer-function-type
/**
Debugging options for the current instance.
*/
debug: DebugOptions<EventData>;
/**
Create a new Emittery instance with the specified options.
@returns An instance of Emittery that you can use to listen for and emit events.
*/
constructor(options?: Options<EventData>);
/**
Subscribe to one or more events.
@ -296,7 +323,7 @@ declare class Emittery<
@example
```
import Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery();
@ -313,9 +340,9 @@ declare class Emittery<
```
*/
on<Name extends keyof AllEventData>(
eventName: Name | Name[],
eventName: Name | readonly Name[],
listener: (eventData: AllEventData[Name]) => void | Promise<void>
): Emittery.UnsubscribeFn;
): UnsubscribeFunction;
/**
Get an async iterator which buffers data each time an event is emitted.
@ -324,7 +351,7 @@ declare class Emittery<
@example
```
import Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery();
const iterator = emitter.events('🦄');
@ -354,7 +381,7 @@ declare class Emittery<
@example
```
import Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery();
const iterator = emitter.events('🦄');
@ -374,7 +401,7 @@ declare class Emittery<
@example
```
import Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery();
const iterator = emitter.events(['🦄', '🦊']);
@ -401,7 +428,7 @@ declare class Emittery<
```
*/
events<Name extends keyof EventData>(
eventName: Name | Name[]
eventName: Name | readonly Name[]
): AsyncIterableIterator<EventData[Name]>;
/**
@ -409,26 +436,27 @@ declare class Emittery<
@example
```
import Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery();
const listener = data => console.log(data);
(async () => {
emitter.on(['🦄', '🐶', '🦊'], listener);
await emitter.emit('🦄', 'a');
await emitter.emit('🐶', 'b');
await emitter.emit('🦊', 'c');
emitter.off('🦄', listener);
emitter.off(['🐶', '🦊'], listener);
await emitter.emit('🦄', 'a'); // nothing happens
await emitter.emit('🐶', 'b'); // nothing happens
await emitter.emit('🦊', 'c'); // nothing happens
})();
const listener = data => {
console.log(data);
};
emitter.on(['🦄', '🐶', '🦊'], listener);
await emitter.emit('🦄', 'a');
await emitter.emit('🐶', 'b');
await emitter.emit('🦊', 'c');
emitter.off('🦄', listener);
emitter.off(['🐶', '🦊'], listener);
await emitter.emit('🦄', 'a'); // nothing happens
await emitter.emit('🐶', 'b'); // nothing happens
await emitter.emit('🦊', 'c'); // nothing happens
```
*/
off<Name extends keyof AllEventData>(
eventName: Name | Name[],
eventName: Name | readonly Name[],
listener: (eventData: AllEventData[Name]) => void | Promise<void>
): void;
@ -436,11 +464,11 @@ declare class Emittery<
Subscribe to one or more events only once. It will be unsubscribed after the first
event.
@returns The event data when `eventName` is emitted.
@returns The promise of event data when `eventName` is emitted. This promise is extended with an `off` method.
@example
```
import Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery();
@ -457,7 +485,7 @@ declare class Emittery<
emitter.emit('🐶', '🍖'); // Nothing happens
```
*/
once<Name extends keyof AllEventData>(eventName: Name | Name[]): Promise<AllEventData[Name]>;
once<Name extends keyof AllEventData>(eventName: Name | readonly Name[]): EmitteryOncePromise<AllEventData[Name]>;
/**
Trigger an event asynchronously, optionally with some data. Listeners are called in the order they were added, but executed concurrently.
@ -493,7 +521,7 @@ declare class Emittery<
eventName: keyof EventData,
eventData: EventData[keyof EventData]
) => void | Promise<void>
): Emittery.UnsubscribeFn;
): UnsubscribeFunction;
/**
Get an async iterator which buffers a tuple of an event name and data each time an event is emitted.
@ -504,7 +532,7 @@ declare class Emittery<
@example
```
import Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery();
const iterator = emitter.anyEvent();
@ -548,19 +576,19 @@ declare class Emittery<
If `eventName` is given, only the listeners for that event are cleared.
*/
clearListeners<Name extends keyof EventData>(eventName?: Name | Name[]): void;
clearListeners<Name extends keyof EventData>(eventName?: Name | readonly Name[]): void;
/**
The number of listeners for the `eventName` or all events if not specified.
*/
listenerCount<Name extends keyof EventData>(eventName?: Name | Name[]): number;
listenerCount<Name extends keyof EventData>(eventName?: Name | readonly Name[]): number;
/**
Bind the given `methodNames`, or all `Emittery` methods if `methodNames` is not defined, into the `target` object.
@example
```
import Emittery = require('emittery');
import Emittery from 'emittery';
const object = {};
@ -571,29 +599,3 @@ declare class Emittery<
*/
bindMethods(target: Record<string, unknown>, methodNames?: readonly string[]): void;
}
declare namespace Emittery {
/**
Removes an event subscription.
*/
type UnsubscribeFn = () => void;
/**
The data provided as `eventData` when listening for `Emittery.listenerAdded` or `Emittery.listenerRemoved`.
*/
interface ListenerChangedData {
/**
The listener that was added or removed.
*/
listener: (eventData?: unknown) => void | Promise<void>;
/**
The name of the event that was added or removed if `.on()` or `.off()` was used, or `undefined` if `.onAny()` or `.offAny()` was used.
*/
eventName?: EventName;
}
type OmnipresentEventData = _OmnipresentEventData;
}
export = Emittery;

199
node_modules/emittery/index.js generated vendored
View file

@ -1,8 +1,5 @@
'use strict';
import {anyMap, producersMap, eventsMap} from './maps.js';
const anyMap = new WeakMap();
const eventsMap = new WeakMap();
const producersMap = new WeakMap();
const anyProducer = Symbol('anyProducer');
const resolvedPromise = Promise.resolve();
@ -10,19 +7,13 @@ const resolvedPromise = Promise.resolve();
const listenerAdded = Symbol('listenerAdded');
const listenerRemoved = Symbol('listenerRemoved');
// Define a symbol that allows internal code to emit meta events, but prevents userland from doing so.
const metaEventsAllowed = Symbol('metaEventsAllowed');
let canEmitMetaEvents = false;
let isGlobalDebugEnabled = false;
function assertEventName(eventName, allowMetaEvents) {
function assertEventName(eventName) {
if (typeof eventName !== 'string' && typeof eventName !== 'symbol' && typeof eventName !== 'number') {
throw new TypeError('`eventName` must be a string, symbol, or number');
}
if (isMetaEvent(eventName) && allowMetaEvents !== metaEventsAllowed) {
throw new TypeError('`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`');
}
}
function assertListener(listener) {
@ -34,7 +25,7 @@ function assertListener(listener) {
function getListeners(instance, eventName) {
const events = eventsMap.get(instance);
if (!events.has(eventName)) {
events.set(eventName, new Set());
return;
}
return events.get(eventName);
@ -44,7 +35,7 @@ function getEventProducers(instance, eventName) {
const key = typeof eventName === 'string' || typeof eventName === 'symbol' || typeof eventName === 'number' ? eventName : anyProducer;
const producers = producersMap.get(instance);
if (!producers.has(key)) {
producers.set(key, new Set());
return;
}
return producers.get(key);
@ -81,11 +72,18 @@ function iterator(instance, eventNames) {
finish() {
isFinished = true;
flush();
}
},
};
for (const eventName of eventNames) {
getEventProducers(instance, eventName).add(producer);
let set = getEventProducers(instance, eventName);
if (!set) {
set = new Set();
const producers = producersMap.get(instance);
producers.set(eventName, set);
}
set.add(producer);
}
return {
@ -109,7 +107,7 @@ function iterator(instance, eventNames) {
return {
done: false,
value: await queue.shift()
value: await queue.shift(),
};
},
@ -117,19 +115,26 @@ function iterator(instance, eventNames) {
queue = undefined;
for (const eventName of eventNames) {
getEventProducers(instance, eventName).delete(producer);
const set = getEventProducers(instance, eventName);
if (set) {
set.delete(producer);
if (set.size === 0) {
const producers = producersMap.get(instance);
producers.delete(eventName);
}
}
}
flush();
return arguments.length > 0 ?
{done: true, value: await value} :
{done: true};
return arguments.length > 0
? {done: true, value: await value}
: {done: true};
},
[Symbol.asyncIterator]() {
return this;
}
},
};
}
@ -157,7 +162,18 @@ function defaultMethodNamesOrAssert(methodNames) {
const isMetaEvent = eventName => eventName === listenerAdded || eventName === listenerRemoved;
class Emittery {
function emitMetaEvent(emitter, eventName, eventData) {
if (isMetaEvent(eventName)) {
try {
canEmitMetaEvents = true;
emitter.emit(eventName, eventData);
} finally {
canEmitMetaEvents = false;
}
}
}
export default class Emittery {
static mixin(emitteryPropertyName, methodNames) {
methodNames = defaultMethodNamesOrAssert(methodNames);
return target => {
@ -174,14 +190,14 @@ class Emittery {
function getEmitteryProperty() {
Object.defineProperty(this, emitteryPropertyName, {
enumerable: false,
value: new Emittery()
value: new Emittery(),
});
return this[emitteryPropertyName];
}
Object.defineProperty(target.prototype, emitteryPropertyName, {
enumerable: false,
get: getEmitteryProperty
get: getEmitteryProperty,
});
const emitteryMethodCaller = methodName => function (...args) {
@ -191,7 +207,7 @@ class Emittery {
for (const methodName of methodNames) {
Object.defineProperty(target.prototype, methodName, {
enumerable: false,
value: emitteryMethodCaller(methodName)
value: emitteryMethodCaller(methodName),
});
}
@ -200,11 +216,15 @@ class Emittery {
}
static get isDebugEnabled() {
if (typeof process !== 'object') {
// In a browser environment, `globalThis.process` can potentially reference a DOM Element with a `#process` ID,
// so instead of just type checking `globalThis.process`, we need to make sure that `globalThis.process.env` exists.
// eslint-disable-next-line n/prefer-global/process
if (typeof globalThis.process?.env !== 'object') {
return isGlobalDebugEnabled;
}
const {env} = process || {env: {}};
// eslint-disable-next-line n/prefer-global/process
const {env} = globalThis.process ?? {env: {}};
return env.DEBUG === 'emittery' || env.DEBUG === '*' || isGlobalDebugEnabled;
}
@ -216,7 +236,10 @@ class Emittery {
anyMap.set(this, new Set());
eventsMap.set(this, new Map());
producersMap.set(this, new Map());
this.debug = options.debug || {};
producersMap.get(this).set(anyProducer, new Set());
this.debug = options.debug ?? {};
if (this.debug.enabled === undefined) {
this.debug.enabled = false;
@ -253,13 +276,20 @@ class Emittery {
eventNames = Array.isArray(eventNames) ? eventNames : [eventNames];
for (const eventName of eventNames) {
assertEventName(eventName, metaEventsAllowed);
getListeners(this, eventName).add(listener);
assertEventName(eventName);
let set = getListeners(this, eventName);
if (!set) {
set = new Set();
const events = eventsMap.get(this);
events.set(eventName, set);
}
set.add(listener);
this.logIfDebugEnabled('subscribe', eventName, undefined);
if (!isMetaEvent(eventName)) {
this.emit(listenerAdded, {eventName, listener}, metaEventsAllowed);
emitMetaEvent(this, listenerAdded, {eventName, listener});
}
}
@ -271,43 +301,59 @@ class Emittery {
eventNames = Array.isArray(eventNames) ? eventNames : [eventNames];
for (const eventName of eventNames) {
assertEventName(eventName, metaEventsAllowed);
getListeners(this, eventName).delete(listener);
assertEventName(eventName);
const set = getListeners(this, eventName);
if (set) {
set.delete(listener);
if (set.size === 0) {
const events = eventsMap.get(this);
events.delete(eventName);
}
}
this.logIfDebugEnabled('unsubscribe', eventName, undefined);
if (!isMetaEvent(eventName)) {
this.emit(listenerRemoved, {eventName, listener}, metaEventsAllowed);
emitMetaEvent(this, listenerRemoved, {eventName, listener});
}
}
}
once(eventNames) {
return new Promise(resolve => {
const off = this.on(eventNames, data => {
off();
let off_;
const promise = new Promise(resolve => {
off_ = this.on(eventNames, data => {
off_();
resolve(data);
});
});
promise.off = off_;
return promise;
}
events(eventNames) {
eventNames = Array.isArray(eventNames) ? eventNames : [eventNames];
for (const eventName of eventNames) {
assertEventName(eventName, metaEventsAllowed);
assertEventName(eventName);
}
return iterator(this, eventNames);
}
async emit(eventName, eventData, allowMetaEvents) {
assertEventName(eventName, allowMetaEvents);
async emit(eventName, eventData) {
assertEventName(eventName);
if (isMetaEvent(eventName) && !canEmitMetaEvents) {
throw new TypeError('`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`');
}
this.logIfDebugEnabled('emit', eventName, eventData);
enqueueProducers(this, eventName, eventData);
const listeners = getListeners(this, eventName);
const listeners = getListeners(this, eventName) ?? new Set();
const anyListeners = anyMap.get(this);
const staticListeners = [...listeners];
const staticAnyListeners = isMetaEvent(eventName) ? [] : [...anyListeners];
@ -323,16 +369,20 @@ class Emittery {
if (anyListeners.has(listener)) {
return listener(eventName, eventData);
}
})
}),
]);
}
async emitSerial(eventName, eventData, allowMetaEvents) {
assertEventName(eventName, allowMetaEvents);
async emitSerial(eventName, eventData) {
assertEventName(eventName);
if (isMetaEvent(eventName) && !canEmitMetaEvents) {
throw new TypeError('`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`');
}
this.logIfDebugEnabled('emitSerial', eventName, eventData);
const listeners = getListeners(this, eventName);
const listeners = getListeners(this, eventName) ?? new Set();
const anyListeners = anyMap.get(this);
const staticListeners = [...listeners];
const staticAnyListeners = [...anyListeners];
@ -359,7 +409,7 @@ class Emittery {
this.logIfDebugEnabled('subscribeAny', undefined, undefined);
anyMap.get(this).add(listener);
this.emit(listenerAdded, {listener}, metaEventsAllowed);
emitMetaEvent(this, listenerAdded, {listener});
return this.offAny.bind(this, listener);
}
@ -372,7 +422,7 @@ class Emittery {
this.logIfDebugEnabled('unsubscribeAny', undefined, undefined);
this.emit(listenerRemoved, {listener}, metaEventsAllowed);
emitMetaEvent(this, listenerRemoved, {listener});
anyMap.get(this).delete(listener);
}
@ -383,29 +433,35 @@ class Emittery {
this.logIfDebugEnabled('clear', eventName, undefined);
if (typeof eventName === 'string' || typeof eventName === 'symbol' || typeof eventName === 'number') {
getListeners(this, eventName).clear();
const set = getListeners(this, eventName);
if (set) {
set.clear();
}
const producers = getEventProducers(this, eventName);
for (const producer of producers) {
producer.finish();
}
producers.clear();
} else {
anyMap.get(this).clear();
for (const listeners of eventsMap.get(this).values()) {
listeners.clear();
}
for (const producers of producersMap.get(this).values()) {
if (producers) {
for (const producer of producers) {
producer.finish();
}
producers.clear();
}
} else {
anyMap.get(this).clear();
for (const [eventName, listeners] of eventsMap.get(this).entries()) {
listeners.clear();
eventsMap.get(this).delete(eventName);
}
for (const [eventName, producers] of producersMap.get(this).entries()) {
for (const producer of producers) {
producer.finish();
}
producers.clear();
producersMap.get(this).delete(eventName);
}
}
}
}
@ -416,13 +472,16 @@ class Emittery {
for (const eventName of eventNames) {
if (typeof eventName === 'string') {
count += anyMap.get(this).size + getListeners(this, eventName).size +
getEventProducers(this, eventName).size + getEventProducers(this).size;
count += anyMap.get(this).size
+ (getListeners(this, eventName)?.size ?? 0)
+ (getEventProducers(this, eventName)?.size ?? 0)
+ (getEventProducers(this)?.size ?? 0);
continue;
}
if (typeof eventName !== 'undefined') {
assertEventName(eventName, metaEventsAllowed);
assertEventName(eventName);
}
count += anyMap.get(this).size;
@ -453,7 +512,7 @@ class Emittery {
Object.defineProperty(target, methodName, {
enumerable: false,
value: this[methodName].bind(this)
value: this[methodName].bind(this),
});
}
}
@ -465,13 +524,11 @@ Object.defineProperty(Emittery, 'listenerAdded', {
value: listenerAdded,
writable: false,
enumerable: true,
configurable: false
configurable: false,
});
Object.defineProperty(Emittery, 'listenerRemoved', {
value: listenerRemoved,
writable: false,
enumerable: true,
configurable: false
configurable: false,
});
module.exports = Emittery;

3
node_modules/emittery/maps.js generated vendored Normal file
View file

@ -0,0 +1,3 @@
export const anyMap = new WeakMap();
export const eventsMap = new WeakMap();
export const producersMap = new WeakMap();

24
node_modules/emittery/package.json generated vendored
View file

@ -1,6 +1,6 @@
{
"name": "emittery",
"version": "0.11.0",
"version": "1.0.1",
"description": "Simple and modern async event emitter",
"license": "MIT",
"repository": "sindresorhus/emittery",
@ -10,15 +10,19 @@
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"types": "./index.d.ts",
"engines": {
"node": ">=12"
"node": ">=14.16"
},
"scripts": {
"test": "xo && nyc ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
"index.d.ts",
"maps.js"
],
"keywords": [
"event",
@ -48,13 +52,13 @@
"typed"
],
"devDependencies": {
"@types/node": "^15.6.1",
"ava": "^2.4.0",
"delay": "^4.3.0",
"nyc": "^15.0.0",
"p-event": "^4.1.0",
"tsd": "^0.19.1",
"xo": "^0.39.0"
"@types/node": "^18.7.15",
"ava": "^4.3.3",
"delay": "^5.0.0",
"nyc": "^15.1.0",
"p-event": "^5.0.1",
"tsd": "^0.23.0",
"xo": "^0.52.3"
},
"nyc": {
"reporter": [

70
node_modules/emittery/readme.md generated vendored
View file

@ -2,7 +2,7 @@
> Simple and modern async event emitter
[![Coverage Status](https://codecov.io/gh/sindresorhus/emittery/branch/main/graph/badge.svg)](https://codecov.io/gh/sindresorhus/emittery)
<!-- [![Coverage Status](https://codecov.io/gh/sindresorhus/emittery/branch/main/graph/badge.svg)](https://codecov.io/gh/sindresorhus/emittery) -->
[![](https://badgen.net/bundlephobia/minzip/emittery)](https://bundlephobia.com/result?p=emittery)
It works in Node.js and the browser (using a bundler).
@ -11,14 +11,14 @@ Emitting events asynchronously is important for production code where you want t
## Install
```
$ npm install emittery
```sh
npm install emittery
```
## Usage
```js
const Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery();
@ -53,7 +53,7 @@ Default: `true` if the `DEBUG` environment variable is set to `emittery` or `*`,
Example:
```js
const Emittery = require('emittery');
import Emittery from 'emittery';
Emittery.isDebugEnabled = true;
@ -103,7 +103,7 @@ Define a name for the instance of Emittery to use when outputting debug data.
Example:
```js
const Emittery = require('emittery');
import Emittery from 'emittery';
Emittery.isDebugEnabled = true;
@ -128,7 +128,7 @@ Toggle debug logging just for this instance.
Example:
```js
const Emittery = require('emittery');
import Emittery from 'emittery';
const emitter1 = new Emittery({debug: {name: 'emitter1', enabled: true}});
const emitter2 = new Emittery({debug: {name: 'emitter2'}});
@ -175,9 +175,11 @@ Function that handles debug data.
Example:
```js
const Emittery = require('emittery');
import Emittery from 'emittery';
const myLogger = (type, debugName, eventName, eventData) => console.log(`[${type}]: ${eventName}`);
const myLogger = (type, debugName, eventName, eventData) => {
console.log(`[${type}]: ${eventName}`);
};
const emitter = new Emittery({
debug: {
@ -204,7 +206,7 @@ Returns an unsubscribe method.
Using the same listener multiple times for the same event will result in only one method call per emitted event.
```js
const Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery();
@ -228,7 +230,7 @@ Emittery exports some symbols which represent "meta" events that can be passed t
- `Emittery.listenerRemoved` - Fires when an event listener was removed.
```js
const Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery();
@ -259,23 +261,23 @@ Only events that are not of this type are able to trigger these events.
Remove one or more event subscriptions.
```js
const Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery();
const listener = data => console.log(data);
const listener = data => {
console.log(data);
};
(async () => {
emitter.on(['🦄', '🐶', '🦊'], listener);
await emitter.emit('🦄', 'a');
await emitter.emit('🐶', 'b');
await emitter.emit('🦊', 'c');
emitter.off('🦄', listener);
emitter.off(['🐶', '🦊'], listener);
await emitter.emit('🦄', 'a'); // Nothing happens
await emitter.emit('🐶', 'b'); // Nothing happens
await emitter.emit('🦊', 'c'); // Nothing happens
})();
emitter.on(['🦄', '🐶', '🦊'], listener);
await emitter.emit('🦄', 'a');
await emitter.emit('🐶', 'b');
await emitter.emit('🦊', 'c');
emitter.off('🦄', listener);
emitter.off(['🐶', '🦊'], listener);
await emitter.emit('🦄', 'a'); // Nothing happens
await emitter.emit('🐶', 'b'); // Nothing happens
await emitter.emit('🦊', 'c'); // Nothing happens
```
##### listener(data)
@ -284,10 +286,10 @@ const listener = data => console.log(data);
Subscribe to one or more events only once. It will be unsubscribed after the first event.
Returns a promise for the event data when `eventName` is emitted.
Returns a promise for the event data when `eventName` is emitted. This promise is extended with an `off` method.
```js
const Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery();
@ -311,7 +313,7 @@ Get an async iterator which buffers data each time an event is emitted.
Call `return()` on the iterator to remove the subscription.
```js
const Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery();
const iterator = emitter.events('🦄');
@ -340,7 +342,7 @@ iterator
In practice, you would usually consume the events using the [for await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of) statement. In that case, to revoke the subscription simply break the loop.
```js
const Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery();
const iterator = emitter.events('🦄');
@ -359,7 +361,7 @@ for await (const data of iterator) {
It accepts multiple event names.
```js
const Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery();
const iterator = emitter.events(['🦄', '🦊']);
@ -416,7 +418,7 @@ Get an async iterator which buffers a tuple of an event name and data each time
Call `return()` on the iterator to remove the subscription.
```js
const Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery();
const iterator = emitter.anyEvent();
@ -458,7 +460,7 @@ The number of listeners for the `eventNames` or all events if not specified.
Bind the given `methodNames`, or all `Emittery` methods if `methodNames` is not defined, into the `target` object.
```js
import Emittery = require('emittery');
import Emittery from 'emittery';
const object = {};
@ -472,7 +474,7 @@ object.emit('event');
The default `Emittery` class has generic types that can be provided by TypeScript users to strongly type the list of events and the data passed to their event listeners.
```ts
import Emittery = require('emittery');
import Emittery from 'emittery';
const emitter = new Emittery<
// Pass `{[eventName]: undefined | <eventArg>}` as the first type argument for events that pass data to their listeners.
@ -501,7 +503,7 @@ emitter.emit('other');
A decorator which mixins `Emittery` as property `emitteryPropertyName` and `methodNames`, or all `Emittery` methods if `methodNames` is not defined, into the target class.
```ts
import Emittery = require('emittery');
import Emittery from 'emittery';
@Emittery.mixin('emittery')
class MyClass {}
@ -521,7 +523,7 @@ Note that when using `.emitSerial()`, a slow listener will delay invocation of s
Emittery can collect and log debug information.
To enable this feature set the DEBUG environment variable to 'emittery' or '*'. Additionally you can set the static `isDebugEnabled` variable to true on the Emittery class, or `myEmitter.debug.enabled` on an instance of it for debugging a single instance.
To enable this feature set the DEBUG environment variable to `'emittery'` or `'*'`. Additionally you can set the static `isDebugEnabled` variable to true on the Emittery class, or `myEmitter.debug.enabled` on an instance of it for debugging a single instance.
See [API](#api) for more details on how debugging works.