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');