{"id":15663325,"url":"https://github.com/rajasegar/jscodeshift-collections","last_synced_at":"2025-05-05T22:49:33.349Z","repository":{"id":37048832,"uuid":"247230071","full_name":"rajasegar/jscodeshift-collections","owner":"rajasegar","description":"Collections for some AST nodes in jscodeshift","archived":false,"fork":false,"pushed_at":"2024-05-09T10:19:47.000Z","size":1110,"stargazers_count":17,"open_issues_count":6,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-28T22:42:09.732Z","etag":null,"topics":["ast","codemod","codemods","collection","collections","hacktoberfest","hacktoberfest-accepted","jscodeshift"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rajasegar.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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}},"created_at":"2020-03-14T07:15:11.000Z","updated_at":"2023-10-10T16:07:50.000Z","dependencies_parsed_at":"2023-02-14T05:10:16.722Z","dependency_job_id":"18598e43-b4a4-4ff5-980f-103892b05267","html_url":"https://github.com/rajasegar/jscodeshift-collections","commit_stats":{"total_commits":165,"total_committers":4,"mean_commits":41.25,"dds":0.5151515151515151,"last_synced_commit":"eed316edd22486ef8569d21e571f268cb4064f96"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajasegar%2Fjscodeshift-collections","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajasegar%2Fjscodeshift-collections/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajasegar%2Fjscodeshift-collections/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajasegar%2Fjscodeshift-collections/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rajasegar","download_url":"https://codeload.github.com/rajasegar/jscodeshift-collections/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252590526,"owners_count":21772935,"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":["ast","codemod","codemods","collection","collections","hacktoberfest","hacktoberfest-accepted","jscodeshift"],"created_at":"2024-10-03T13:36:38.753Z","updated_at":"2025-05-05T22:49:33.328Z","avatar_url":"https://github.com/rajasegar.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jscodeshift-collections\n\n![Build and Deploy](https://github.com/rajasegar/jscodeshift-collections/workflows/CI/badge.svg)\n[![npm version](http://img.shields.io/npm/v/jscodeshift-collections.svg?style=flat)](https://npmjs.org/package/jscodeshift-collections \"View this project on npm\")\n[![Coverage Status](https://coveralls.io/repos/github/rajasegar/jscodeshift-collections/badge.svg?branch=master)](https://coveralls.io/github/rajasegar/jscodeshift-collections?branch=master)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)\n\n\nSome more Collections for jscodeshift for easy and terse api for writing Codemods\n\n## Install\n```\nnpm install jscodeshift-collections\n```\n\n## List of collections\n- [Functiondeclaration](#functiondeclaration)\n- [CallExpression](#callexpression)\n- [Importdeclaration](#importdeclaration)\n- [ClassDeclaration](#classdeclaration)\n\n## Usage\n```js\nconst jscsCollections = require('jscodeshift-collections');\n\nmodule.exports = function(fileInfo, api) {\n  const j =  api.jscodeshift;\n\n  jscsCollections.registerCollections(j);\n\n  return j(fileInfo.source)\n    .findFunctionDeclarations('foo')\n    .renameTo('bar')\n    .toSource();\n}\n```\n\n## Example\n\nSay for example, if you want to rename a function declaration `foo` to `bar` \n\n### Transform with new Collection API\n```js\nj.findFunctionDeclarations('foo')\n .renameTo('bar')\n```\n\n### Before\n\n```js\nfunction foo() {\n}\n```\n\n\n### After\n\n```js\nfunction bar() {\n}\n```\n\n## List of Collections:\n\n### FunctionDeclaration\n\n```js\n// Find all function declarations\nj.findFunctionDeclarations()\n\n// Find all function declarations with name=foo and rename them to bar\nj.findFunctionDeclarations('foo')\n    .renameTo('xyz');\n\n// Find and remove params\n  j.findFunctionDeclarations('bar')\n    .removeParam('a');\n\n// Find and add params\n  j.findFunctionDeclarations('bar')\n    .addParam('d');\n```\n\n### CallExpression\n\n```js\n// Find all call expressions\n  j.findCallExpressions();\n\n// Find all member expressions\n  j.findCallExpressions('foo.bar');\n\n\n// Find all nested member expressions\n  j.findCallExpressions('foo.bar.baz');\n\n// Find and rename call expressions\n  j.findCallExpressions('foo')\n  .renameTo('xyz');\n\n// Find and rename member expressions\n  j.findCallExpressions('foo')\n  .renameTo('foo.bar');\n\n//  Find and remove params\n  j.findCallExpressions('bar')\n  .removeParam('a');\n\n// Find and add params\n  j.findCallExpressions('bar')\n  .addParam('d');\n```\n\n### ImportDeclaration\n\n```js\n// Find all import declarations\n  j.findImportDeclarations();\n\n// Find and rename\n  j.findImportDeclarations('a')\n  .renameTo('xyz');\n\n// Find and remove specifiers\n  j.findImportDeclarations('a')\n  .removeSpecifier('a');\n\n// Find and add specifiers\n  j.findImportDeclarations('a')\n  .addSpecifier('c');\n```\n\n### ClassDeclaration\n```js\n// Find all class declarations\nj.findClassdeclarations();\n\n// Find and rename\nj.findClassDeclarations('foo').renameTo('bar')\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frajasegar%2Fjscodeshift-collections","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frajasegar%2Fjscodeshift-collections","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frajasegar%2Fjscodeshift-collections/lists"}