{"id":17216419,"url":"https://github.com/ganeshkbhat/get-imports","last_synced_at":"2026-02-13T08:19:57.590Z","repository":{"id":62249329,"uuid":"559110777","full_name":"ganeshkbhat/get-imports","owner":"ganeshkbhat","description":"The module has JS functions to check all imports or required modules and check if the file is a ES Module or a CJS/ JS Module or Script","archived":false,"fork":false,"pushed_at":"2024-01-22T11:40:40.000Z","size":471,"stargazers_count":4,"open_issues_count":2,"forks_count":30,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T12:52:36.812Z","etag":null,"topics":["cjs","es","esm","iscjscode","isescode","isesmcode","js","mjs"],"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/ganeshkbhat.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}},"created_at":"2022-10-29T04:55:59.000Z","updated_at":"2024-03-30T01:27:30.000Z","dependencies_parsed_at":"2024-06-21T02:16:38.398Z","dependency_job_id":"c038d97e-52a5-4aaa-a084-0d77ae66d3ef","html_url":"https://github.com/ganeshkbhat/get-imports","commit_stats":{"total_commits":46,"total_committers":2,"mean_commits":23.0,"dds":"0.021739130434782594","last_synced_commit":"398353a9a1f7676c18ac39c9764757ba8041a759"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ganeshkbhat%2Fget-imports","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ganeshkbhat%2Fget-imports/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ganeshkbhat%2Fget-imports/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ganeshkbhat%2Fget-imports/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ganeshkbhat","download_url":"https://codeload.github.com/ganeshkbhat/get-imports/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248792634,"owners_count":21162398,"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":["cjs","es","esm","iscjscode","isescode","isesmcode","js","mjs"],"created_at":"2024-10-15T03:27:41.812Z","updated_at":"2026-02-13T08:19:52.543Z","avatar_url":"https://github.com/ganeshkbhat.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# get-imported\nModule to fetch all required and imported modules in Javascript and NodeJS. The module has JS functions to check all imports or required modules and check if the file is a ES Module or a CJS/ JS Module or Script\n\n\nFind the demos in the [demos folder](./demos)\n\n\n# Usage\n\n`CommonJS example`\n\nFile example: `demos/parser.imports.regex.js`\n\n```\n\nconst parser = require(\"get-imported\");\nlet example_one = parser._importRegex(\"./demos/src/parser.imports.regex.js\");\nlet example_two = parser._requiresObject();\nlet example_three = parser._requireRegex(\"./demos/src/parser.require.regex.js\");\nlet example_four = parser._importRegexExtended(\"./demos/src/parser.imports.regex.extended.js\");\n\n\n```\n\n\nFile example: `demos/parser.imports.regex.mjs`\n\n```\n\n\nimport * as parser from \"get-imported\";\nconst path = import('path');\nconst someModuleCJS = import('./parser.demo.require.cache.test.file.cjs');\nconst someModuleJS = import('./parser.demo.require.cache.test.file.js');\nconst acorn = import(\"chai\");\n\nlet arr = parser._importESRegex(\"./demos/src/parser.imports.regex.mjs\");\nconsole.log(arr);\n\n\n```\n\n\n---\n\n\n### INSTALL\n\n```npm install get-imported --save```\n\n\n---\n\n\n### USAGE\n\n\nESM Module\n\n`import { _isESCode } from \"get-imported\";`\n\n\nCommonJS Script/ Module\n\n```\nconst checkEsm = require(\"get-imported\");\nisESCode(\"./path/to/file.mjs\")\n```\n\n\n---\n\n\n### Package APIs\n\n\nThere are other script APIs you may wish to explore that includes the following:\n\n#### `.checkModuleImports` \nCheck if a module can be imported using `import()`\n\nUsage:\n\n`.checkModuleImports(absPath)`\n\n\n\n#### `.requiresObject`\nCheck require.cache list in code - used in your code's process global context.\n\nUsage:\n\n`.requiresObject()`\n\n\n\n#### `.requireRegex`\nCheck to see if there are `require()` syntax in code.\n\nUsage:\n\n`.requireRegex(absPath, basePath = \"\", useProcessCwd = false)`\n\n`.requireRegex(absPath)`\n\n\n\n#### `.importRegex`\nCheck to see if there are `import()` syntax in code.\n\nUsage:\n\n`.importRegex(absPath, basePath = \"\", useProcessCwd = false)`\n\n`.importRegex(absPath)`\n\n\n\n#### `.importESRegex`\nCheck to see if there are `import x from \"\"` syntax in code.\n\nUsage:\n\n`.importESRegex(absPath, basePath = \"\", useProcessCwd = false)`\n\n`.importESRegex(absPath)`\n\n\n\n#### `.importRegexExtended`\nCheck to see if there are `import()` syntax in code.\n\nUsage:\n\n`.importRegexExtended(absPath, basePath = \"\", useProcessCwd = false)`\n\n`.importRegexExtended(absPath)`\n\n\n\n#### `.isESMFileExtension`\nCheck to see if the file has `.mjs`/ `.cjs`/ `.js` extension.\n\nUsage:\n\n`.isESMFileExtension(absPath)`\n\n\n\n#### `.isNodeCompatibleFileExtension`\nCheck to see if the file has `.mjs`/ `.cjs`/ `.js` / `.node` / `.wasm` extension.\n\nUsage:\n\n`.isNodeCompatibleFileExtension(absPath)`\n\n\n\n#### `.isESMCodeBase`\nCheck to see if the code is ESM Module.\n\nUsage:\n\n`.isESMCodeBase(absPath)`\n\n\n\n#### `isCJSCodeBase`\nCheck to see if the code is CommonJS Script or Module.\n\nUsage:\n\n`isCJSCodeBase(absPath)`\n\n\n\n#### `isModuleInPackageJson`\nChecks type key's value in package.json.\n\nUsage:\n\n`getPackageJsonRoot(startdirectory, options)`\n\n\n\n#### `isESCode`\nMultiple checks to check if the code is ESM Module (other than package.json type key's value check in package.json).\n\nUsage:\n\n`isModuleInPackageJson(absPath, packagejsonPath, returns)`\n\n\n---\n\n\n\n### Contributions\n\nContributions, Feature Improvements, Bugs, and Issues are invited. [raising an issue](https://github.com/ganeshkbhat/get-imports/issues)\n\n\n# License\n\n[MIT License](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fganeshkbhat%2Fget-imports","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fganeshkbhat%2Fget-imports","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fganeshkbhat%2Fget-imports/lists"}