{"_id":"@are/f-fetch","_rev":"2-b6a626b57fe81408520bd9c21bd7251a","name":"@are/f-fetch","dist-tags":{"latest":"1.15.5"},"versions":{"1.15.4":{"name":"@are/f-fetch","version":"1.15.4","description":"Functional fetch wrapper","main":"dist/index.js","scripts":{"build":"rollup -c","test":"npm run build && tape test/**/*.js | tap-dot","prepare":"npm run build"},"repository":{"type":"git","url":"git+https://github.com/are/f-fetch.git"},"keywords":["fetch","functional"],"author":{"name":"Artur Wojciechowski","email":"me@iama.re"},"license":"MIT","bugs":{"url":"https://github.com/are/f-fetch/issues"},"homepage":"https://github.com/are/f-fetch#readme","devDependencies":{"builtin-modules":"^3.1.0","rollup":"^1.25.2","rollup-plugin-commonjs":"^10.1.0","rollup-plugin-multi-entry":"^2.1.0","rollup-plugin-multi-input":"^1.0.2","rollup-plugin-node-resolve":"^5.2.0","tap-dot":"^2.0.0","tape":"^4.11.0"},"dependencies":{"abort-controller":"^3.0.0","cross-fetch":"^3.0.4","url-template":"^2.0.8"},"gitHead":"cfbd30b0770ddaa3ce8fec10888e4ad4a6085f33","_id":"@are/f-fetch@1.15.4","_nodeVersion":"10.16.3","_npmVersion":"6.11.3","dist":{"integrity":"sha512-dTlh2w9UZe0zi0FkzZeU8N4yTno3PJKrMt5rIM8k0LKOjgTi+krGueIp+Wk73GOj1BUXjdAe7KII93pZGfTntw==","shasum":"d9848f250ac174de600a0bdbbe3947d482f6b95d","tarball":"https://registry.npmjs.org/@are/f-fetch/-/f-fetch-1.15.4.tgz","fileCount":22,"unpackedSize":95228,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd3pJVCRA9TVsSAnZWagAA8mAQAINGVhBFkJCHLqIOMwah\niXuMUNZY97SfzGIdhJnqgSk4Th6JEpCYavRVNCUwhCZuq0nMmzUGOSYwUec4\nU5b434d6vHuJyUFUOqjsQJtf6TB9LrOmQGiQypxARC352a89qpAefktYDctr\nt9+VBW4LlLJDHUkGkJFnfV3xCzXeqFQnYfWC+qTCnlkS0wKkr+I1opqU4hV6\nlbSXcNUE30t+lac/jynQhSb5IiI3yqWqUNcFJT/Ck0jh+UAQ2qrGE4OiYEAg\nXFYpCEQsaKR7Hd9YM7gVSTZYY9OGpliEwfS9eQFZUwselX0dLvDDxJywcW2l\nbZXAQAHn6nwXAa6Rqcak6CJH1A4oOl+dfd/5Ug6hBqR1prSsTCbOUtYi9dmq\nYzxcib9QoQT6F3nMrCAom73jMzoBQKzlGGsSdSctuczvSlOJD/812dNk++YA\n1gT/yKXeX/WRrR8S/M34NFXaSUwnQ11mlmc/8I+dqDo7KaXiDRL+vh9ZTaX3\nHUFxf1vlhxGZSSQd9f8g72W5HoOmJxqQ0o331cMIOj0aQ3Re06soOLpIobSY\nSISjdJFW9VfXfsFmbixIsjAqB6tbGnK/4y+2uxRBz1Vg5sFFTPY4VnAEbrwq\n0Y4HTtDhH5VyonaeTTvfhmoxbAq/cgQtuth+2xQ2CpaCzX4O2/SannwM/V5P\ncILv\r\n=vroq\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGlZfs7raCWGVcMn2sZQGougLC5p1K6xK2t4CSnvhQCMAiEAq5peT8JiJVILv3zJzR52at/ePQo27TotHyQ/aoW1PgM="}]},"maintainers":[{"name":"are","email":"me@iama.re"}],"_npmUser":{"name":"are","email":"me@iama.re"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/f-fetch_1.15.4_1574867540560_0.4627951539381363"},"_hasShrinkwrap":false},"1.15.5":{"name":"@are/f-fetch","version":"1.15.5","description":"Functional fetch wrapper","main":"dist/index.js","scripts":{"build":"rollup -c","test":"npm run build && tape test/**/*.js | tap-dot","prepare":"npm run build"},"repository":{"type":"git","url":"git+https://github.com/are/f-fetch.git"},"keywords":["fetch","functional"],"author":{"name":"Artur Wojciechowski","email":"me@iama.re"},"license":"MIT","bugs":{"url":"https://github.com/are/f-fetch/issues"},"homepage":"https://github.com/are/f-fetch#readme","devDependencies":{"builtin-modules":"^3.1.0","rollup":"^1.25.2","rollup-plugin-commonjs":"^10.1.0","rollup-plugin-multi-entry":"^2.1.0","rollup-plugin-multi-input":"^1.0.2","rollup-plugin-node-resolve":"^5.2.0","tap-dot":"^2.0.0","tape":"^4.11.0"},"dependencies":{"abort-controller":"^3.0.0","cross-fetch":"^3.0.4","url-template":"^2.0.8"},"gitHead":"0705d556395c2bf0efb2b024be668deee1505c48","_id":"@are/f-fetch@1.15.5","_nodeVersion":"10.16.3","_npmVersion":"6.11.3","dist":{"integrity":"sha512-FgjLEkmMJO+0s9tYOQtlq9pmfkDEB6p3EGTs/623rgTBc3J5j0V42b/veQ0fKn1AhIXqgH+LfK4aTXKom1qCTA==","shasum":"2b551908c505dfbe0f1425e8722473f5ac5d5d8c","tarball":"https://registry.npmjs.org/@are/f-fetch/-/f-fetch-1.15.5.tgz","fileCount":22,"unpackedSize":95234,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd4QbVCRA9TVsSAnZWagAA/5cQAI3dR7E5YUYfIX0TN1dc\nAZ5FOEBaw9qma2o+MYARyVTLZk020meRB56murGLXTUYV0DmbKa6FGH/bHpY\nvzTRfcwgZ393nlKq66tjxMK0h/G3gPRpSTCxjjJU433jxW2PvXegcvVDwoud\nCQIz31xnYGi5skc8C99x50SgPc0Q2qFtLxZJq/I3vpr1yWKvHggEDrNAFwMx\nZLohvvLn2B0Zz5w7widu+z/Lqsdl+OYoLNipx/1kWivx1On4gMDCt4ZwgI+f\n/o/2RQReZCaO00MTWD0l7c0Jc20F6cc3QiXWN9PnsUR4FwTP5qpYCVcuhcGX\nvOH83GwGfQH53KWHR0pSmLhRNkl/3XnITCWGrl5H+9qPV1eT9jFYfZMeyLHI\nwbNvJwEAN7TvgvEDC3QoH+PtYU1fFKyB0UF7/P+0eaMbTBnVHMZ2KIGHnhlj\nJH4QK6GfWx8qfA/SY36nHQYbRCTqxzNQraCWzFtetYncyFM743YpxTDRZkyN\nOlm1HhtaglDFo4+MTxT2s6VJiHqc+7M6mfTbOsPQZrl62pTvxx3uGnbLJ862\n6qsDY2CMpgfuo1GVTVeJgbWLJSr7hy5Nw4MZjMod4LwgKd/as3Ka942snYXn\nwo2tfUnu4OFpx4vCvTgIBuNQ2XYxNe+l20PfS1PFxXenIU/M3UsbtWvHIKId\nLIK7\r\n=KbRU\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBRCjr96hzJDw7h2+YMZkZk2vGNOTOecfbRIeQTno1HEAiEAiSnqW52ZeFlNwNGKov+e/P8vEHn8R8Ueo52ANdwtCFE="}]},"maintainers":[{"name":"are","email":"me@iama.re"}],"_npmUser":{"name":"are","email":"me@iama.re"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/f-fetch_1.15.5_1575028436744_0.7034178985893813"},"_hasShrinkwrap":false}},"time":{"created":"2019-11-27T15:12:20.320Z","1.15.4":"2019-11-27T15:12:20.743Z","modified":"2022-04-04T15:22:44.776Z","1.15.5":"2019-11-29T11:53:56.969Z"},"maintainers":[{"name":"are","email":"me@iama.re"}],"description":"Functional fetch wrapper","homepage":"https://github.com/are/f-fetch#readme","keywords":["fetch","functional"],"repository":{"type":"git","url":"git+https://github.com/are/f-fetch.git"},"author":{"name":"Artur Wojciechowski","email":"me@iama.re"},"bugs":{"url":"https://github.com/are/f-fetch/issues"},"license":"MIT","readme":"# f-fetch\n\n`f-fetch` is a JavaScript wrapper for functional `fetch`.\n\n## Installation\n\n```bash\nnpm i @are1000/f-fetch\n```\n\n## Example\n\n```js\nimport { request } from '@are1000/f-fetch'\n\nimport target from '@are1000/f-fetch/operators/target'\nimport when from '@are1000/f-fetch/operators/when'\nimport parse from '@are1000/f-fetch/operators/parse'\nimport map from '@are1000/f-fetch/operators/map'\nimport error from '@are1000/f-fetch/operators/error'\n\n/*\n  You can alternatively import like this:\n  \n  import { target, when, parse, map, error } from '@are1000/f-fetch/operators'\n*/\n\nconst req = request(\n    target('GET', 'https://example.com', 'api', 'users', 5),\n    when(r => r.ok, parse('json'), map(res => res.entities)),\n    when(r => r.status === 404, error(NotFoundError)),\n    when(r => r.status === 500, error(InternalServerError)),\n)\n\nconst entities = await req.run()\n```\n\n## Usage\n\nTo use `f-fetch`, import the module using npm or yarn.\n\n```bash\nnpm install @are1000/f-fetch\n```\n\nThen, import the main `request` builder and pass any amount of operators inside.\n\nThe operators are not executed until the method `run` is called, so any custom operators\nthat contain time sentitive logic are safe.\n\n```js\nconst req = request(...)\n\nconst response = await req.run()\n```\n\nYou can additionally pass values to the `run` function. They will become available\nin certain operators (i.e. `json`).\n\n```js\nconst req = request(\n    ...,\n    json((query) => ({ query }))\n)\n\nconst response = await req.run('myQuery')\n```\n\nYou can also extend existing requests by adding more operators:\n\n```js\nconst req1 = request(...)\n\nconst req2 = req1.extend(...)\n```\n\n## Operators\n\n### Request operators\n\n#### `target(method: string, ...url: Array<string | number>)`\n\nSets the method and the URL of the request.\n\nAfter the method, you can pass an arbitrary amount of URL fragments -\nthey will be joined using the `/` character.\n\n#### `appendUrl(...url: Array<string | number>)`\n\nJoin current URL with URL fragments using `/` character. Useful for extending\nrequests.\n\n#### `json(obj: JSON)` | `json((...Args) => JSON)`\n\nSets the request body to an JSON object (internally uses JSON.stringify).\nIt also correctly sets `Content-Type` header.\n\nIf you pass a function instead, you can access the arguments from `request().run`.\n\n#### `body(data: string, type: string)`\n\nSets the request body to a string. You must pass the `Content-Type` as a second\nargument.\n\n#### `timeout(delay: number)`\n\nTimeouts the request after a number of milliseconds passed.\n\n#### `headers(obj: Record<string, string>)`\n\nAppends the request headers.\n\n### Response operators\n\n#### `when(predicate: (response: Response) => boolean, ...operators: Array<Operator>)`\n\nConditional operator that executes other operators only on success\nand only if the predicate returns true.\n\n#### `whenError(predicate: (error: Error) => boolean, ...operators: Array<Operator>)`\n\nConditional operator that executes other operators only on failure\nand only if the predicate returns true.\n\n#### `parse(format: 'json' | 'text' | 'blob' | 'arrayBuffer')`\n\nOperator that parses response body into one of available formats.\n\n#### `error<T extends Error>(errorClass: T)`\n\nIf this operator is invoked, it will throw.\n\nIt passes the response object as the first argument to the error constructor.\n\n#### `map(mapper: <T>(res: T) => T)`\n\nMaps the response object. Useful for transformations.\n\n#### `project(keys: Array<string>, mapper?: <T>(obj: T) => T)`\n\nWhen the response is an array of objects, it transforms the objects in such a way,\nthat only the keys that are included in the argument go through.\n\nYou can optionally pass a second argument that will be used to map through every\nprojected object.\n\n#### `prop(key: string)`\n\nWhen the response is an object, return the value of key. Otherwise returns null.\n\n### Meta operators\n\n#### `custom(creator: (...Args) => Operator)`\n\nCreates a custom operator. It is used to group common and repeating operators into one.\n\nThe creator function has to return an operator instance or an array of operator instances.\n\n#### `hook(hookName: string, handler: (args, { params, data, ctx }))`\n\nHooks into internals of `f-fetch`. Only use if you know what you are doing!\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first\nto discuss what you would like to change.\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n","readmeFilename":"README.md"}