{"id":27107247,"url":"https://github.com/andreasnicolaou/safe","last_synced_at":"2026-04-21T14:32:05.283Z","repository":{"id":285220668,"uuid":"957447909","full_name":"andreasnicolaou/safe","owner":"andreasnicolaou","description":"A simple utility for handling synchronous and asynchronous errors without relying on try-catch blocks.","archived":false,"fork":false,"pushed_at":"2026-04-06T08:57:49.000Z","size":629,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-06T10:26:49.518Z","etag":null,"topics":["exponential-backoff","retry-strategies","try-catch","utility-library"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andreasnicolaou.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-03-30T11:59:50.000Z","updated_at":"2026-04-06T08:57:46.000Z","dependencies_parsed_at":"2025-06-01T22:31:16.034Z","dependency_job_id":"26922db6-c205-4da4-8425-2ebd32a228a6","html_url":"https://github.com/andreasnicolaou/safe","commit_stats":null,"previous_names":["andreasnicolaou/safe"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/andreasnicolaou/safe","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreasnicolaou%2Fsafe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreasnicolaou%2Fsafe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreasnicolaou%2Fsafe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreasnicolaou%2Fsafe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreasnicolaou","download_url":"https://codeload.github.com/andreasnicolaou/safe/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreasnicolaou%2Fsafe/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32095828,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T11:25:29.218Z","status":"ssl_error","status_checked_at":"2026-04-21T11:25:28.499Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["exponential-backoff","retry-strategies","try-catch","utility-library"],"created_at":"2025-04-06T20:33:06.764Z","updated_at":"2026-04-21T14:32:05.268Z","avatar_url":"https://github.com/andreasnicolaou.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @andreasnicolaou/safe — Say Goodbye to Try-Catch Blocks!\n\n![TypeScript](https://img.shields.io/badge/TS-TypeScript-3178c6?logo=typescript\u0026logoColor=white)\n![GitHub contributors](https://img.shields.io/github/contributors/andreasnicolaou/safe)\n![GitHub License](https://img.shields.io/github/license/andreasnicolaou/safe)\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/andreasnicolaou/safe/build.yaml)\n![GitHub package.json version](https://img.shields.io/github/package-json/v/andreasnicolaou/safe)\n[![Known Vulnerabilities](https://snyk.io/test/github/andreasnicolaou/safe/badge.svg)](https://snyk.io/test/github/andreasnicolaou/safe)\n![Bundle Size](https://deno.bundlejs.com/badge?q=@andreasnicolaou/safe\u0026treeshake=[*])\n\n![ESLint](https://img.shields.io/badge/linter-eslint-4B32C3.svg?logo=eslint)\n![Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?logo=prettier)\n![Jest](https://img.shields.io/badge/tested_with-jest-99424f.svg?logo=jest)\n![Maintenance](https://img.shields.io/maintenance/yes/2026)\n[![codecov](https://codecov.io/gh/andreasnicolaou/safe/graph/badge.svg?token=9CPNF2XE59)](https://codecov.io/gh/andreasnicolaou/safe)\n\n![NPM Downloads](https://img.shields.io/npm/dm/%40andreasnicolaou%2Fsafe)\n\n### **Tired of writing `try...catch` everywhere?**\n\nLet `@andreasnicolaou/safe` handle it for you. This tiny, library automatically wraps your functions and promises in a safe execution environment.\n\n## Features\n\n- **No more try-catch everywhere:** Clean up your code by handling errors in one place.\n- **Works with sync and async:** One API for both synchronous and asynchronous code.\n- **TypeScript-first:** Full type inference and guards for safer code.\n- **Customizable logging:** Plug in your own logger or error reporting.\n- **Framework-agnostic:** Use in Node.js, browsers, React and more.\n\n### Package Managers\n\n```bash\n# npm\nnpm install @andreasnicolaou/safe\n\n# yarn\nyarn add @andreasnicolaou/safe\n\n# pnpm\npnpm add @andreasnicolaou/safe\n```\n\n## CDN Usage\n\nFor direct browser usage without a build step:\n\n```html\n\u003c!-- unpkg CDN (latest version, unminified) --\u003e\n\u003cscript src=\"https://unpkg.com/@andreasnicolaou/safe/dist/index.umd.js\"\u003e\u003c/script\u003e\n\n\u003c!-- unpkg CDN (latest version, minified) --\u003e\n\u003cscript src=\"https://unpkg.com/@andreasnicolaou/safe/dist/index.umd.min.js\"\u003e\u003c/script\u003e\n\n\u003c!-- jsDelivr CDN (unminified) --\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/@andreasnicolaou/safe/dist/index.umd.js\"\u003e\u003c/script\u003e\n\n\u003c!-- jsDelivr CDN (minified) --\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/@andreasnicolaou/safe/dist/index.umd.min.js\"\u003e\u003c/script\u003e\n```\n\nThe library will be available as `safe` on the global scope:\n\n```html\n\u003cscript\u003e\n  // Example: use safe utilities from the global `safe` object\n  const { safe: safeFn, isSuccess, isFailure } = safe;\n  const [error, result] = safeFn(() =\u003e JSON.parse('{\"foo\": 123}'));\n  if (isSuccess([error, result])) {\n    console.log('Parsed:', result);\n  }\n\u003c/script\u003e\n```\n\n## Usage\n\nYou can use this library in any modern JavaScript environment:\n\n### ESM (ECMAScript Modules)\n\n```js\nimport { safe, isSuccess, isFailure } from '@andreasnicolaou/safe';\n\nconst [error, result] = safe(() =\u003e JSON.parse('{\"foo\": 123}'));\nif (isSuccess([error, result])) {\n  console.log('Parsed:', result);\n}\n```\n\n### CommonJS (Node.js require)\n\n```js\nconst { safe, isSuccess, isFailure } = require('@andreasnicolaou/safe');\n\nconst [error, result] = safe(() =\u003e JSON.parse('{\"foo\": 123}'));\nif (isSuccess([error, result])) {\n  console.log('Parsed:', result);\n}\n```\n\n### UMD (CDN/Browser)\n\n```html\n\u003cscript src=\"https://unpkg.com/@andreasnicolaou/safe/dist/index.umd.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  const { safe: safeFn, isSuccess, isFailure } = safe;\n  const [error, result] = safeFn(() =\u003e JSON.parse('{\"foo\": 123}'));\n  if (isSuccess([error, result])) {\n    console.log('Parsed:', result);\n  }\n\u003c/script\u003e\n```\n\n## Basic Usage\n\n```typescript\nimport { safe, isSuccess, isFailure } from '@andreasnicolaou/safe';\n\nconst [error, result] = safe(() =\u003e {\n  throw new Error('An error Occured!');\n});\n\nconsole.log(error); // An error Occured!\nconsole.log(result); // undefined\nconsole.log(isSuccess([error, result])); // false\nconsole.log(isFailure([error, result])); // true\n```\n\n## Advanced Error Handling\n\n```typescript\nconst { safe, safeWithRetries } = createSafeUtils({\n  logger: (error) =\u003e sentry.captureException(error),\n  logErrors: process.env.NODE_ENV === 'production',\n});\n```\n\n## Architecture Benefits\n\n- **Functional Programming Friendly**  \n  Compose operations without error handling noise\n- **TypeScript Optimized**  \n  Full type inference and guards\n- **Framework Agnostic**  \n  Works with React, Node.js, Deno, etc.\n\n## Related\n\n- [Error Handling in TypeScript](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#unknown-on-catch-clause-bindings)\n- [RxJS Error Handling](https://rxjs.dev/guide/operators#error-handling-operators)\n\n## Contributing\n\nContributions are welcome! If you encounter issues or have ideas to enhance the library, feel free to submit an issue or pull request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreasnicolaou%2Fsafe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreasnicolaou%2Fsafe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreasnicolaou%2Fsafe/lists"}