{"_id":"@avearistov/fa-fo","name":"@avearistov/fa-fo","dist-tags":{"latest":"2.0.0"},"versions":{"2.0.0":{"name":"@avearistov/fa-fo","private":false,"version":"2.0.0","module":"dist/index.cjs","typings":"dist/index.d.ts","main":"dist/index.js","type":"module","description":"A TypeScript Result type for when you want to f around and find out","author":{"name":"Ave Aristov","email":"chantepkik@gmail.com","url":"https://www.avearistov.com/"},"license":"MIT","repository":{"type":"github","url":"git+https://github.com/avevotsira/fuck-around.git"},"devDependencies":{"@changesets/cli":"^2.27.1","tsup":"^8.0.1","typescript":"^5.0.2","vitest":"3.1.1"},"bugs":{"url":"https://github.com/avevotsira/fuck-around/issues"},"homepage":"https://github.com/avevotsira/fuck-around#readme","scripts":{"build":"tsup src/index.ts --format cjs,esm --dts --minify","test:run":"vitest --run","test:watch":"vitest --watch","typecheck":"tsc --noEmit","ci":"pnpm run test:run && pnpm run typecheck && pnpm run build","release":"pnpm run ci && changeset publish"},"_id":"@avearistov/fa-fo@2.0.0","_integrity":"sha512-rG88no2Uhf9Ge38L0uRpirp4loufQEA82s86uoTF7JDFgTugDw5AhxTRLDWQdM00khBoimzqbeh3GbQofwUMfg==","_resolved":"/tmp/f18ad2d969adbf4d9ca2aab956898d4a/avearistov-fa-fo-2.0.0.tgz","_from":"file:avearistov-fa-fo-2.0.0.tgz","_nodeVersion":"18.20.7","_npmVersion":"10.8.2","dist":{"integrity":"sha512-rG88no2Uhf9Ge38L0uRpirp4loufQEA82s86uoTF7JDFgTugDw5AhxTRLDWQdM00khBoimzqbeh3GbQofwUMfg==","shasum":"e8ffe244647a88c8ac5c24b40d06f73d8ad1b184","tarball":"https://registry.npmjs.org/@avearistov/fa-fo/-/fa-fo-2.0.0.tgz","fileCount":7,"unpackedSize":15777,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIH0E1fQooWjI8P0CWE4O51gxdstI9BUIoFNLVss170nbAiEAuX/daOgdFevZ1ajy+PmqavQbfxb2DOnovl23xwGan2s="}]},"_npmUser":{"name":"avearistov","email":"chantepkik@gmail.com"},"directories":{},"maintainers":[{"name":"avearistov","email":"chantepkik@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/fa-fo_2.0.0_1743505613874_0.26683367422252147"},"_hasShrinkwrap":false}},"time":{"created":"2025-04-01T11:06:53.794Z","2.0.0":"2025-04-01T11:06:54.052Z","modified":"2025-04-01T11:06:54.299Z"},"maintainers":[{"name":"avearistov","email":"chantepkik@gmail.com"}],"description":"A TypeScript Result type for when you want to f around and find out","homepage":"https://github.com/avevotsira/fuck-around#readme","repository":{"type":"github","url":"git+https://github.com/avevotsira/fuck-around.git"},"author":{"name":"Ave Aristov","email":"chantepkik@gmail.com","url":"https://www.avearistov.com/"},"bugs":{"url":"https://github.com/avevotsira/fuck-around/issues"},"license":"MIT","readme":"# @ave/fuck-around\n\nA minimal implementation of the Result type in TypeScript. Allowing you to handle success and error states in a more explicit and structured way.\n\n### Installation\n\n```bash\nnpm install @avearistov/fa-fo\n\nyarn add @avearistov/fa-fo\n\npnpm add @avearistov/fa-fo\n\nbun add @avearistov/fa-fo\n```\n\n### Docs\n\n- [API](#api)\n- [Creating a Result](#creating-a-result)\n- [Checking Result Type](#checking-result-type)\n- [Unwrapping Result](#unwrapping-result)\n- [Transforming Result](#transforming-result)\n\n### API\n\n```ts\n// A result is either successful or you find out what happens\ntype Result<T> = FuckedAround<T> | FoundOut;\n\n// When you fuck around and it works\ntype FuckedAround<T> = { value: T; consequences: null };\n\n// When you find out what happens\ntype FoundOut = { value: null; consequences: Error };\n```\n\n### Creating a Result\n\nYou can create a result using the fuckAround or findOut function:\n\n```typescript\nimport { fuckAround, findOut } from \"@justmiracle/result\";\n\nconst successResult: Result<number> = fuckAround(42);\n// { value: 42, consequences: null }\n\nconst errorResult: Result<number> = findOut(\n  new Error(\"Found out the hard way\")\n);\n// { value: null, consequences: Error }\n\n// consequences can be anything, if it's not an Error it will be converted to one\nconst errorResult: Result<number> = findOut(\"Found out the hard way\");\n// { value: null, consequences: Error }\n```\n\n### Checking Result Type\n\nYou can check if a result worked using the didItWork function:\n\n```typescript\nif (didItWork(successResult)) {\n  console.log(\"Nice!\", successResult.value);\n} else {\n  console.error(\"Found out:\", successResult.consequences.message);\n}\n```\n\nYou can check if a result is an error using the didYouFuckUp function:\n\n```typescript\nif (didYouFuckUp(errorResult)) {\n  console.error(\"Found out:\", errorResult.consequences.message);\n} else {\n  console.log(\"Nice!\", errorResult.value);\n}\n```\n\n### Unwrapping Result\n\nYou can unwrap the value from a result type using `unwrapOr`, this will return the value if the result worked or a default value if it's an error:\n\n```typescript\nconst resultOne = fuckAround(42);\nconst value = unwrapOr(resultOne, 12); // 42\n\nconst resultTwo = findOut(\"Found out the hard way\");\nconst value = unwrapOr(resultTwo, 12); // 12 default value\n```\n\nYou can also unwrap the value from a successful result using `unwrap`, which throws an error for an error result:\n\n> [!WARNING]\n> This will throw an error if you fucked up, so make sure to handle it properly.\n\n```typescript\nconst resultOne = fuckAround(42);\nconst value = unwrap(resultOne); // 42\n\nconst resultTwo = findOut(\"Found out the hard way\");\nconst value = unwrap(resultTwo); // throws an error\n```\n\n### Transforming Result\n\nYou can apply a function to the value inside a successful result using `map`:\n\n```typescript\nconst successResult = fuckAround(42);\nconst mappedResult = map(successResult, (value) => value * 2);\n// { value: 84, consequences: null }\n```\n\n### Roadmap\n\n- [ ] Typesafe error handling\n- [ ] `pipe` function\n\n### Contributing\n\nContributions are welcome, feel free to open an issue or a pull request.🍀\n\n","readmeFilename":"README.md","_rev":"1-ec6dd76db11aa9845b0fe7591479131d"}