@harexs/jsonp
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

Harexs-Jsonp

A simple promiseify jsonp

Useage

npm install @harexs/jsonp

yarn install @harexs/jsonp

pnpm install @harexs/jsonp

import Jsonp from "@harexs/jsonp";

Jsonp(url, params, options).then((res) => {
  if (res.code === 200) {
    //success
  } else if (res.code === 400) {
    // success but response empty
  } else if (res.code === 500) {
    // script error and file load fail
  }
});

// await
const res = await Jsonp(url, params, options);

Example

Jsonp("http://127.0.0.1/api/print", { url: "xx", fileName: "xx" }, { timeout: 10000 }, options).then((res) => {
  console.log(res.data);
});

Type

interface JsonpRes<T> {
  code: JsonpResCode;
  data: T | null;
}

type JsonpResCode = 200 | 400 | 500;

type JsonpOptions = {
  timeout?: number;
  callbackName?: string;
  insertDom?: HTMLElement; //  default document.body
};

Readme

Keywords

Package Sidebar

Install

npm i @harexs/jsonp

Weekly Downloads

4

Version

1.2.1

License

ISC

Unpacked Size

15.8 kB

Total Files

10

Last publish

Collaborators

  • gu1st