-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TypeScript annotations and documentation.
- http() can no longer take a URL as first argument as a shorthand to make a GET request. - runProcess() no longer returns a promise. Instead, the object it returns has a waitUntilExit() method BREAKING CHANGE: http() no longer takes a string as shorthand. runProcess() no longer returns a promise.
- Loading branch information
1 parent
31deddc
commit 1d10a89
Showing
12 changed files
with
528 additions
and
889 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
/node_modules | ||
/index.d.ts |
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,14 +1,33 @@ | ||
import {sendRequest} from 'passing-notes' | ||
|
||
export default async function (request) { | ||
if (typeof request === 'string') { | ||
const response = await sendRequest({ | ||
method: 'GET', | ||
headers: {}, | ||
url: request, | ||
}) | ||
return response.body | ||
} | ||
/** | ||
* @typedef {'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'} Method | ||
* @typedef {{ [name: string]: string }} Headers | ||
* @typedef {string | Buffer} Data | ||
* @typedef {Data | ReadableStream<Data> | AsyncIterable<Data>} Body | ||
* | ||
* @typedef {{ | ||
* method: Method, | ||
* url: string, | ||
* headers?: Headers, | ||
* body?: Body | ||
* }} Request | ||
* | ||
* @typedef {{ | ||
* status: number, | ||
* headers: Headers, | ||
* body: Body | ||
* }} Response | ||
*/ | ||
|
||
/** | ||
* Make an HTTP request | ||
* | ||
* @param {Request} request - Request `method` and `url`, with optional | ||
* `headers` and `body` | ||
* | ||
* @return {Promise<Response>} - The response `status`, `headers`, and `body` | ||
*/ | ||
export default function (request) { | ||
return sendRequest(request) | ||
} |
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,16 +1,25 @@ | ||
import test from 'ava' | ||
import {http} from '../index.js' | ||
|
||
test('sending a simple HTTP GET request', async (t) => { | ||
t.regex(await http('http://example.com'), /Example Domain/) | ||
}) | ||
|
||
test('sending an HTTP request', async (t) => { | ||
const response = await http({ | ||
method: 'POST', | ||
url: 'https://httpbin.org/post', | ||
headers: {}, | ||
body: 'Hello World!', | ||
}) | ||
|
||
if (typeof response.body !== 'string') { | ||
return t.fail('Response body was not a string') | ||
} | ||
|
||
t.like(JSON.parse(response.body), {data: 'Hello World!'}) | ||
}) | ||
|
||
test('omitting unused fields', async (t) => { | ||
const response = await http({ | ||
method: 'GET', | ||
url: 'https://httpbin.org/status/200', | ||
}) | ||
t.like(response, {status: 200}) | ||
}) |
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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"allowSyntheticDefaultImports": true, | ||
"allowJs": true, | ||
"checkJs": true, | ||
"declaration": true | ||
}, | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
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
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,3 +1,14 @@ | ||
import {promisify} from 'node:util' | ||
|
||
export default promisify(setTimeout) | ||
const promisifiedSetTimeout = promisify(setTimeout) | ||
|
||
/** | ||
* Stop execution for a specified number of milliseconds | ||
* | ||
* @param {number} time | ||
* | ||
* @return {Promise<void>} Resolves after the specified amount of time | ||
*/ | ||
export default async function (time) { | ||
await promisifiedSetTimeout(time) | ||
} |
Oops, something went wrong.