{"id":21186046,"url":"https://github.com/codemodsquad/jscodeshift-find-imports","last_synced_at":"2025-07-10T01:30:58.730Z","repository":{"id":40747695,"uuid":"187269245","full_name":"codemodsquad/jscodeshift-find-imports","owner":"codemodsquad","description":"find imported/required identifiers with jscodeshift","archived":false,"fork":false,"pushed_at":"2023-01-06T01:51:04.000Z","size":1117,"stargazers_count":12,"open_issues_count":21,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-14T09:40:41.377Z","etag":null,"topics":["imports","jscodeshift"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/codemodsquad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-17T19:16:03.000Z","updated_at":"2023-04-11T15:26:05.000Z","dependencies_parsed_at":"2023-02-05T02:00:55.051Z","dependency_job_id":null,"html_url":"https://github.com/codemodsquad/jscodeshift-find-imports","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemodsquad%2Fjscodeshift-find-imports","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemodsquad%2Fjscodeshift-find-imports/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemodsquad%2Fjscodeshift-find-imports/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemodsquad%2Fjscodeshift-find-imports/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codemodsquad","download_url":"https://codeload.github.com/codemodsquad/jscodeshift-find-imports/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225607508,"owners_count":17495743,"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":["imports","jscodeshift"],"created_at":"2024-11-20T18:21:07.644Z","updated_at":"2024-11-20T18:21:08.270Z","avatar_url":"https://github.com/codemodsquad.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jscodeshift-find-imports\n\n[![CircleCI](https://circleci.com/gh/codemodsquad/jscodeshift-find-imports.svg?style=svg)](https://circleci.com/gh/codemodsquad/jscodeshift-find-imports)\n[![Coverage Status](https://codecov.io/gh/codemodsquad/jscodeshift-find-imports/branch/master/graph/badge.svg)](https://codecov.io/gh/codemodsquad/jscodeshift-find-imports)\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[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![npm version](https://badge.fury.io/js/jscodeshift-find-imports.svg)](https://badge.fury.io/js/jscodeshift-find-imports)\n\nfind imported/required identifiers with jscodeshift\n\n# Usage\n\n```\nnpm i jscodeshift-find-imports\n```\n\n```js\nconst findImports = require('jscodeshift-find-imports')\nconst j = require('jscodeshift')\nconst { statement } = j.template\n\nconst code = `\nimport bar from 'foo'\n`\n\nconst imports = findImports(j(code), statement`import foo from 'foo'`)\n\nconsole.log(imports) // {foo: {type: 'Identifier', name: 'bar'}}\n```\n\n# Compatibility\n\nCurrently tested and working with `jscodeshift@0.11.0` and the following parsers:\n\n* `'babel'`\n* `'babylon'`\n* `'ts'`\n* `'flow'`\n\nIt won't likely work with other custom parsers unless they output nodes in the same format as\nBabel for import declarations, variable declarations, require calls, and object patterns.\n\n# `findImports(root, statements)`\n\n## Arguments\n\n### `root`\n\nThe jscodeshift-wrapped AST of source code\n\n### `statements`\n\nThe AST of an `ImportDeclaration` or `VariableDeclaration` containing `require`\ncalls to search for (e.g. `const foo = require('foo')`), or an array of them.\n\n## Returns\n\nAn object where each key is an identifier from your search statement(s) that was found, and the\ncorresponding value is the AST for the local binding for that import (either an `Identifier` or\n`MemberExpression` node). For example, if you search for `const {bar} = require('bar')` but the\nsource code has `const foo = require('bar').bar`, the result will have `bar: { type: 'Identifier', name: 'bar' }`.\n\nThe local binding will be a `MemberExpression` in cases like this:\n\n```js\nconst code = `\nimport React from 'react'\n`\nconst imports = findImports(\n  j(code),\n  statement`import { Component } from 'react'`\n)\n```\n\nIn this case `imports` would be\n\n```js\n{\n  Component: {\n    type: 'MemberExpression',\n    object: {\n      type: 'Identifier',\n      name: 'React',\n    },\n    property: {\n      type: 'Identifier',\n      name: 'Component',\n    },\n  },\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemodsquad%2Fjscodeshift-find-imports","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodemodsquad%2Fjscodeshift-find-imports","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemodsquad%2Fjscodeshift-find-imports/lists"}