{"id":19418964,"url":"https://github.com/playform/eliminate","last_synced_at":"2025-04-14T14:11:09.842Z","repository":{"id":258873836,"uuid":"874468646","full_name":"PlayForm/Eliminate","owner":"PlayForm","description":"Eliminate ↘️","archived":false,"fork":false,"pushed_at":"2025-04-13T02:08:33.000Z","size":24431,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"Current","last_synced_at":"2025-04-13T03:21:54.575Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://playform.github.io/Eliminate/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PlayForm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"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,"zenodo":null},"funding":{"custom":"https://Stripe.PlayForm.LTD/b/3csdQZfzn2LDaBOcMN","open_collective":"playform-cloud-collective"}},"created_at":"2024-10-17T22:07:26.000Z","updated_at":"2025-04-13T02:08:36.000Z","dependencies_parsed_at":"2024-12-08T17:18:16.446Z","dependency_job_id":"f9f31d3f-7a58-4bb5-8d31-5debc21517c1","html_url":"https://github.com/PlayForm/Eliminate","commit_stats":null,"previous_names":["playform/eliminate"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PlayForm%2FEliminate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PlayForm%2FEliminate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PlayForm%2FEliminate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PlayForm%2FEliminate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PlayForm","download_url":"https://codeload.github.com/PlayForm/Eliminate/tar.gz/refs/heads/Current","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248894938,"owners_count":21179152,"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":[],"created_at":"2024-11-10T13:15:44.285Z","updated_at":"2025-04-14T14:11:09.836Z","avatar_url":"https://github.com/PlayForm.png","language":"TypeScript","readme":"# [Eliminate] ↘️\n\n`Eliminate` is a powerful `TypeScript` utility designed to streamline your\ncodebase by identifying and removing variable and function declarations that are\nused only once and not exported. It replaces their usage with their initializers\nor inlines function bodies, improving code readability and potentially enhancing\nperformance. This tool is ideal for developers looking to eliminate redundancy\nwhile preserving the integrity of exported APIs and respecting custom\nconfigurations.\n\n### Example\n\nHere’s a simple illustration of how Eliminate transforms your code:\n\n\u003ctable\u003e\n\t\u003ctr\u003e\n\t\t\u003cth\u003eBefore\u003c/th\u003e\n    \t\u003cth\u003eAfter\u003c/th\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n    \t\u003ctd\u003e\n    \t\t\u003cpre lang=\"typescript\"\u003e\nlet a = 5;\n\nlet b = 10;\n\nlet c = a + b;\n\nconsole.log(c);\n\n\u003c/pre\u003e\n\t\t\u003c/td\u003e\n\t\t\u003ctd\u003e\n\t\t\t\u003cpre lang=\"typescript\"\u003e\nconsole.log(5 + 10);\n\n\u003c/pre\u003e\n\t\t\u003c/td\u003e\n\t\u003c/tr\u003e\n\u003c/table\u003e\n\n## Feature 📦\n\n- **`TypeScript` Integration with Type-Checking:**\n    - Utilizes `TypeScript`’s compiler API and type checker for safe, reliable\n      transformations.\n- **Usage Analysis:**\n    - Counts references to variables and functions to determine eligibility for\n      removal.\n- **Export Preservation:**\n    - Detects and retains exported symbols to maintain your module’s public\n      interface.\n- **Code Optimization:**\n\n    - Eliminates variable and function declarations used only once and not\n      exported.\n    - Substitutes their references with initializers or inlined function bodies\n      where applicable.\n\n- **Advanced Scenario Support:**\n\n    - Handles complex cases like destructuring, default parameters, nested\n      scopes, type annotations, and mutual recursion.\n    - Prevents infinite inlining loops in recursive scenarios.\n\n- **Customizable Configuration:**\n\n    - `Comment`: Preserve symbols with comments (**default:** `true`).\n    - `Max`: Maximum expression size (in AST nodes) for inlining (**default:**\n      `100`).\n    - `Async`: Preserve async/await constructs (**default:** `false`).\n    - `Const`: Preserve const variables (**default:** `false`).\n    - `Function`: Preserve all function declarations (**default:** `false`).\n    - `Debug`: Enable verbose logging for debugging (**default:** `false`).\n\n- **Recursion Handling:**\n    - Safely manages direct and mutual recursion with configurable depth limits\n      to avoid stack overflows.\n\n## Installation 🚀\n\nAdd `Eliminate` to your project as a development dependency:\n\n```sh\nnpm install -D -E @playform/eliminate\n```\n\n## Usage 🛠️\n\n### Command Line\n\nExecute `Eliminate` via the command line with a configuration file:\n\n```sh\nnpx @playform/eliminate Configuration.ts\n```\n\nCheck out an example configuration file:\n[`Configuration.ts`](./Configuration.ts)\n\n### CLI Options\n\n```\nUsage: Eliminate Eliminate\n\nArguments:\n  Eliminate                 Eliminate configuration file 📜\n\nOptions:\n  -V, --version             Output the version number\n  -h, --help                Display help information\n```\n\n### NPM Scripts\n\nAdd `Eliminate` to your `package.json` scripts:\n\n```json\n{\n\t\"scripts\": {\n\t\t\"Eliminate\": \"Eliminate Configuration.ts\"\n\t}\n}\n```\n\n### How It Works\n\n`Eliminate` leverages the `TypeScript` compiler `API` to analyze and transform\nyour code through these steps:\n\n1.  **Analysis Phase:**\n\n    - Builds an Abstract Syntax Tree (`AST`) of your code.\n    - Identifies variable and function declarations.\n    - Tracks reference counts and export status.\n    - Detects recursion via call graph analysis.\n\n2.  **Transformation Phase:**\n\n    - Iteratively removes eligible declarations (used once, not exported) and\n      inlines their values or bodies.\n    - Manages edge cases like destructuring, nested scopes, and recursive\n      functions.\n    - Respects size limits and configuration settings to ensure safe\n      transformations.\n\n3.  **Output Phase:**\n\n    - Produces optimized code with redundant declarations eliminated and their\n      usage simplified.\n\n### Configuration\n\nCustomize `Eliminate’s` behavior with these options:\n\n- `Comment`: If `true`, keeps declarations with comments intact (**default:**\n  `true`).\n- `Max`: Limits the size of inlined expressions (**default:** `100` `AST`\n  nodes).\n\n- `Async`: If `true`, retains async functions and await expressions\n  (**default:** `false`).\n- `Const`: If `true`, preserves const variables (**default:** `false`).\n\n- `Function`: If `true`, retains all function declarations (**default:**\n  `false`).\n\n- `Debug`: If `true`, outputs detailed logs for debugging (**default:**\n  `false`).\n\nThese settings allow you to fine-tune the tool to suit your project’s needs,\nbalancing optimization with code preservation.\n\n## Contributing 🤝\n\nContributions are welcome! Please see [`CONTRIBUTING.md`](CONTRIBUTING.md) for\nguidelines and feel free to submit a Pull Request.\n\n## Changelog\n\nSee [`CHANGELOG.md`](CHANGELOG.md) for a history of changes to this component.\n\n[Eliminate]: HTTPS://NPMJS.Org/@playform/eliminate\n","funding_links":["https://Stripe.PlayForm.LTD/b/3csdQZfzn2LDaBOcMN","https://opencollective.com/playform-cloud-collective"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplayform%2Feliminate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplayform%2Feliminate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplayform%2Feliminate/lists"}