From 1f139d876ff17466218de383459e1d4835df12f1 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Mon, 25 Nov 2024 20:27:08 +0800 Subject: [PATCH] docs: add `fetch-jsonp` --- docs/src/pages/_meta.json | 1 + docs/src/pages/fetch-jsonp.mdx | 22 ++++++++++++++++++++++ src/fetch-jsonp/index.ts | 1 + 3 files changed, 24 insertions(+) create mode 100644 docs/src/pages/fetch-jsonp.mdx diff --git a/docs/src/pages/_meta.json b/docs/src/pages/_meta.json index 5ceba81..782b4b9 100644 --- a/docs/src/pages/_meta.json +++ b/docs/src/pages/_meta.json @@ -74,6 +74,7 @@ "context-local-storage-state": {}, "context-session-storage-state": {}, "create-fixed-array": {}, + "fetch-jsonp": {}, "invariant-nullthrow": {}, "noop": {}, "no-ssr": {}, diff --git a/docs/src/pages/fetch-jsonp.mdx b/docs/src/pages/fetch-jsonp.mdx new file mode 100644 index 0000000..ad6ab2b --- /dev/null +++ b/docs/src/pages/fetch-jsonp.mdx @@ -0,0 +1,22 @@ +--- +title: fetchJsonp +--- + +# CurrentYear + +import ExportMetaInfo from '../components/export-meta-info'; + + + +Resolve JSONP request with a promise. + +## Usage + +```tsx copy +import { fetchJsonp } from 'foxact/fetch-jsonp'; + +const data = await fetchJsonp( + // the `getUrl` function that passes the callback name + (callbackName) => 'https://api.example.com/data?callback=' + callbackName +); +``` diff --git a/src/fetch-jsonp/index.ts b/src/fetch-jsonp/index.ts index 0699ab7..6a9d6a2 100644 --- a/src/fetch-jsonp/index.ts +++ b/src/fetch-jsonp/index.ts @@ -6,6 +6,7 @@ declare global { const INTERNAL = '__foxact_jsonp_callbacks__SECRET_INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED'; +/** @see https://foxact.skk.moe/fetch-jsonp */ export function fetchJsonp(getUrl: (callbackName: string) => string) { if (typeof window === 'undefined') { throw new TypeError('fetchJsonp is only available in the browser');