mirror of
https://github.com/shivammathur/setup-php.git
synced 2026-01-23 09:07:52 +07:00
Refactor to use ES2024+ features for Node 24
Use Set for O(1) redirect status code lookup in fetch.ts Use at(-1) and Object.hasOwn() in tools.ts Use for...of with entries() in utils.ts
This commit is contained in:
10
src/fetch.ts
10
src/fetch.ts
@@ -1,3 +1,8 @@
|
||||
/**
|
||||
* Redirect status codes set for O(1) lookup
|
||||
*/
|
||||
const REDIRECT_CODES = new Set([301, 302, 303, 307, 308]);
|
||||
|
||||
/**
|
||||
* Function to fetch a URL using native fetch API (Node 24+)
|
||||
*
|
||||
@@ -26,10 +31,7 @@ export async function fetch(
|
||||
if (response.ok) {
|
||||
const data = await response.text();
|
||||
return {data};
|
||||
} else if (
|
||||
[301, 302, 303, 307, 308].includes(response.status) &&
|
||||
redirect_count <= 0
|
||||
) {
|
||||
} else if (REDIRECT_CODES.has(response.status) && redirect_count <= 0) {
|
||||
return {error: `${response.status}: Redirect error`};
|
||||
} else {
|
||||
return {error: `${response.status}: ${response.statusText}`};
|
||||
|
||||
Reference in New Issue
Block a user