{"id":26587935,"url":"https://github.com/rahulc0dy/safe-execute","last_synced_at":"2026-02-17T01:33:39.916Z","repository":{"id":283457286,"uuid":"951854383","full_name":"rahulc0dy/safe-execute","owner":"rahulc0dy","description":"npm install @rahulc0dy/safe-execute","archived":false,"fork":false,"pushed_at":"2025-03-30T08:05:18.000Z","size":65,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-04T09:00:29.496Z","etag":null,"topics":["cache","debounce","error-handling","function","function-caching","javascript","npm","package","throttle","typescript","utility"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/@rahulc0dy/safe-execute","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/rahulc0dy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-20T10:51:32.000Z","updated_at":"2025-03-30T08:05:22.000Z","dependencies_parsed_at":"2025-03-21T13:48:06.854Z","dependency_job_id":null,"html_url":"https://github.com/rahulc0dy/safe-execute","commit_stats":null,"previous_names":["rahulc0dy/safe-execute"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/rahulc0dy/safe-execute","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahulc0dy%2Fsafe-execute","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahulc0dy%2Fsafe-execute/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahulc0dy%2Fsafe-execute/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahulc0dy%2Fsafe-execute/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rahulc0dy","download_url":"https://codeload.github.com/rahulc0dy/safe-execute/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahulc0dy%2Fsafe-execute/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29529482,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T00:57:22.232Z","status":"ssl_error","status_checked_at":"2026-02-17T00:54:25.811Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["cache","debounce","error-handling","function","function-caching","javascript","npm","package","throttle","typescript","utility"],"created_at":"2025-03-23T12:31:33.868Z","updated_at":"2026-02-17T01:33:39.909Z","avatar_url":"https://github.com/rahulc0dy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\" style=\"display: flex; justify-content: center;\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@rahulc0dy/safe-execute\" style=\"margin-right: 8px; margin-bottom: 5px;\"\u003e\n    \u003cimg alt=\"GitHub package.json version (branch)\" src=\"https://badgen.net/npm/dt/@rahulc0dy/safe-execute\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/rahulc0dy/safe-execute/releases\" style=\"margin-right: 8px; margin-bottom: 5px;\"\u003e\n    \u003cimg alt=\"GitHub package.json version (branch)\" src=\"https://img.shields.io/github/package-json/v/rahulc0dy/safe-execute\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@rahulc0dy/safe-execute\" style=\"margin-right: 8px; margin-bottom: 5px;\"\u003e\n    \u003cimg alt=\"GitHub package.json version (branch)\" src=\"https://badgen.net/npm/node/@rahulc0dy/safe-execute\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@rahulc0dy/safe-execute\" style=\"margin-right: 8px; margin-bottom: 5px;\"\u003e\n    \u003cimg alt=\"GitHub package.json version (branch)\" src=\"https://badgen.net/github/license/rahulc0dy/safe-execute\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@rahulc0dy/safe-execute\" style=\"margin-right: 8px; margin-bottom: 5px;\"\u003e\n    \u003cimg alt=\"GitHub package.json version (branch)\" src=\"https://badgen.net/github/releases/rahulc0dy/safe-execute\"\u003e\n  \u003c/a\u003e\n  \u003cbr\u003e\n  \u003ca href=\"https://github.com/rahulc0dy/safe-execute/issues\" style=\"margin-right: 8px; margin-bottom: 5px;\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/issues/rahulc0dy/safe-execute\" alt=\"Issues\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/rahulc0dy/safe-execute\" style=\"margin-right: 8px; margin-bottom: 5px;\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/stars/rahulc0dy/safe-execute\" alt=\"GitHub Stars\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/rahulc0dy/safe-execute\" style=\"margin-right: 8px; margin-bottom: 5px;\"\u003e\n    \u003cimg src=\"https://img.shields.io/coderabbit/prs/github/rahulc0dy/safe-execute?utm_source=oss\u0026utm_medium=github\u0026utm_campaign=rahulc0dy%2Fsafe-execute\u0026labelColor=171717\u0026color=FF570A\u0026link=https%3A%2F%2Fcoderabbit.ai\u0026label=CodeRabbit+Reviews\" alt=\"CodeRabbit Reviews\"\u003e\n  \u003c/a\u003e\n  \u003cbr\u003e\n  \u003ca href=\"https://github.com/rahulc0dy/safe-execute/actions/workflows/tests.yml\" style=\"margin-right: 8px; margin-bottom: 5px;\"\u003e\n    \u003cimg src=\"https://github.com/rahulc0dy/safe-execute/actions/workflows/tests.yml/badge.svg\" alt=\"Test Status\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/rahulc0dy/safe-execute/actions/workflows/builds.yml\" style=\"margin-right: 8px; margin-bottom: 5px;\"\u003e\n    \u003cimg src=\"https://github.com/rahulc0dy/safe-execute/actions/workflows/builds.yml/badge.svg\" alt=\"Build Status\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n# Safe Execute\n\nSafe Execute is a versatile utility library that simplifies the execution of asynchronous tasks while handling errors gracefully. It not only provides core functions like tryCatch and safeExecute, but also includes three additional utilities—throttle, debounce, and cache—to improve performance and control.\n\n## Installation\n\nYou can add Safe Execute to your project using npm or pnpm:\n\n- Using `npm`:\n\n  ```bash\n  npm install @rahulc0dy/safe-execute\n  ```\n\n- Using `pnpm`:\n\n  ```bash\n  pnpm add @rahulc0dy/safe-execute\n  ```\n\n## Usage\n\n### Core Functions\n\n- **tryCatch**  \n  Execute a promise safely and get either the data or error without try/catch blocks.\n\n- **safeExecute**  \n  Run synchronous or asynchronous functions with built-in error handling and optional callbacks.\n\n### Additional Utility Functions\n\n- **throttle**  \n  Rate-limit a function so it executes at most once per defined interval.\n\n- **debounce**  \n  Delay function execution until a period of inactivity, ideal for inputs and filtering.\n\n- **cache**  \n  Cache the result of asynchronous calls to prevent redundant execution.\n\nFor detailed usage examples and API descriptions, refer to the sections below or check the documentation within your IDE.\n\n## API Overview\n\n### tryCatch\n\n**Signature:**\n\n```typescript\nasync function tryCatch\u003cT, E = Error\u003e(\n  promise: Promise\u003cT\u003e\n): Promise\u003c{ data: T | null; error: E | null }\u003e;\n```\n\n- On success: `{ data: T, error: null }`\n- On failure: `{ data: null, error: E }`\n\n### safeExecute\n\n**Signature:**\n\n```typescript\nasync function safeExecute\u003cT\u003e(\n  fn: () =\u003e Promise\u003cT\u003e | T,\n  options?: {\n    onSuccess?: (result: T) =\u003e void;\n    onError?: (error: unknown) =\u003e void;\n    timeoutMs?: number;\n  }\n): Promise\u003c{\n  data: T | null;\n  isError: boolean;\n  isSuccess: boolean;\n  isLoading: boolean;\n  error: unknown;\n}\u003e;\n```\n\nExecutes a given function safely, handling both synchronous and asynchronous operations, with optional callbacks and a timeout.\n\n### throttle\n\n**Signature:**\n\n```typescript\nfunction throttle\u003cT extends (...args: any[]) =\u003e any\u003e(fn: T, wait: number): T;\n```\n\nReturns a throttled version of the function that only executes once within the specified wait time.\n\n### debounce\n\n**Signature:**\n\n```typescript\nfunction debounce\u003cT extends (...args: any[]) =\u003e any\u003e(fn: T, delay: number): T;\n```\n\nReturns a debounced version of the function that delays execution until after the delay period has passed without further invocation.\n\n### cache\n\n**Signature:**\n\n```typescript\nfunction cache\u003cT extends (...args: any[]) =\u003e Promise\u003cany\u003e\u003e(fn: T): T;\n```\n\nCaches the result of asynchronous function calls to avoid redundant executions when called with the same arguments.\n\n## Contributing\n\nContributions are welcome! Please refer to our [contributing guidelines](CONTRIBUTING.md) for details on how to help improve the project.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n\n## Support\n\nIf you encounter any issues or have questions, please open an [issue](https://github.com/rahulc0dy/safe-execute/issues) for assistance.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frahulc0dy%2Fsafe-execute","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frahulc0dy%2Fsafe-execute","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frahulc0dy%2Fsafe-execute/lists"}