Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require Node.js 18 #67

Merged
merged 1 commit into from Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/main.yml
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
@@ -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
Expand Up @@ -13,7 +13,7 @@
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=16"
"node": ">=18"
},
"scripts": {
"test": "xo && ava && tsd"
Expand Down