1.2.1 • Published 1 month ago

@harexs/jsonp v1.2.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 month ago

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
};
1.2.1

1 month ago

1.2.0

2 months ago

1.0.0

2 months ago