Skip to content

Commit

Permalink
Require Node.js 18 (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
Richienb authored Nov 23, 2023
1 parent 66b039b commit 136b08a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 34 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
node-version:
- 20
- 18
- 16
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
34 changes: 2 additions & 32 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,3 @@
/**
An error to be thrown when the request is aborted by AbortController.
DOMException is thrown instead of this Error when DOMException is available.
*/
export class AbortError extends Error {
constructor(message) {
super();
this.name = 'AbortError';
this.message = message;
}
}

/**
TODO: Remove AbortError and just throw DOMException when targeting Node 18.
*/
const getDOMException = errorMessage => globalThis.DOMException === undefined
? new AbortError(errorMessage)
: new DOMException(errorMessage);

/**
TODO: Remove below function and just 'reject(signal.reason)' when targeting Node 18.
*/
const getAbortedReason = signal => {
const reason = signal.reason === undefined
? getDOMException('This operation was aborted.')
: signal.reason;

return reason instanceof Error ? reason : getDOMException(reason);
};

export default async function pMap(
iterable,
mapper,
Expand Down Expand Up @@ -68,11 +38,11 @@ export default async function pMap(

if (signal) {
if (signal.aborted) {
reject(getAbortedReason(signal));
reject(signal.reason);
}

signal.addEventListener('abort', () => {
reject(getAbortedReason(signal));
reject(signal.reason);
});
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=16"
"node": ">=18"
},
"scripts": {
"test": "xo && ava && tsd"
Expand Down

0 comments on commit 136b08a

Please sign in to comment.