From 65b27ddb863790af8637b9da1c50c8fba14a295d Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 25 Aug 2021 17:23:21 +0200 Subject: [PATCH] feat: direct export fetch implementation --- README.md | 2 +- src/index.ts | 8 ++++---- src/node.ts | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3d2c135..11a7747 100644 --- a/README.md +++ b/README.md @@ -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?** diff --git a/src/index.ts b/src/index.ts index bb6d1ef..b4a9b17 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 }) diff --git a/src/node.ts b/src/node.ts index c3c7a83..69ab826 100644 --- a/src/node.ts +++ b/src/node.ts @@ -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 })