Skip to content

Commit

Permalink
Require Node.js 12
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 28, 2021
1 parent 43b6deb commit d0776b4
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 52 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto eol=lf
*.psd binary
1 change: 0 additions & 1 deletion .github/funding.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
- 10
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
4 changes: 2 additions & 2 deletions examples/clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ function onTick({duration}) {
}
}

function onError(err) {
function onError(error) {
process.exitCode = 1;
console.error(err);
console.error(error);
stop();
}

Expand Down
4 changes: 2 additions & 2 deletions examples/clocktyped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ function onTick({duration}: TickData) {
}
}

function onError(err: Error) {
function onError(error: Error) {
process.exitCode = 1;
console.error(err);
console.error(error);
stop();
}

Expand Down
57 changes: 38 additions & 19 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-redeclare */

/**
Emittery accepts strings and symbols as event names.
Expand All @@ -17,7 +19,7 @@ type OmnipresentEventData = {[listenerAdded]: Emittery.ListenerChangedData; [lis
/**
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 for more information on how debugging works.
*/
Expand All @@ -34,14 +36,17 @@ interface DebugOptions<EventData> {
@example
```
const Emittery = require('emittery');
import Emittery = require('emittery');
Emittery.isDebugEnabled = true;
const emitter = new Emittery({debug: {name: 'myEmitter'}});
emitter.on('test', data => { // do something });
emitter.emit('test');
emitter.on('test', data => {
// …
});
emitter.emit('test');
//=> [16:43:20.417][emittery:subscribe][myEmitter] Event Name: test
// data: undefined
```
Expand All @@ -55,19 +60,24 @@ interface DebugOptions<EventData> {
@example
```
const Emittery = require('emittery');
import Emittery = require('emittery');
const emitter1 = new Emittery({debug: {name: 'emitter1', enabled: true}});
const emitter2 = new Emittery({debug: {name: 'emitter2'}});
emitter1.on('test', data => { // do something });
emitter2.on('test', data => { // do something });
emitter1.on('test', data => {
// …
});
emitter1.emit('test');
emitter2.emit('test');
emitter2.on('test', data => {
// …
});
emitter1.emit('test');
//=> [16:43:20.417][emittery:subscribe][emitter1] Event Name: test
// data: undefined
emitter2.emit('test');
```
*/
enabled?: boolean;
Expand All @@ -92,7 +102,8 @@ interface DebugOptions<EventData> {
@example
```
const Emittery = require('emittery');
import Emittery = require('emittery');
const myLogger = (type, debugName, eventName, eventData) => console.log(`[${type}]: ${eventName}`);
const emitter = new Emittery({
Expand All @@ -103,10 +114,11 @@ interface DebugOptions<EventData> {
}
});
emitter.on('test', data => { // do something });
emitter.on('test', data => {
// …
});
emitter.emit('test');
//=> [subscribe]: test
```
*/
Expand Down Expand Up @@ -159,25 +171,30 @@ declare class Emittery<
/**
Toggle debug mode for all instances.
@default Returns true if the DEBUG environment variable is set to 'emittery' or '*', otherwise false.
Default: `true` if the `DEBUG` environment variable is set to `emittery` or `*`, otherwise `false`.
@example
```
const Emittery = require('emittery');
import Emittery = require('emittery');
Emittery.isDebugEnabled = true;
const emitter1 = new Emittery({debug: {name: 'myEmitter1'}});
const emitter2 = new Emittery({debug: {name: 'myEmitter2'}});
emitter1.on('test', data => { // do something });
emitter2.on('otherTest', data => { // do something });
emitter1.on('test', data => {
// …
});
emitter2.on('otherTest', data => {
// …
});
emitter1.emit('test');
emitter2.emit('otherTest');
//=> [16:43:20.417][emittery:subscribe][myEmitter1] Event Name: test
// data: undefined
emitter2.emit('otherTest');
//=> [16:43:20.417][emittery:subscribe][myEmitter2] Event Name: otherTest
// data: undefined
```
Expand Down Expand Up @@ -268,7 +285,7 @@ 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 (): any}>(klass: T) => T; // eslint-disable-line @typescript-eslint/prefer-function-type

/**
Subscribe to one or more events.
Expand All @@ -286,6 +303,7 @@ declare class Emittery<
emitter.on('🦄', data => {
console.log(data);
});
emitter.on(['🦄', '🐶'], data => {
console.log(data);
});
Expand Down Expand Up @@ -430,6 +448,7 @@ declare class Emittery<
console.log(data);
//=> '🌈'
});
emitter.once(['🦄', '🐶']).then(data => {
console.log(data);
});
Expand Down
4 changes: 2 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars, @typescript-eslint/no-floating-promises */
import {expectType, expectError, expectNotAssignable, expectAssignable} from 'tsd';
import pEvent = require('p-event');
import Emittery = require('.');
import Emittery = require('./index.js');

type AnyListener = (eventData?: unknown) => void | Promise<void>;

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=10"
"node": ">=12"
},
"scripts": {
"test": "xo && nyc ava && tsd"
Expand Down Expand Up @@ -48,13 +48,13 @@
"typed"
],
"devDependencies": {
"@types/node": "^13.7.5",
"@types/node": "^15.6.1",
"ava": "^2.4.0",
"delay": "^4.3.0",
"nyc": "^15.0.0",
"p-event": "^4.1.0",
"tsd": "^0.14.0",
"xo": "^0.36.1"
"tsd": "^0.16.0",
"xo": "^0.39.0"
},
"nyc": {
"reporter": [
Expand Down
48 changes: 33 additions & 15 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Symbol event names can be used to avoid name collisions when your classes are ex

Toggle debug mode for all instances.

Default: Returns true if the DEBUG environment variable is set to 'emittery' or '*', otherwise false.
Default: `true` if the `DEBUG` environment variable is set to `emittery` or `*`, otherwise `false`.

Example:

Expand All @@ -60,15 +60,19 @@ Emittery.isDebugEnabled = true;
const emitter1 = new Emittery({debug: {name: 'myEmitter1'}});
const emitter2 = new Emittery({debug: {name: 'myEmitter2'}});

emitter1.on('test', data => { // do something });
emitter2.on('otherTest', data => { // do something });
emitter1.on('test', data => {
//
});

emitter1.emit('test');
emitter2.emit('otherTest');
emitter2.on('otherTest', data => {
//
});

emitter1.emit('test');
//=> [16:43:20.417][emittery:subscribe][myEmitter1] Event Name: test
// data: undefined

emitter2.emit('otherTest');
//=> [16:43:20.417][emittery:subscribe][myEmitter2] Event Name: otherTest
// data: undefined
```
Expand All @@ -79,10 +83,14 @@ Create a new instance of Emittery.

#### options?

Type: `object`

Configure the new instance of Emittery.

##### debug?

Type: `objcect`

Configure the debugging options for this instance.

###### name
Expand All @@ -100,18 +108,19 @@ const Emittery = require('emittery');
Emittery.isDebugEnabled = true;

const emitter = new Emittery({debug: {name: 'myEmitter'}});
emitter.on('test', data => { // do something });

emitter.emit('test');
emitter.on('test', data => {
//
});

emitter.emit('test');
//=> [16:43:20.417][emittery:subscribe][myEmitter] Event Name: test
// data: undefined
```

###### enabled?

Type: `boolean`
Type: `boolean`\
Default: `false`

Toggle debug logging just for this instance.
Expand All @@ -124,14 +133,19 @@ const Emittery = require('emittery');
const emitter1 = new Emittery({debug: {name: 'emitter1', enabled: true}});
const emitter2 = new Emittery({debug: {name: 'emitter2'}});

emitter1.on('test', data => { // do something });
emitter2.on('test', data => { // do something });
emitter1.on('test', data => {
//
});

emitter1.emit('test');
emitter2.emit('test');
emitter2.on('test', data => {
//
});

emitter1.emit('test');
//=> [16:43:20.417][emittery:subscribe][emitter1] Event Name: test
// data: undefined

emitter2.emit('test');
```

###### logger?
Expand Down Expand Up @@ -173,10 +187,11 @@ const emitter = new Emittery({
}
});

emitter.on('test', data => { // do something });
emitter.on('test', data => {
//
});

emitter.emit('test');

//=> [subscribe]: test
```

Expand All @@ -196,6 +211,7 @@ const emitter = new Emittery();
emitter.on('🦄', data => {
console.log(data);
});

emitter.on(['🦄', '🐶'], data => {
console.log(data);
});
Expand Down Expand Up @@ -248,6 +264,7 @@ const Emittery = require('emittery');
const emitter = new Emittery();

const listener = data => console.log(data);

(async () => {
emitter.on(['🦄', '🐶', '🦊'], listener);
await emitter.emit('🦄', 'a');
Expand Down Expand Up @@ -278,6 +295,7 @@ emitter.once('🦄').then(data => {
console.log(data);
//=> '🌈'
});

emitter.once(['🦄', '🐶']).then(data => {
console.log(data);
});
Expand Down
Loading

0 comments on commit d0776b4

Please sign in to comment.