{"_id":"cope","_rev":"42-87a856163515bdc7867409e596487417","name":"cope","dist-tags":{"latest":"1.0.9"},"versions":{"1.0.2":{"name":"cope","version":"1.0.2","keywords":["error","handling","cope"],"author":{"name":"Lucifurry"},"license":"ISC","_id":"cope@1.0.2","maintainers":[{"name":"lucifurry","email":"thelucifurry@gmail.com"}],"homepage":"https://github.com/TheLucifurry/cope#readme","bugs":{"url":"https://github.com/TheLucifurry/cope/issues"},"dist":{"shasum":"39d816c291c8c461fd27ee68da4e8b417de36836","tarball":"https://registry.npmjs.org/cope/-/cope-1.0.2.tgz","fileCount":4,"integrity":"sha512-f0KLfp1QZdVIa2DtF2Q7TnaoSRfponRrSBYfY/2lXiZXjs6UnzuHHuMkc1/u+wcc+taj3m9kuAYIqfoKnfF4aw==","signatures":[{"sig":"MEYCIQCSo9LFfntKxEBj+NEgKK2qrehaW0nRCD38jEFrtTAb+AIhAInRTEUHtMfUmlo4VGYJs20wrOK02dY8neOxN01ueKoE","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2399},"type":"module","types":"./index.d.ts","module":"index.js","exports":{"./*":{"types":"./index.d.ts","import":"./index.js","default":"./index.js"}},"gitHead":"835b031a67988914f1af9da8266369bbe4da0ac9","scripts":{"dev":"bun test --watch","build":"tsc index.ts --noCheck && bun build ./index.ts --outdir ."},"_npmUser":{"name":"lucifurry","email":"thelucifurry@gmail.com"},"repository":{"url":"git+https://github.com/TheLucifurry/cope.git","type":"git"},"_npmVersion":"10.2.3","description":"Simple error handling util, inspired by Golang solution","directories":{},"_nodeVersion":"20.10.0","_hasShrinkwrap":false,"devDependencies":{"@types/bun":"latest"},"peerDependencies":{"typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/cope_1.0.2_1730788863711_0.9493780776338925","host":"s3://npm-registry-packages"}},"1.0.3":{"name":"cope","version":"1.0.3","keywords":["error","handling","cope"],"author":{"name":"Lucifurry"},"license":"ISC","_id":"cope@1.0.3","maintainers":[{"name":"lucifurry","email":"thelucifurry@gmail.com"}],"homepage":"https://github.com/TheLucifurry/cope#readme","bugs":{"url":"https://github.com/TheLucifurry/cope/issues"},"dist":{"shasum":"23eace023b3e193953d36dfa9abdca51c650524b","tarball":"https://registry.npmjs.org/cope/-/cope-1.0.3.tgz","fileCount":4,"integrity":"sha512-JayHC5533da0yW51Vyg7O0KzgDD0VEeANpqQBs0KIhlY6vRoaB8XeB5zaGu9qjMLhVD8uQLH4iGXhH8WyTgHbg==","signatures":[{"sig":"MEQCIAd6RXzZV0qNZ7055b9mnbk3m7Oyj4rdgaDIGx6L/83eAiAWTWKWMUvdWWDn/tzBc5xqrfMEc6OX9dnZbI3hW3GGqA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":4638},"type":"module","types":"./index.d.ts","module":"index.js","exports":{"./*":{"types":"./index.d.ts","import":"./index.js","default":"./index.js"}},"gitHead":"3a98db5f0dfad3642d7b29914ba42cb2d4ecd022","scripts":{"dev":"bun test --watch","build":"tsc index.ts --noCheck && bun build ./index.ts --outdir .","publish":"npm publish","new-version:minor":"npm version minor","new-version:patch":"npm version patch"},"_npmUser":{"name":"lucifurry","email":"thelucifurry@gmail.com"},"repository":{"url":"git+https://github.com/TheLucifurry/cope.git","type":"git"},"_npmVersion":"10.2.3","description":"Simple error handling util, inspired by Golang solution","directories":{},"_nodeVersion":"20.10.0","_hasShrinkwrap":false,"devDependencies":{"@types/bun":"latest"},"peerDependencies":{"typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/cope_1.0.3_1730802886233_0.023086034341438078","host":"s3://npm-registry-packages"}},"1.0.4":{"name":"cope","version":"1.0.4","keywords":["error","handling","cope"],"author":{"name":"Lucifurry"},"license":"ISC","_id":"cope@1.0.4","maintainers":[{"name":"lucifurry","email":"thelucifurry@gmail.com"}],"homepage":"https://github.com/TheLucifurry/cope#readme","bugs":{"url":"https://github.com/TheLucifurry/cope/issues"},"dist":{"shasum":"8b7114bf5443f2230ef6ca2a5a14371e386d2d44","tarball":"https://registry.npmjs.org/cope/-/cope-1.0.4.tgz","fileCount":4,"integrity":"sha512-nl4v6Cu4J+JV+Ge9S1bOsyi5hSwh7/nTrb3iaA8YWNKkwzlAMwUptWEChCsk8Y7MEKuyGExgeP9QGYwaOIqQOA==","signatures":[{"sig":"MEQCIA2g2y7wtOV00SpnVuiu7WR1dmka4UnRww1qlO6pZYBkAiAkPev8OETZah3fm+vjeDks1ShdIqFuREW1UjjwDHMt+g==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":4638},"type":"module","types":"./index.d.ts","module":"index.js","exports":{"./*":{"types":"./index.d.ts","import":"./index.js","default":"./index.js"}},"gitHead":"4d2478601f9ba546b52c6434a8a1f5fbd3f804d0","scripts":{"dev":"bun test --watch","build":"tsc index.ts --noCheck && bun build ./index.ts --outdir .","publish":"npm publish","new-version:minor":"npm version minor","new-version:patch":"npm version patch"},"_npmUser":{"name":"lucifurry","email":"thelucifurry@gmail.com"},"repository":{"url":"git+https://github.com/TheLucifurry/cope.git","type":"git"},"_npmVersion":"10.2.3","description":"Simple error handling util, inspired by Golang solution","directories":{},"_nodeVersion":"20.10.0","_hasShrinkwrap":false,"devDependencies":{"@types/bun":"latest"},"peerDependencies":{"typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/cope_1.0.4_1730802909576_0.661860402754022","host":"s3://npm-registry-packages"}},"1.0.6":{"name":"cope","version":"1.0.6","keywords":["error","handling","cope"],"author":{"name":"Lucifurry"},"license":"ISC","_id":"cope@1.0.6","maintainers":[{"name":"lucifurry","email":"thelucifurry@gmail.com"}],"homepage":"https://github.com/TheLucifurry/cope#readme","bugs":{"url":"https://github.com/TheLucifurry/cope/issues"},"dist":{"shasum":"60eeb2b93916cc94ad9e1914abe7861bf836fd06","tarball":"https://registry.npmjs.org/cope/-/cope-1.0.6.tgz","fileCount":4,"integrity":"sha512-Hj2RGO+X9PhUlDeLIB+UnHj8JzbleAK6QqfGWJM7HD7fjgNoijlc2kBj+HU0jlxKbPfZ6LtSqAdGpj/dTxDC6Q==","signatures":[{"sig":"MEUCIQCe2sFhWbnOznHzpRUpcfnjtNTUH4ni/E+PuaOkrOZRwgIgHfrGM0pZg+sBRvxXiNuEfRxnN5u7KucOuuR6oA27i14=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":4638},"type":"module","types":"./index.d.ts","module":"index.js","exports":{"./*":{"types":"./index.d.ts","import":"./index.js","default":"./index.js"}},"gitHead":"48de7a488aac0a9e7295e867badb9641411ab464","scripts":{"dev":"bun test --watch","build":"tsc index.ts --noCheck && bun build ./index.ts --outdir .","publish":"npm publish","new-version:minor":"npm version minor","new-version:patch":"npm version patch"},"_npmUser":{"name":"lucifurry","email":"thelucifurry@gmail.com"},"repository":{"url":"git+https://github.com/TheLucifurry/cope.git","type":"git"},"_npmVersion":"10.2.3","description":"Simple error handling util, inspired by Golang solution","directories":{},"_nodeVersion":"20.10.0","_hasShrinkwrap":false,"devDependencies":{"@types/bun":"latest"},"peerDependencies":{"typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/cope_1.0.6_1730803274883_0.08307041550982341","host":"s3://npm-registry-packages"}},"1.0.7":{"name":"cope","version":"1.0.7","keywords":["error","handling","cope"],"author":{"name":"Lucifurry"},"license":"ISC","_id":"cope@1.0.7","maintainers":[{"name":"lucifurry","email":"thelucifurry@gmail.com"}],"homepage":"https://github.com/TheLucifurry/cope#readme","bugs":{"url":"https://github.com/TheLucifurry/cope/issues"},"dist":{"shasum":"9c488955792d1fe6de16a7468ee661ac89e34033","tarball":"https://registry.npmjs.org/cope/-/cope-1.0.7.tgz","fileCount":4,"integrity":"sha512-AoFgWQ3tN/71YMrVH8t5D59iJ9je3hwQSZ0HCBmyslPF/eQJl0A9IHNvVJeOujlceQ4KJX6WsM2id9O8WXpdcQ==","signatures":[{"sig":"MEUCIQCOSloW7Eos/IeHLqu/KJsG98VPZxJQv+BnXl1bOSv6ogIgOAzs/RFQpgspUciQ64ihYoOuQUUAQdJ0GNgB3btAY3g=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":4707},"type":"module","types":"./index.d.ts","module":"index.js","exports":{"./*":{"types":"./index.d.ts","import":"./index.js","default":"./index.js"}},"gitHead":"530ba685eb406f2c750ce16e85317638d65c0752","scripts":{"dev":"bun test --watch","build":"tsc index.ts --noCheck && bun build ./index.ts --outdir .","package:publish":"npm publish","package:new-minor":"npm version minor","package:new-patch":"npm version patch"},"_npmUser":{"name":"lucifurry","email":"thelucifurry@gmail.com"},"repository":{"url":"git+https://github.com/TheLucifurry/cope.git","type":"git"},"_npmVersion":"10.2.3","description":"Simple error handling util, inspired by Golang solution","directories":{},"_nodeVersion":"20.10.0","_hasShrinkwrap":false,"devDependencies":{"@types/bun":"latest"},"peerDependencies":{"typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/cope_1.0.7_1730804923711_0.37026368978991075","host":"s3://npm-registry-packages"}},"1.0.8":{"name":"cope","version":"1.0.8","keywords":["error","handling","cope"],"author":{"name":"Lucifurry"},"license":"ISC","_id":"cope@1.0.8","maintainers":[{"name":"lucifurry","email":"thelucifurry@gmail.com"}],"homepage":"https://github.com/TheLucifurry/cope#readme","bugs":{"url":"https://github.com/TheLucifurry/cope/issues"},"dist":{"shasum":"bed3b93c91e8dae3e2f86a925605841d04cf22de","tarball":"https://registry.npmjs.org/cope/-/cope-1.0.8.tgz","fileCount":4,"integrity":"sha512-5vLOsqPxF+nxyatxH9QcsyiDJdJyeZVGltdiU0iXT/WYHvsipvNNNh7zKiXUenRV3q5kALsfdmV8gzhkOv31tQ==","signatures":[{"sig":"MEUCIAtK13bfyGVM21mNlrOXR94537EEbSxjEKHHbPrXeFTZAiEAvMSVA9Ax5tyFVzdumDT99k1POhlkF3N0xf3PU188Cho=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":4707},"type":"module","types":"./index.d.ts","module":"index.js","exports":{"./*":{"types":"./index.d.ts","import":"./index.js","default":"./index.js"}},"gitHead":"719b4293ce36e3fb24dad7b27039133f81212473","scripts":{"dev":"bun test --watch","build":"tsc index.ts --noCheck && bun build ./index.ts --outdir .","package:publish":"npm publish","package:new-minor":"npm version minor","package:new-patch":"npm version patch"},"_npmUser":{"name":"lucifurry","email":"thelucifurry@gmail.com"},"repository":{"url":"git+https://github.com/TheLucifurry/cope.git","type":"git"},"_npmVersion":"10.2.3","description":"Simple error handling util, inspired by Golang solution","directories":{},"_nodeVersion":"20.10.0","_hasShrinkwrap":false,"devDependencies":{"@types/bun":"latest"},"peerDependencies":{"typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/cope_1.0.8_1730874814082_0.08673530876856672","host":"s3://npm-registry-packages"}},"1.0.9":{"name":"cope","version":"1.0.9","description":"Simple error handling util, inspired by Golang solution","module":"index.js","type":"module","exports":{".":{"types":"./index.d.ts","import":"./index.js","default":"./index.js"}},"author":{"name":"Lucifurry"},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/TheLucifurry/cope.git"},"homepage":"https://github.com/TheLucifurry/cope#readme","scripts":{"dev":"bun test --watch","build":"tsc index.ts --noCheck && bun build ./index.ts --outdir .","package:new-patch":"npm version patch","package:new-minor":"npm version minor","package:publish":"git push && npm publish"},"keywords":["error","handling","cope"],"devDependencies":{"@types/bun":"latest"},"peerDependencies":{"typescript":"^5.0.0"},"_id":"cope@1.0.9","gitHead":"297b9fb3d79807662126f5fc80f41527d51be378","types":"./index.d.ts","bugs":{"url":"https://github.com/TheLucifurry/cope/issues"},"_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-m/H58581+vMs2fF6xkoQPNFxVTfSpguy67fv9mR0NDotY6dPY+4TFRkx1HwwFcvkVPTqk1NZBZMcG5JPW1C8bA==","shasum":"b97918d74b9302f36149cac713c1137a5717270b","tarball":"https://registry.npmjs.org/cope/-/cope-1.0.9.tgz","fileCount":4,"unpackedSize":4717,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCTO7enhwAzq9S3a8fMiaWYcCZgmUvari/p/VH2ua8BrQIhAKSz3iHwwdadaoEeabEpoGwkZa1hxR+3avAF0cFdPvWz"}]},"_npmUser":{"name":"lucifurry","email":"thelucifurry@gmail.com"},"directories":{},"maintainers":[{"name":"lucifurry","email":"thelucifurry@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cope_1.0.9_1731037259648_0.7304739760441463"},"_hasShrinkwrap":false}},"time":{"created":"2024-11-05T06:41:03.710Z","modified":"2024-11-08T03:40:59.997Z","0.0.1":"2014-10-02T02:04:22.338Z","0.0.2":"2014-10-02T02:15:14.863Z","0.0.3":"2014-10-14T18:16:50.186Z","0.0.4":"2014-10-14T21:23:47.805Z","0.1.0":"2014-10-21T00:18:16.503Z","0.1.1":"2014-10-21T00:41:36.085Z","0.1.2":"2014-10-21T00:47:20.705Z","0.1.3":"2014-10-21T01:06:15.675Z","1.0.0":"2016-02-02T23:09:28.018Z","1.0.1":"2016-03-19T18:50:36.646Z","1.0.2":"2024-11-05T06:41:03.911Z","1.0.3":"2024-11-05T10:34:46.369Z","1.0.4":"2024-11-05T10:35:09.728Z","1.0.6":"2024-11-05T10:41:15.046Z","1.0.7":"2024-11-05T11:08:43.878Z","1.0.8":"2024-11-06T06:33:34.264Z","1.0.9":"2024-11-08T03:40:59.804Z"},"bugs":{"url":"https://github.com/TheLucifurry/cope/issues"},"author":{"name":"Lucifurry"},"license":"ISC","homepage":"https://github.com/TheLucifurry/cope#readme","keywords":["error","handling","cope"],"repository":{"type":"git","url":"git+https://github.com/TheLucifurry/cope.git"},"description":"Simple error handling util, inspired by Golang solution","maintainers":[{"name":"lucifurry","email":"thelucifurry@gmail.com"}],"readme":"# 👐 cope\n> Simple helper to handle errors, inspired by Golang solution\n\n\n### 💿 Installation\n```bash\npnpm i cope\n```\n<details><summary>Other package managers</summary>\n\n```bash\nnpm i cope\n```\n```bash\nyarn add cope\n```\n</details>\n\n### ❓ Why\n- **Simplicity:** Avoid try/catch blocks scattered across your code\n- **Type Safety:** You know exactly what types to expect in success and failure cases\n- **Consistency:** Standardized structure for handling errors in sync and async code\n\n### 💡 Examples\n\n#### Basic usage:\n```ts\nimport { cope } from 'cope';\n\nconst [result, error] = cope(() => JSON.parse('{\"a\": 123}'));\n\nif (error)\n  // process error\nelse\n  // process result\n```\n\n#### Usage with default:\n```ts\nconst [result = {count: 0}, error] = cope(() => JSON.parse('_broken_\"count\": 123}'));\nif (error)\n  console.warn('fail')\n\n// result is always defined\n```\n> [!NOTE]  \n> This is why, the util returns undefined instead of null\n\n#### Usage with optional execution:\n```ts\ncope(() => window.querySelector('#dynamic-element').scrollTo(123, 0))\n// ...guaranteed executions\n```\n\n#### Asynchronous usage:\nStepwise\n```ts\nconst [fetchResult, fetchingError] = await cope(() => fetch('https://example.com'));\nif (fetchingError) {\n  console.error('Request failed')\n  return\n}\n\nconst [result = null, parsingError] = await cope(() => fetchResult.json());\nif (parsingError)\n  console.warn('Cannot parse response data')\n\n// process result\n```\nOr just\n```ts\nconst [result = null, error] = await cope(\n  () => fetch('https://example.com')).then(d=>d.json())\n);\nif (error) {\n  console.error('Somewhere failed 🌚')\n  return\n}\n\n// process result\n```\n\n\n### 🛠️ API\n```ts\ncope<Throws, Executor, Result>(executor: Executor): CopeResult<Result, Throws>\n```\n- Generics\n  - `Throws` - You can define types of errors, that can be thrown by `executor`. Default is `Error`\n  - `Executor` - Private, don't change it!\n  - `Result` - Private, don't change it!\n\n- Parameters\n  - `executor` (Function): The function to be executed. It can be either a synchronous or asynchronous function.\n\n- Returns\n  - If sync `executor` - [`Result`, undefined] | [undefined, `Throws`]\n  - If async `executor` - Promise<[`Result`, undefined] | [undefined, `Throws`]>","readmeFilename":"README.md"}