{"id":16751593,"url":"https://github.com/lancercomet/vue-jsonp","last_synced_at":"2025-05-16T01:05:26.409Z","repository":{"id":12170397,"uuid":"71123798","full_name":"LancerComet/vue-jsonp","owner":"LancerComet","description":"A tiny library for handling JSONP request.","archived":false,"fork":false,"pushed_at":"2025-03-28T22:15:55.000Z","size":1819,"stargazers_count":154,"open_issues_count":16,"forks_count":26,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-12T04:32:50.561Z","etag":null,"topics":["jsonp-request","vue-jsonp","vue-plugin"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LancerComet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-17T09:52:52.000Z","updated_at":"2025-02-09T18:36:52.000Z","dependencies_parsed_at":"2024-01-02T23:38:46.555Z","dependency_job_id":"366d1761-d23a-419c-84c9-5b13888ed26e","html_url":"https://github.com/LancerComet/vue-jsonp","commit_stats":{"total_commits":31,"total_committers":5,"mean_commits":6.2,"dds":"0.19354838709677424","last_synced_commit":"ff97728a53b3f01c51a96a5f32de771e471924ca"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LancerComet%2Fvue-jsonp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LancerComet%2Fvue-jsonp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LancerComet%2Fvue-jsonp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LancerComet%2Fvue-jsonp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LancerComet","download_url":"https://codeload.github.com/LancerComet/vue-jsonp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254448579,"owners_count":22072764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jsonp-request","vue-jsonp","vue-plugin"],"created_at":"2024-10-13T02:44:24.312Z","updated_at":"2025-05-16T01:05:22.218Z","avatar_url":"https://github.com/LancerComet.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Vue-jsonp\n\n[![npm version](https://badge.fury.io/js/vue-jsonp.svg)](https://badge.fury.io/js/vue-jsonp)\n[![VueJsonp](https://github.com/LancerComet/vue-jsonp/workflows/Test/badge.svg)](https://github.com/LancerComet/vue-jsonp/actions)\n\nA tiny library for handling JSONP request.\n\n## Quick Start\n\nAs Vue plugin:\n\n```ts\nimport { VueJsonp } from 'vue-jsonp'\n\n// Vue Plugin.\nVue.use(VueJsonp)\n\n// Now you can use \"$jsonp\" on Vue components.\nconst vm = new Vue()\nconst data = await vm.$jsonp('/some-jsonp-url', {\n  myCustomUrlParam: 'veryNice'\n})\n```\n\nUse function directly:\n\n```ts\nimport { jsonp } from 'vue-jsonp'\n\n// Pass a response type.\nconst data = await jsonp\u003cstring\u003e('/some-jsonp-url', {\n  myCustomUrlParam: 'veryNice'\n})\n```\n\n## Send data and set query \u0026 function name\n\n### Send data\n\n```ts\n// The request url will be \"/some-jsonp-url?type=admin\u0026date=2020\u0026callback=jsonp_{RANDOM_STR}\".\nconst data = await jsonp('/some-jsonp-url', {\n  type: 'admin',\n  date: 2020\n})\n```\n\n### Custom query \u0026 function name\n\nThe url uniform is `/url?{callbackQuery}={callbackName}\u0026...` and the default is `/url?callback=jsonp_{RANDOM_STRING}\u0026...`.\n\nAnd you can change it like this:\n\n```ts\n// The request url will be \"/some-jsonp-url?type=admin\u0026date=2020\u0026cb=jsonp_func\".\njsonp('/some-jsonp-url', {\n  callbackQuery: 'cb',\n  callbackName: 'jsonp_func',\n  type: 'admin',\n  date: 2020\n})\n```\n\n## Module exports\n\n - `VueJsonp: PluginObject\u003cnever\u003e`\n \n - `jsonp\u003cT\u003e: (url: string, param?: IJsonpParam, timeout?: number) =\u003e Promise\u003cT\u003e`\n \n## API\n\n### IJsonpParam\n\nIJsonpParam is the type of param for jsonp function.\n\n```ts\n/**\n * JSONP parameter declaration.\n */\ninterface IJsonpParam {\n  /**\n   * Callback query name.\n   * This param is used to define the query name of the callback function.\n   *\n   * @example\n   * // The request url will be \"/some-url?myCallback=jsonp_func\u0026myCustomUrlParam=veryNice\"\n   * const result = await jsonp('/some-url', {\n   *   callbackQuery: 'myCallback',\n   *   callbackName: 'jsonp_func',\n   *   myCustomUrlParam: 'veryNice'\n   * })\n   *\n   * @default callback\n   */\n  callbackQuery?: string\n\n  /**\n   * Callback function name.\n   * This param is used to define the jsonp function name.\n   *\n   * @example\n   * // The request url will be \"/some-url?myCallback=jsonp_func\u0026myCustomUrlParam=veryNice\"\n   * const result = await jsonp('/some-url', {\n   *   callbackQuery: 'myCallback',\n   *   callbackName: 'jsonp_func',\n   *   myCustomUrlParam: 'veryNice'\n   * })\n   *\n   * @default jsonp_ + randomStr()\n   */\n  callbackName?: string\n\n  /**\n   * Custom data.\n   */\n  [key: string]: any\n}\n```\n\n## Example\n\n```ts\nimport Vue from 'vue'\nimport { VueJsonp } from 'vue-jsonp'\n\nVue.use(VueJsonp)\n\nconst vm = new Vue()\nconst { code, data, message } = await vm.$jsonp\u003c{\n  code: number,\n  message: string,\n  data: {\n    id: number,\n    nickname: string\n  }\n}\u003e('/my-awesome-url', {\n  name: 'MyName', age: 20\n})\n\nassert(code === 0)\nassert(message === 'ok')\nassert(data.id === 1)\nassert(data.nickname === 'John Smith')\n```\n\n```ts\nimport { jsonp } from 'vue-jsonp'\n\nconst result = await jsonp\u003cstring\u003e('/my-awesome-url')\nassert(result === 'such a jsonp')\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flancercomet%2Fvue-jsonp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flancercomet%2Fvue-jsonp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flancercomet%2Fvue-jsonp/lists"}