-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: fetch-compatible signature
- Loading branch information
Showing
6 changed files
with
64 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"barnard59-http": minor | ||
--- | ||
|
||
Add overload to `get` and `post` to match the signature of native `fetch` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
import type { RequestInit } from 'node-fetch' | ||
import type { GetInit } from './lib/fetch.js' | ||
import fetch from './lib/fetch.js' | ||
|
||
function get(options: GetInit) { | ||
return fetch(options) | ||
function get(options: GetInit): ReturnType<typeof fetch> | ||
function get(url: string, options?: RequestInit): ReturnType<typeof fetch> | ||
function get(urlOrOptions: GetInit | string, options: RequestInit = {}): ReturnType<typeof fetch> { | ||
if (typeof urlOrOptions === 'string') { | ||
return fetch({ ...options, url: urlOrOptions }) | ||
} | ||
|
||
return fetch(urlOrOptions) | ||
} | ||
|
||
export default get |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
import type { RequestInit } from 'node-fetch' | ||
import type { PostInit } from './lib/writableFetch.js' | ||
import writableFetch from './lib/writableFetch.js' | ||
|
||
function post(options: PostInit) { | ||
return writableFetch(options) | ||
function post(options: PostInit): ReturnType<typeof writableFetch> | ||
function post(url: string, options: RequestInit): ReturnType<typeof writableFetch> | ||
function post(urlOrOptions: PostInit | string, options: RequestInit = {}): ReturnType<typeof writableFetch> { | ||
if (typeof urlOrOptions === 'string') { | ||
return writableFetch({ ...options, url: urlOrOptions }) | ||
} | ||
|
||
return writableFetch(urlOrOptions) | ||
} | ||
|
||
export default post |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters