# jsonp-promise-enhance

> Jsonp es6 implementation that returns a promise.

Latest version **0.0.2** (published 2018-12-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install jsonp-promise-enhance
pnpm add jsonp-promise-enhance
yarn add jsonp-promise-enhance
bun add jsonp-promise-enhance
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2018-12-21 |
| First published | 2018-12-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 24.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Allen |
| Maintainers | jf3096 |
| Keywords | jsonp, promise, async, es6 |

## Links

- npm: https://www.npmjs.com/package/jsonp-promise-enhance
- Repository: https://github.com/jf3096/jsonp-promise
- Homepage: https://github.com/jf3096/jsonp-promise#readme
- Issues: https://github.com/jf3096/jsonp-promise/issues
- npm.io page: https://npm.io/package/jsonp-promise-enhance

## Dependencies (1)

- [short-hash](https://npm.io/package/short-hash.md) 1.0.0

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 0.0.2 (latest) — 2018-12-21
- 0.0.1 — 2018-12-21

## README

# jsonp-promise-enhance

### FORK

1. added short hash rather than self incremental callback param

### Description

A simple JSONP es6 implementation (inspired from `https://github.com/webmodules/jsonp`) which returns an object containing a promise, so it can be used by generators and async functions.

It's supposed to be used with an es6 module loader. Works great with jspm/systemjs for cross-browser compatibility.

## Instalation
Install for node.js, browserify or jspm using `npm`:

```bash
$ npm install jsonp-promise
```
or
```bash
$ jspm install npm:jsonp-promise
```

## API

###jsonp(url, options)

- `url` (`String`) url to fetch
- `options` (`Object`), optional
  - `param` (`String`) name of the query string parameter to specify
    the callback (defaults to `callback`)
  - `timeout` (`Number`) how long after the request until a timeout error
    is emitted. `0` to disable (defaults to `15000`)
  - `prefix` (`String`) prefix for the global callback functions that
    handle jsonp responses (defaults to `__jp`)

Returns an object containing two properties:
- `promise` a promise which will be resolved if the jsonp request succeeds,
    otherwise will be rejected
- `cancel` a method which will cancel the request and reject the promise

If it times out or gets canceled, the promise will be rejected with an `Error` object.

```javascript
// e.g.: get the latest javascript subrredits
async function getJson() {
    let data = await jsonp('http://www.reddit.com/r/javascript/top.json', {param: 'jsonp'}).promise;
    console.log(data.data.children);
}
```

## License

MIT

---
_Source: https://npm.io/package/jsonp-promise-enhance · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
