npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

http-jsonp

v1.1.1

Published

A JSONP cross-origin request library

Downloads

181

Readme

httpJsonp

Build Status npm version npm downloads npm license

A JSONP cross-origin request library

Features

  • Supports the Requests the Script
  • State callback
  • Cancel requests

Browser Support

| Chrome | Firefox | Safari | Opera | Edge | IE | | :---: | :---: | :---: | :---: | :---: | :---: | | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 7+ ✔ |

Installation

Using npm:

$ npm install --save http-jsonp

or Yarn:

$ yarn add http-jsonp

Using cdn:

<script type="text/javascript" src="https://unpkg.com/http-jsonp/dist/http-jsonp.min.js"></script>

Example

Performing a JsonpCallbck request

import httpJsonp from "http-jsonp";

httpJsonp({
  url: "/user",
  params: {
    ID: 123456
  },
  callbackProp: "callback",
  callback: function(data) {
    console.log("callback", data);
  },
  error: function(err) {
    console.log(err);
  },
  complete: function() {
    console.log("complete");
  }
});

Performing a script request

import httpJsonp from "http-jsonp";

httpJsonp({
  url: "/lodash.js",
  params: {
    v: "3.8.0"
  },
  load: function() {
    console.log("load", window._);
  },
  error: function(err) {
    console.log("error");
  },
  complete: function() {
    console.log("complete");
  }
});

httpJsonp API

Requests can be made by passing the relevant options to httpJsonp.

httpJsonp(options)

Request Options

{
  // `baseURL` will be prepended to `url` unless `url` is absolute.
  baseURL: "", // baseURL: "https://example.com/api/"

  // `url` is the server URL that will be used for the request.
  url: "", // url: "/jsonpdata"

  // `params` are the URL parameters to be sent with the request.(Includes Callback behavior)
  params: {},

  // `callbackProp` Specify which key in `params` is the callback behavior interface.
  // If a key value in `params` is specified, the specified value overrides the default random name of `callbackName`
  callbackProp: false, // default [false, callbackProp]

  // `callbackNamespase` Namespace before callback name
  // exmaple:
  //   "__httpJsonpCallback" = window.__httpJsonpCallback = {}
  callbackNamespase: "__httpJsonpCallback", // default

  // `callbackName` Callback name. (If not specified, a name is randomly generated)
  callbackName: "",

  // `timeout` specifies the number of milliseconds before the request times out.
  timeout: 60000, // default

  // script attribute
  scriptAttr: {
    type: "",
    charset: "",
    crossOrigin: null,
    async: true,
    defer: false
  },

  // Does the script tag remain when the request is completed.
  keepScriptTag: false,

  // callbackProp = "callback"
  // When callbackProp exists, A function to be called if the callback is triggered.
  callback: null,

  // callbackProp = false
  // When callbackProp is false, A function to be called if the request load complete.
  load: null,

  // A function to be called if the request fails.
  error: null,
  
  // A function to be called when the request finishes (after success and error callbacks are executed).
  complete: null
}

License

MIT