The smallest possible JSONP implementation


103.0.22 years ago5 years agoMinified + gzip package size for @borodean/jsonp in KB


npm version Build status Coverage Sauce test status

jsonp(url[, options], callback)

  • url <String> The URL to which the request is sent.
  • options <Object>
    • parameter <String> The name of the JSONP query parameter. Defaults to "callback".
    • object <Object> An object to which to attach the JSONP callback. Defaults to window.
    • key <String> The name of the JSONP callback. Defaults to an automatically generated unique value.
  • callback <Function(err, data)> A callback function that receives the data.

Loads data from the server using JSONP. Example:

import jsonp from '@borodean/jsonp';

jsonp('https://jsfiddle.net/echo/jsonp?foo=bar', (err, data) => {
  if (err) throw err;

Promise version

A version that returns a promise is also available:

import jsonp from '@borodean/jsonp/promise';

  data => console.log(data),
  err => console.log(err)


npm install @borodean/jsonp

For a browser global version check the dist directory of the installed module or directly download it:

Promise version:

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.