{"_id":"@alex6357/tsresult","name":"@alex6357/tsresult","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@alex6357/tsresult","version":"1.0.0","description":"Implement Rust-like Result and Option types for TypeScript","keywords":["typescript","rust","result","option","error-safe","error-handling","type-safe","monad"],"license":"MIT","author":{"name":"Alex6357","url":"https://github.com/Alex6357"},"type":"module","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./core":{"types":"./dist/core/index.d.ts","default":"./dist/core/index.js"},"./core/newable":{"types":"./dist/core/newable.d.ts","default":"./dist/core/newable.js"},"./extensions/result/*":{"types":"./dist/extensions/result/*.d.ts","default":"./dist/extensions/result/*.js"},"./extnesions/option/*":{"types":"./dist/extensions/option/*.d.ts","default":"./dist/extensions/option/*.js"},"./extensions/all":{"types":"./dist/extensions/all.d.ts","default":"./dist/extensions/all.js"},"./extensions":{"types":"./dist/extensions/index.d.ts","default":"./dist/extensions/index.js"}},"main":"dist/index.js","devDependencies":{"@eslint/js":"^9.39.1","@jest/globals":"^30.2.0","@types/node":"^24.10.1","eslint":"^9.39.1","jest":"^30.2.0","jiti":"^2.6.1","prettier":"^3.7.4","rimraf":"^6.1.2","ts-jest":"^29.4.6","typescript":"^5.9.3","typescript-eslint":"^8.48.1"},"devEngines":{"packageManager":{"name":"pnpm","version":">=10.0.0 <11"},"runtime":{"name":"node","version":">=24.0.0"}},"scripts":{"build":"rimraf dist && tsc","check":"tsc --noEmit","format":"prettier --write src/**/*.ts","lint":"eslint --fix src/**/*.ts","test":"pnpm jest"},"types":"./dist/index.d.ts","_id":"@alex6357/tsresult@1.0.0","_integrity":"sha512-/3118tUiCGZOURsEmyyZ+8UkCwBZ+PqbHyGHvIoD06F0FVaRYD9n1jxGwmeJ8z9HcAMANAGYBmSOZWPY+Xy2RA==","_resolved":"C:\\Users\\Alex11\\AppData\\Local\\Temp\\00857b92f1d14cbdd9db713b8b8744a1\\alex6357-tsresult-1.0.0.tgz","_from":"file:alex6357-tsresult-1.0.0.tgz","_nodeVersion":"24.11.1","_npmVersion":"11.6.2","dist":{"integrity":"sha512-/3118tUiCGZOURsEmyyZ+8UkCwBZ+PqbHyGHvIoD06F0FVaRYD9n1jxGwmeJ8z9HcAMANAGYBmSOZWPY+Xy2RA==","shasum":"d409b3d1b8ff3600bbec663232bdfff54734417a","tarball":"https://registry.npmjs.org/@alex6357/tsresult/-/tsresult-1.0.0.tgz","fileCount":59,"unpackedSize":59716,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIGxM+DFkSJxx8g0qcDdtvTDCPJ3CQBuHVO3dTBuhYeRaAiBXsZ0DhoxZo/1ePawpGtOhpsdSdFHe5x75FgTn1tTvyQ=="}]},"_npmUser":{"name":"alex6357","email":"1746907849@qq.com"},"directories":{},"maintainers":[{"name":"alex6357","email":"1746907849@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/tsresult_1.0.0_1765034113978_0.12320141991920197"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-06T15:15:13.878Z","1.0.0":"2025-12-06T15:15:14.122Z","modified":"2025-12-06T15:15:14.401Z"},"maintainers":[{"name":"alex6357","email":"1746907849@qq.com"}],"description":"Implement Rust-like Result and Option types for TypeScript","keywords":["typescript","rust","result","option","error-safe","error-handling","type-safe","monad"],"author":{"name":"Alex6357","url":"https://github.com/Alex6357"},"license":"MIT","readme":"# tsresult\n\n[![NPM Version](https://img.shields.io/npm/v/tsresult)](https://www.npmjs.com/package/tsresult)\n[![License](https://img.shields.io/npm/l/tsresult)](https://github.com/Alex6357/tsresult/blob/main/LICENSE)\n\nA TypeScript library that implements Rust-like Result and Option types for safer error handling and nullable value management.\n\n## Features\n\n- 🔒 **Type Safety**: Brings Rust's powerful `Result` and `Option` types to TypeScript\n- 🛡️ **Error Handling**: Eliminate null/undefined runtime errors with compile-time safety\n- 🧩 **Functional Approach**: Monad operations like `map`, `andThen`, `orElse`, etc.\n- 🚀 **Zero Dependencies**: Lightweight library with no external dependencies\n- 📦 **Tree-shakable**: Import only what you need\n- 💪 **Fully Typed**: Complete TypeScript support with excellent IDE integration\n- 🧰 **Rich Utility Extensions**: Extensive practical extensions that can be selectively imported\n\n## Installation\n\n```bash\nnpm install tsresult\n# or\nyarn add tsresult\n# or\npnpm add tsresult\n```\n\n## Usage\n\n### Result Type\n\nThe `Result<T, E>` type represents either success (`Ok`) or failure (`Err`).\n\n```typescript\nimport { ok, err, type Result } from \"tsresult\";\n\n// Function that might fail\nfunction divide(a: number, b: number): Result<number, string> {\n  if (b === 0) {\n    return err(\"Cannot divide by zero\");\n  }\n  return ok(a / b);\n}\n\n// Using the result\nconst result = divide(10, 2);\nif (result.isOk()) {\n  console.log(\"Result:\", result.unwrap()); // 5\n} else {\n  console.error(\"Error:\", result.unwrapErr());\n}\n\n// Chaining operations\ndivide(10, 2)\n  .map((x) => x * 2)\n  .map((x) => `Value is ${x}`)\n  .inspect(console.log); // \"Value is 10\"\n```\n\n### Option Type\n\nThe `Option<T>` type represents an optional value: every Option is either `Some` and contains a value, or `None` and does not.\n\n```typescript\nimport { some, none, type Option } from \"tsresult\";\n\n// Function that might return nothing\nfunction findUser(id: number): Option<User> {\n  const user = database.find((u) => u.id === id);\n  return user ? some(user) : none();\n}\n\n// Using the option\nconst user = findUser(123);\nif (user.isSome()) {\n  console.log(\"Found user:\", user.unwrap());\n} else {\n  console.log(\"User not found\");\n}\n\n// Safe operations\nuser\n  .map((u) => u.name)\n  .map((name) => `Hello, ${name}!`)\n  .inspect(console.log);\n```\n\n### Extensions\n\nThe library includes helpful extensions:\n\n```typescript\nimport \"tsresult/extensions/all\";\n\n// Convert Result to tuple\nconst [value, error] = result.toTuple();\n\n// Convert Option to nullable\nconst nullableValue = option.toNullable();\n```\n\n### Core-only Import (without extensions)\n\nIf you prefer to selectively load only the functionality you need, import from the core module:\n\n```typescript\nimport { Result, Option, ok, err, some, none } from \"tsresult/core\";\n// Extensions are not loaded by default\n// You can import them explicitly if needed\n```\n\nWith core-only imports, extensions like [toTuple](file://e:\\Develop\\github\\tsresult\\src\\extensions\\result\\toTuple.ts#L3-L9) and [toNullable](file://e:\\Develop\\github\\tsresult\\test.ts#L6-L6) are not automatically available. You must explicitly import the extensions you want to use:\n\n```typescript\nimport \"tsresult/extensions/result/toTuple\";\nimport \"tsresult/extensions/option/toNullable\";\n\n// Now these extensions are available\nconst [value, error] = result.toTuple();\nconst nullable = option.toNullable();\n```\n\nThis approach allows for more fine-grained control over bundle size and only includes the extensions you actually use.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Contributing\n\nContributions are welcome! Feel free to open issues and pull requests.\n","readmeFilename":"README.md","_rev":"1-14f646bc9dc5e916187d0c79add6c39c"}