{"id":49866235,"url":"https://github.com/lenml/editc","last_synced_at":"2026-05-15T03:01:40.868Z","repository":{"id":356880473,"uuid":"1232716533","full_name":"lenML/editc","owner":"lenML","description":"edit code by code path without `old_text`","archived":false,"fork":false,"pushed_at":"2026-05-10T07:34:35.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-05-10T09:36:36.138Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lenML.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,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-08T07:42:51.000Z","updated_at":"2026-05-10T07:34:39.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/lenML/editc","commit_stats":null,"previous_names":["lenml/editc"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/lenML/editc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lenML%2Feditc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lenML%2Feditc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lenML%2Feditc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lenML%2Feditc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lenML","download_url":"https://codeload.github.com/lenML/editc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lenML%2Feditc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33051875,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-15T02:00:06.351Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2026-05-15T03:01:09.508Z","updated_at":"2026-05-15T03:01:40.861Z","avatar_url":"https://github.com/lenML.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# editc\n\nEdit code by powerful **AST Selectors** without `old_text`.\n\n## Usage\n\n```bash\nnpm install\n\n# Option 1: Run directly with tsx (no build required)\nnpx tsx src/editc.ts index.ts --selector \"Class::MyService Method::hello\" --replace \"hello() { console.log('done'); }\"\n\n# Option 2: Build and run\nnpm run build\nnode dist/editc.js index.ts --selector \"Class::MyService Method::hello Block\" --replace \"return 42;\"\n```\n\n## Selector Syntax\n\nThe AST Selector syntax works similarly to CSS Selectors, matching elements down the TypeScript Abstract Syntax Tree.\n\n### Basic Format\n\nEach part of a selector is space-separated, representing a descendant relationship.\nFormat for a single part: `[Kind]::[Name][text^=\"Prefix\"]:comment`\n\n| Component       | Description                                                                                                                                                                                                            | Example                             |\n| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- |\n| `Kind`          | The AST `SyntaxKind`. We support **all** native kinds (e.g., `VariableDeclaration`, `Identifier`, `ReturnStatement`), and provide friendly aliases like `Class`, `Function`, `Method`, `ForBlock`, `IfBlock`, `Block`. | `Function` or `FunctionDeclaration` |\n| `::Name`        | Matches the explicit `.getName()` or the identifier text of the node.                                                                                                                                                  | `Class::MyService`                  |\n| `[text^=\"...\"]` | A property selector that matches if the node's full text starts with the specified prefix.                                                                                                                             | `ForBlock[text^=\"for (let i = 0\"]`  |\n| `:comment`      | A pseudo-class that targets the leading JSDoc or line comment attached to the node, instead of the node itself.                                                                                                        | `Method::hello:comment`             |\n\n### CLI Options\n\n- `--selector \u003cquery\u003e` : The AST selector path (required).\n- `--replace \u003ccode\u003e` : Replace the matched node with the given code.\n- `--replace-file \u003cfilepath\u003e` : Load replacement code from a file.\n- `--delete` : Delete the targeted node entirely.\n- `--before \u003ccode\u003e` : Insert text right before the targeted node.\n- `--after \u003ccode\u003e` : Insert text right after the targeted node.\n- `--all` : By default, editc edits the _first_ matching node. Pass `--all` to edit **all matching nodes** globally in the file scope.\n\n## Examples\n\nAssume the source file `index.ts`:\n\n```ts\nclass MyService {\n  hello() {\n    console.log(\"1\");\n  }\n}\n\nfunction fib(n: number) {\n  let fib = [0, 1];\n  for (let i = 2; i \u003c n; i++) {\n    fib[i] = fib[i - 1] + fib[i - 2];\n  }\n  return fib;\n}\n```\n\n### Replace an entire method\n\n```bash\nnpx tsx src/editc.ts index.ts --selector \"Class::MyService Method::hello\" --replace \"hello() { console.log('hi'); }\"\n```\n\n### Replace only the method body (auto-wraps in braces)\n\n```bash\nnpx tsx src/editc.ts index.ts --selector \"Class::MyService Method::hello Block\" --replace \"console.log('new body');\"\n```\n\n### Delete a specific block statement using text prefix\n\n```bash\nnpx tsx src/editc.ts index.ts --selector \"Function::fib Block VariableStatement[text^='let fib =']\" --delete\n```\n\n### Replace Comments\n\nUse `:comment` to edit JSDocs safely. You don't need to wrap your replacement in `/** */`, the tool does it for you.\n\n```bash\nnpx tsx src/editc.ts index.ts --selector \"Class::MyService Method::hello:comment\" --replace \"Says hello.\"\n```\n\n### Global Rename / Replace using `--all`\n\nFind all variables/identifiers named `fib` and rename them.\n\n```bash\nnpx tsx src/editc.ts index.ts --selector \"Function::fib Block Identifier::fib\" --replace \"fib_arr\" --all\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flenml%2Feditc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flenml%2Feditc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flenml%2Feditc/lists"}