-
Notifications
You must be signed in to change notification settings - Fork 127
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
docs: add initial examples #288
Merged
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ee1b2b9
docs: add examples
Barbapapazes 21448ea
docs: add examples
Barbapapazes ccdb6d7
Merge branch 'main' into docs/examples
Barbapapazes 2d0c85a
chore: format
Barbapapazes 5a14d42
fix: use `ofetch` instead of `$fetch`
Barbapapazes f4cac1c
Merge branch 'main' into docs/examples
pi0 51b405e
hide ref to website until published
pi0 fb6fdab
lint eslint
pi0 6fe6922
simplify to iterate
pi0 447ff00
update eslintrc
pi0 0eb629b
update more
pi0 3dd4afe
revert lock
pi0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,8 +1,11 @@ | ||
{ | ||
"extends": ["eslint-config-unjs"], | ||
"extends": [ | ||
"eslint-config-unjs" | ||
], | ||
"rules": { | ||
"no-undef": 0, | ||
"unicorn/consistent-destructuring": 0, | ||
"unicorn/no-await-expression-member": 0 | ||
"unicorn/no-await-expression-member": 0, | ||
"unicorn/prefer-top-level-await": 0 | ||
} | ||
} |
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 @@ | ||
# ofetch examples | ||
|
||
In this directory you can find some examples of how to use ofetch. | ||
|
||
To learn more, you can read the [ofetch first hand tutorial on unjs.io](https://unjs.io/resources/learn/ofetch-101-firs-hand). | ||
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,15 @@ | ||
import { $fetch } from "ofetch"; | ||
|
||
async function main() { | ||
const response = await $fetch<string>("https://api.github.com/markdown", { | ||
method: "POST", | ||
// To provide a body, we need to use the `body` option and just use an object. | ||
body: { | ||
text: "UnJS is **awesome**!\n\nCheck out their [website](https://unjs.io).", | ||
}, | ||
}); // Be careful, we use the GitHub API. | ||
|
||
console.log(response); | ||
} | ||
|
||
main().catch(console.error); |
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,13 @@ | ||
import { $fetch } from "ofetch"; | ||
|
||
async function main() { | ||
try { | ||
await $fetch("https://api.github.com", { | ||
method: "POST", | ||
}); | ||
} catch (error) { | ||
console.log(error.data); // This allow us to get the error body. | ||
} | ||
} | ||
|
||
main().catch(console.error); |
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,9 @@ | ||
import { $fetch } from "ofetch"; | ||
|
||
async function main() { | ||
const data = await $fetch("https://ungh.cc/repos/unjs/ofetch"); | ||
|
||
console.log(data); | ||
} | ||
|
||
main().catch(console.error); |
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,23 @@ | ||
import { $fetch } from "ofetch"; | ||
|
||
async function main() { | ||
const response = await $fetch("https://api.github.com/gists", { | ||
method: "POST", | ||
headers: { | ||
Authorization: `token ${process.env.GH_TOKEN}`, | ||
}, | ||
body: { | ||
description: "This is a gist created by ofetch.", | ||
public: true, | ||
files: { | ||
"unjs.txt": { | ||
content: "UnJS is awesome!", | ||
}, | ||
}, | ||
}, | ||
}); // Be careful, we use the GitHub API directly. | ||
|
||
console.log(response.url); | ||
} | ||
|
||
main().catch(console.error); |
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,11 @@ | ||
import { $fetch } from "ofetch"; | ||
|
||
async function main() { | ||
const response = await $fetch("https://api.github.com/gists", { | ||
method: "POST", | ||
}); // Be careful, we use the GitHub API directly. | ||
|
||
console.log(response); | ||
} | ||
|
||
main().catch(console.error); |
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,7 @@ | ||
{ | ||
"name": "examples", | ||
"dependencies": { | ||
"jiti": "^1.19.3", | ||
"ofetch": "workspace:../src" | ||
} | ||
} |
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,16 @@ | ||
import { $fetch } from "ofetch"; | ||
|
||
async function main() { | ||
const response = await $fetch( | ||
"https://api.github.com/repos/unjs/ofetch/tags", | ||
{ | ||
query: { | ||
per_page: 2, | ||
}, | ||
} | ||
); // Be careful, we use the GitHub API directly. | ||
|
||
console.log(response); | ||
} | ||
|
||
main().catch(console.error); |
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,19 @@ | ||
import { $fetch } from "ofetch"; | ||
|
||
interface Repo { | ||
id: number; | ||
name: string; | ||
repo: string; | ||
description: string; | ||
stars: number; | ||
} | ||
|
||
async function main() { | ||
const { repo } = await $fetch<{ repo: Repo }>( | ||
"https://ungh.cc/repos/unjs/ofetch" | ||
); | ||
|
||
console.log(`The repo ${repo.name} has ${repo.stars} stars.`); // The repo object is now strongly typed. | ||
} | ||
|
||
main().catch(console.error); |
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 |
---|---|---|
|
@@ -62,8 +62,8 @@ | |
"scripts": { | ||
"build": "unbuild", | ||
"dev": "vitest", | ||
"lint": "eslint --ext .ts . && prettier -c src test playground", | ||
"lint:fix": "eslint --fix --ext .ts . && prettier -w src test playground", | ||
"lint": "eslint --ext .ts . && prettier -c src test playground examples", | ||
"lint:fix": "eslint --fix --ext .ts . && prettier -w src test playground examples", | ||
"prepack": "pnpm build", | ||
"play": "jiti playground/index.ts", | ||
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags", | ||
|
@@ -92,4 +92,4 @@ | |
"vitest": "^0.34.3" | ||
}, | ||
"packageManager": "[email protected]" | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"name": "playground", | ||
"dependencies": { | ||
"ofetch": "workspace:../src" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,4 @@ | ||
packages: | ||
- "src" | ||
- "playground" | ||
- "examples" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.