Skip to content

Commit

Permalink
Require Node.js 14 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Sep 6, 2022
1 parent 5d814d9 commit 3b7db43
Show file tree
Hide file tree
Showing 13 changed files with 348 additions and 318 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/main.yml
Expand Up @@ -10,15 +10,16 @@ jobs:
fail-fast: false
matrix:
node-version:
- 18
- 16
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
- uses: codecov/codecov-action@v1
if: matrix.node-version == 14
with:
fail_ci_if_error: true
# - uses: codecov/codecov-action@v3
# if: matrix.node-version == 16
# with:
# fail_ci_if_error: true
5 changes: 2 additions & 3 deletions examples/clock.js
@@ -1,7 +1,6 @@
#!/usr/bin/env node
'use strict';

const Emittery = require('..');
import process from 'node:process';
import Emittery from '../index.js';

class Clock extends Emittery {
constructor() {
Expand Down
12 changes: 7 additions & 5 deletions examples/clocktyped.ts
@@ -1,11 +1,13 @@
#!/usr/bin/env npx ts-node
import {setInterval} from 'timers';
import Emittery = require('..');
/* eslint-disable @typescript-eslint/no-floating-promises */
import process from 'node:process';
import {setInterval} from 'node:timers';
import Emittery from '../index.js';

interface TickData {
type TickData = {
now: number;
duration: number;
}
};

// Map Clock's events emitting data to the type of their data.
type EventDataMap = {
Expand All @@ -17,7 +19,7 @@ type EventDataMap = {

class Clock extends Emittery<EventDataMap> {
private startedAt = 0;
private timer: NodeJS.Timer | null = null;
private timer: NodeJS.Timer | undefined = null;

public constructor() {
super();
Expand Down
16 changes: 9 additions & 7 deletions examples/emit.js
@@ -1,18 +1,20 @@
#!/usr/bin/env node

'use strict';

const Emittery = require('..');
import Emittery from '../index.js';

const myEmitter = new Emittery();

// Register listener
myEmitter.on('event', () => console.log('an event occurred!'));
myEmitter.onAny(eventName => console.log('"%s" event occurred!', eventName));
myEmitter.on('event', () => {
console.log('an event occurred!');
});

myEmitter.onAny(eventName => {
console.log('`%s` event occurred!', eventName);
});

// Emit event in next tick
myEmitter.emit('event');

// Prints:
// an event occurred!
// "event" event occurred!
// `event` event occurred!
12 changes: 5 additions & 7 deletions examples/emitonce.js
@@ -1,18 +1,16 @@
#!/usr/bin/env node

'use strict';

const Emittery = require('..');
import Emittery from '../index.js';

const myEmitter = new Emittery();

// Register listener for only the one event
myEmitter.once('event')
.then(count => console.log('an event occurred (#%d).', count));
(async () => {
console.log('An event occurred (#%d).', await myEmitter.once('event'));
})();

// Emit events in next tick
myEmitter.emit('event', 1);
myEmitter.emit('event', 2);

// Prints:
// an event occurred (#1).
// An event occurred (#1).
9 changes: 3 additions & 6 deletions examples/eventdata.js
@@ -1,14 +1,11 @@
#!/usr/bin/env node

'use strict';

const Emittery = require('..');
import Emittery from '../index.js';

const myEmitter = new Emittery();

// Does not provide a context either.
myEmitter.on('event', function ({a, b}, ...args) {
console.log(a, b, args, this);
myEmitter.on('event', function ({a, b}, ...arguments_) {
console.log(a, b, arguments_, this);
});

// Only accept one event data parameter
Expand Down

0 comments on commit 3b7db43

Please sign in to comment.