{"id":22015419,"url":"https://github.com/tsukinoko-kun/panic","last_synced_at":"2025-03-23T08:44:39.680Z","repository":{"id":78530310,"uuid":"605701510","full_name":"tsukinoko-kun/panic","owner":"tsukinoko-kun","description":"blazingly fast reimplementation of the Error class","archived":false,"fork":false,"pushed_at":"2023-02-25T15:41:42.000Z","size":363,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-14T19:17:28.197Z","etag":null,"topics":["error","error-handling","exception","exception-handling","panic","typescript","typescript-library"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@frank-mayer/panic","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/tsukinoko-kun.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":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-02-23T18:06:02.000Z","updated_at":"2023-03-27T09:26:59.000Z","dependencies_parsed_at":"2023-07-06T14:01:21.462Z","dependency_job_id":null,"html_url":"https://github.com/tsukinoko-kun/panic","commit_stats":null,"previous_names":["tsukinoko-kun/panic","frank-mayer/panic"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsukinoko-kun%2Fpanic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsukinoko-kun%2Fpanic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsukinoko-kun%2Fpanic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsukinoko-kun%2Fpanic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tsukinoko-kun","download_url":"https://codeload.github.com/tsukinoko-kun/panic/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245078128,"owners_count":20557279,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["error","error-handling","exception","exception-handling","panic","typescript","typescript-library"],"created_at":"2024-11-30T04:21:45.341Z","updated_at":"2025-03-23T08:44:39.644Z","avatar_url":"https://github.com/tsukinoko-kun.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# panic\n\n[![Types included](https://img.shields.io/badge/Types-included-blue?logo=typescript\u0026style=plastic)](https://www.typescriptlang.org)\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-teal.svg?logo=law\u0026style=plastic)](https://opensource.org/licenses/MIT)\n\n[![Test](https://github.com/Frank-Mayer/panic/actions/workflows/test.yml/badge.svg)](https://github.com/Frank-Mayer/panic/actions/workflows/test.yml)\n\n[![Lint](https://github.com/Frank-Mayer/panic/actions/workflows/lint.yml/badge.svg)](https://github.com/Frank-Mayer/panic/actions/workflows/lint.yml)\n\n## What is this?\n\nThis is a blazingly fast reimplementation of the `Error` class in TypeScript. In most cases, you don't need the call stack of an `Error`. This implementation is a lot faster than the original `Error` class because the collection of the call stack is extremely expensive and `Panic` only collects the call stack when you need it.\n\nIt is not possible to get the call stack on demand (when you access the `stack` Property) because the used `Error.captureStackTrace` function captures the current call stack and there is no way to get the call stack of a previous function context. (If you know a way to do this, please let me know.)\n\n## Installation\n\n```bash\nnpm install @frank-mayer/panic\n```\n\n## How to use\n\nUse the `panic` function to throw an error.\n\n```TypeScript\nimport { panic } from '@frank-mayer/panic';\n\nif (someCondition) {\n    panic('Some condition was not met');\n}\n```\n\nUse the `throw` keyword to throw an instance of the `Panic` class.\n\n```TypeScript\nimport { Panic } from '@frank-mayer/panic';\n\nif (someCondition) {\n    throw new Panic('Some condition was not met');\n}\n```\n\n### What if I need the call stack?\n\nTo get the call stack set the `Panic.captureStackTrace` Property to `true`. From now on every `Panic` instance will collect the call stack. This should only be done in development mode.\n\n```TypeScript\nimport { Panic } from '@frank-mayer/panic';\n\nPanic.captureStackTrace = true;\n\nthrow new Panic('Some condition was not met');\n```\n\nTo get the call stack only for a single `Panic` instance, use the second parameter of the `panic` function.\n\n```TypeScript\nimport { panic } from '@frank-mayer/panic';\n\npanic('Some condition was not met', true);\n```\n\n## Performance tests\n\n### Constructor\n\n| Name        |    Ops/sec | Relative margin of error |\n| :---------- | ---------: | -----------------------: |\n| new Error() |    403,086 |                   ±5.93% |\n| new Panic() | 71,113,873 |                   ±1.92% |\n\nYou see, the `Panic` class is over **175 times faster** than the `Error` class!\n\n### throw\n\n| Name              |   Ops/sec | Relative margin of error |\n| :---------------- | --------: | -----------------------: |\n| throw new Error() |   309,103 |                   ±1.38% |\n| panic()           | 5,063,993 |                   ±0.86% |\n\n### throw with captureStackTrace enabled\n\n| Name              | Ops/sec | Relative margin of error |\n| :---------------- | ------: | -----------------------: |\n| throw new Error() | 232,223 |                   ±0.37% |\n| panic()           | 248,450 |                   ±0.72% |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsukinoko-kun%2Fpanic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftsukinoko-kun%2Fpanic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsukinoko-kun%2Fpanic/lists"}