{"_id":"@co-labo-hub/fetcha","_rev":"13-f225c7f1c42eaa5b8018b62fef016f06","time":{"created":"2023-07-04T16:18:32.201Z","1.0.0":"2023-07-02T19:41:36.483Z","modified":"2024-01-28T16:19:43.685Z","1.0.1":"2023-07-04T16:02:10.013Z","1.0.2":"2023-07-04T16:18:32.515Z","1.0.3":"2023-07-04T17:51:39.546Z","1.0.4":"2023-07-04T23:26:12.944Z","1.0.5":"2023-07-06T22:15:32.110Z","1.0.6":"2023-07-06T22:34:03.358Z","1.0.7":"2024-01-28T16:19:43.510Z"},"name":"@co-labo-hub/fetcha","dist-tags":{"latest":"1.0.7"},"versions":{"1.0.6":{"name":"@co-labo-hub/fetcha","version":"1.0.6","description":"## comparison","main":"dist/js/index.js","types":"dist/types/index.d.ts","scripts":{"build":"npx tsc","build:watch":"npx tsc --watch"},"repository":{"type":"git","url":"git+https://github.com/co-labo-hub/fetcha.git"},"keywords":["typescript","fetch"],"author":{"name":"co.labo.hub"},"license":"MIT","bugs":{"url":"https://github.com/co-labo-hub/fetcha/issues"},"homepage":"https://github.com/co-labo-hub/fetcha#readme","dependencies":{"typescript":"^5.1.6"},"gitHead":"10cfd7e110fa62f2713f344158e12c18b7396a26","_id":"@co-labo-hub/fetcha@1.0.6","_nodeVersion":"20.3.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-6oKc1wxzgQar3GYa7+7u0PK6CiSghI7sto0ccOrODeyqxmDQhcsRlO0BPuXeE+5gZ7chF+XHecFPapftOy6SVw==","shasum":"5bec7926fd7922ac0c936726a5f286058b2d870c","tarball":"https://registry.npmjs.org/@co-labo-hub/fetcha/-/fetcha-1.0.6.tgz","fileCount":19,"unpackedSize":42169,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIH9rGdfXtk1QN8MzzbNCHEx6fs2Zy0CBpKz59Flw8eFDAiEArTHpMztW4bts4PjLFF3x0U330A/9bKrTIhCzwultiJ0="}]},"_npmUser":{"name":"co-labo-hub","email":"co.labo.hub+npm@gmail.com"},"directories":{},"maintainers":[{"name":"co-labo-hub","email":"co.labo.hub+npm@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fetcha_1.0.6_1688682843071_0.6232016604153199"},"_hasShrinkwrap":false},"1.0.7":{"name":"@co-labo-hub/fetcha","version":"1.0.7","description":"## comparison","main":"dist/js/index.js","types":"dist/types/index.d.ts","scripts":{"build":"npx tsc","build:watch":"npx tsc --watch"},"repository":{"type":"git","url":"git+https://github.com/co-labo-hub/fetcha.git"},"keywords":["typescript","fetch"],"author":{"name":"co.labo.hub"},"license":"MIT","bugs":{"url":"https://github.com/co-labo-hub/fetcha/issues"},"homepage":"https://github.com/co-labo-hub/fetcha#readme","dependencies":{"typescript":"^5.1.6"},"gitHead":"39ebe663922dec5f8a705cdd6478ea136cca3e29","_id":"@co-labo-hub/fetcha@1.0.7","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-iygv6ikI++QOAAlNKd9gmvJ8vLoGUMJWGlAQCxLQvg6MH1V4mjRk3u1BP4Gh2eti3d1t3JuQH1wy8cXw31NEHQ==","shasum":"8ffb71ad4f493b50252520261b0c5163e7a736b9","tarball":"https://registry.npmjs.org/@co-labo-hub/fetcha/-/fetcha-1.0.7.tgz","fileCount":19,"unpackedSize":43127,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHIW5r99vkGQuMjB3tcm7n68nit3sRFX1DyU8dmXISy/AiAY5K+3AXJIsdPHbQW2GhGPMXnPfHcWf9r/7EZXoBx3jw=="}]},"_npmUser":{"name":"co-labo-hub","email":"co.labo.hub+npm@gmail.com"},"directories":{},"maintainers":[{"name":"co-labo-hub","email":"co.labo.hub+npm@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fetcha_1.0.7_1706458783333_0.9960576941237176"},"_hasShrinkwrap":false}},"maintainers":[{"name":"co-labo-hub","email":"co.labo.hub+npm@gmail.com"}],"description":"## comparison","homepage":"https://github.com/co-labo-hub/fetcha#readme","keywords":["typescript","fetch"],"repository":{"type":"git","url":"git+https://github.com/co-labo-hub/fetcha.git"},"author":{"name":"co.labo.hub"},"bugs":{"url":"https://github.com/co-labo-hub/fetcha/issues"},"license":"MIT","readme":"# fetcha!\n\n## Comparison\n\n- fetch\n\n```typescript\nfetch(\"https://example.com/api\", {\n  method: \"POS\", // typo\n  headers: {\n    \"Content-Typ\": \"application/jso\", // typo\n    Authorization: `Bearer ${\"foo\"}`,\n  },\n  credentials: \"include\",\n  mode: \"cors\",\n  body: JSON.stringify({ name: \"bar\" }), // JSON.stringify\n})\n  .then((resp) => {\n    // normal and abnormal.\n\n    if (resp.ok) return resp.json();\n\n    switch (resp.status) {\n      case 500:\n        location.href = \"/500.html\";\n        return;\n      case 404:\n        location.href = \"/404.html\";\n        return;\n      case 401:\n        location.href = \"/login.html\";\n        return;\n      default:\n        alert(resp.statusText);\n    }\n  })\n  .then(({ id }: { id: number }) => console.log(id))\n  .catch((e) => alert(e.message));\n```\n\n- fetcha!\n\n```typescript\nfetcha(\"https://example.com/api\")\n  .contentType(\"application/json\")\n  .header(\"Authrization\", `Bearer ${\"foo\"}`)\n  .credentials(\"include\")\n  .mode(\"cors\")\n  .post({ name: \"bar\" })\n  .then((resp) => resp.toJson<{ id: number }>())\n  .then(({id}) => console.(id))\n  .catch((e: FetchaError) => {\n    switch (e.status) {\n      case 500:\n        location.href = \"/500.html\";\n        return;\n      case 404:\n        location.href = \"/404.html\";\n        return;\n      case 401:\n        location.href = \"/login.html\";\n        return;\n      default:\n        alert(e.message);\n    }\n  });\n```\n\n## Install\n\n```sh\nnpm install @co-labo-hub/fetcha\n```\n\n```typescript\nimport { fetcha, FetchaError } from \"@co-labo-hub/fetcha\";\n```\n\n## Examples\n\n- /src/example.ts\n\n## Methods\n\n| methods                                          | type      | description |\n| ------------------------------------------------ | --------- | ----------- |\n| `url(url: string \\| URL)`                        | setting   |             |\n| `origin(origin?: string \\| URL)`                 | setting   |             |\n| `header(name: string, value?: string)`           | setting   | \"\": delete  |\n| `contentType(mime: \"application/json\" \\| \"\")`    | setting   | \"\": delete  |\n| `body(body: BodyInit \\| Json)`                   | setting   |             |\n| `mode(mode: RequestMode)`                        | setting   |             |\n| `credentials(credentials: RequestCredentials)`   | setting   |             |\n| `cache(cache: RequestCache)`                     | setting   |             |\n| `redirect(redirect: RequestRedirect)`            | setting   |             |\n| `referrer(referrer: string)`                     | setting   |             |\n| `referrerPolicy(referrerPolicy: ReferrerPolicy)` | setting   |             |\n| `integrity(integrity: string)`                   | setting   |             |\n| `keepalive(keepalive: boolean)`                  | setting   |             |\n| `signal(signal: AbortSignal)`                    | setting   |             |\n| `fetch(method: Method = \"GET\")`                  | execution |             |\n| `get()`                                          | execution |             |\n| `head()`                                         | execution |             |\n| `delete()`                                       | execution |             |\n| `post(body?: BodyInit \\| Json)`                  | execution |             |\n| `patch(body?: BodyInit \\| Json)`                 | execution |             |\n| `put(body?: BodyInit \\| Json)`                   | execution |             |\n\n## Response\n\nadditional properties\n\n| properties  | return     |\n| ----------- | ---------- |\n| toJson<T>() | Promise<T> |\n\n## Error\n\nFetchaError:\n`constructor({ message, request, response }: FetchaErrorProps)`\n\n| properties   | description       | type                                            |\n| ------------ | ----------------- | ----------------------------------------------- |\n| `request`    | request and url   | RequestInit & { url?: string \\| URL }           |\n| `response`   | original response | Response \\| undefined                           |\n| `headers`    | of response       | Headers \\| undefined                            |\n| `ok`         | of response       | boolean \\| undefined                            |\n| `redirected` | of response       | boolean \\| undefined                            |\n| `status`     | of response       | number \\| undefined                             |\n| `statusText` | of response       | string \\| undefined                             |\n| `type`       | of response       | ResponseType \\| undefined                       |\n| `url`        | of response       | string \\| undefined                             |\n| `body`       | of response       | ReadableStream<Uint8Array> \\| null \\| undefined |\n| `bodyUsed`   | of response       | boolean \\| undefined                            |\n","readmeFilename":"README.md"}