Skip to content

Commit

Permalink
docs: add fetch-jsonp
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Nov 25, 2024
1 parent 79c21a5 commit 1f139d8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/src/pages/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"context-local-storage-state": {},
"context-session-storage-state": {},
"create-fixed-array": {},
"fetch-jsonp": {},
"invariant-nullthrow": {},
"noop": {},
"no-ssr": {},
Expand Down
22 changes: 22 additions & 0 deletions docs/src/pages/fetch-jsonp.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: fetchJsonp
---

# CurrentYear

import ExportMetaInfo from '../components/export-meta-info';

<ExportMetaInfo />

Resolve JSONP request with a promise.

## Usage

```tsx copy
import { fetchJsonp } from 'foxact/fetch-jsonp';

const data = await fetchJsonp<T>(
// the `getUrl` function that passes the callback name
(callbackName) => 'https://api.example.com/data?callback=' + callbackName
);
```
1 change: 1 addition & 0 deletions src/fetch-jsonp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(getUrl: (callbackName: string) => string) {
if (typeof window === 'undefined') {
throw new TypeError('fetchJsonp is only available in the browser');
Expand Down

0 comments on commit 1f139d8

Please sign in to comment.