Skip to content

Commit

Permalink
feat: direct export fetch implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 25, 2021
1 parent b81082b commit 65b27dd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const response = await $fetch.raw('/sushi')

**Why export is called `$fetch` instead of `fetch`?**

Using the same name of `fetch` can be confusing since API is different but still it is a fetch so using closest possible alternative.
Using the same name of `fetch` can be confusing since API is different but still it is a fetch so using closest possible alternative. You can however, import `{ fetch }` from `ohmyfetch` which is auto polyfilled for Node.js and using native otherwise.

**Why not having default export?**

Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const getGlobal = function () {
throw new Error('unable to locate global object')
}

export const $fetch = createFetch({
fetch: getGlobal().fetch || (() => {
return Promise.reject(new Error('[ohmyfetch] global.fetch is not supported!'))
})
export const fetch = getGlobal().fetch || (() => {
return Promise.reject(new Error('[ohmyfetch] global.fetch is not supported!'))
})

export const $fetch = createFetch({ fetch })
6 changes: 3 additions & 3 deletions src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { createFetch } from './base'

export * from './base'

export const $fetch = createFetch({
fetch: nodeFetch.default as any // TODO
})
export const fetch = nodeFetch.default as any as typeof globalThis.fetch

export const $fetch = createFetch({ fetch })

0 comments on commit 65b27dd

Please sign in to comment.