{"id":19176979,"url":"https://github.com/joomcode/parse-imports-exports","last_synced_at":"2025-10-12T00:42:06.933Z","repository":{"id":197422396,"uuid":"697074174","full_name":"joomcode/parse-imports-exports","owner":"joomcode","description":"Fast and easy parser for declarations of import and export in ECMAScript/TypeScript","archived":false,"fork":false,"pushed_at":"2025-02-16T04:24:25.000Z","size":219,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-23T23:42:59.453Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joomcode.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":"2023-09-27T02:11:16.000Z","updated_at":"2025-02-16T04:24:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"50ddd223-2046-45f4-9be1-15a01738fa2a","html_url":"https://github.com/joomcode/parse-imports-exports","commit_stats":null,"previous_names":["joomcode/parse-imports-exports"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joomcode%2Fparse-imports-exports","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joomcode%2Fparse-imports-exports/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joomcode%2Fparse-imports-exports/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joomcode%2Fparse-imports-exports/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joomcode","download_url":"https://codeload.github.com/joomcode/parse-imports-exports/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247909134,"owners_count":21016475,"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-09T10:31:27.602Z","updated_at":"2025-10-12T00:42:01.895Z","avatar_url":"https://github.com/joomcode.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# parse-imports-exports\n\n[![NPM version][npm-image]][npm-url]\n[![minzipped size][size-image]][size-url]\n[![code style: prettier][prettier-image]][prettier-url]\n[![Conventional Commits][conventional-commits-image]][conventional-commits-url]\n[![License MIT][license-image]][license-url]\n\nFast and easy parser for declarations of [import](https://tc39.es/ecma262/#prod-ImportDeclaration)\nand [export](https://tc39.es/ecma262/#prod-ExportDeclaration) from the ECMAScript standard,\nwith [TypeScript](https://www.typescriptlang.org/docs/handbook/2/modules.html) syntax support.\n\n`parse-imports-exports` works for syntactically correct, well-formatted code (for example, by [prettier][prettier-url]).\nSingle-line and multi-line ECMAScript comments in `import`/`export` statements are supported.\n\n## Basic example\n\nImagine a module with the following content:\n\n```ts\n/**\n * Imports.\n */\n// {Qux: [{start: 17, end: 58, names: {baz: {by: 'foo'}}, types: {Bar: {}}}]}\nimport {foo as baz, type Bar} from 'Qux';\n\n// {Qux: [{start: 80, end: 112, namespace: 'foo', default: 'Foo'}]}\nimport Foo, * as foo from 'Qux';\n\n// {Qux: [{start: 114, end: 127}]}\nconst foo = await import('Qux');\n\n// {Qux: [{start: 128, end, 134}]}\nconst foo = require('Qux');\n\n// {Qux: [{start: 142, end: 175, names: {Baz: {by: 'Foo'}, Bar: {}}}]}\nimport type {Foo as Baz, Bar} from 'Qux';\n\n// {Qux: [{start: 201, end: 233, namespace: 'Foo'}]}\nimport type * as Foo from 'Qux';\n\n// {Qux: [{start: 137, end: 141}]}\ntype Foo = typeof import('Qux');\n\n/**\n * Reexports.\n */\n// {Qux: [{start: 254, end: 295, names: {baz: {by: 'foo'}}, types: {Bar: {}}}]}\nexport {foo as baz, type Bar} from 'Qux';\n\n// {Qux: [{start: 319, end: 346, namespace: 'foo'}]}\nexport * as foo from 'Qux';\n\n// {Qux: [{start: 365, end: 385}]}\nexport * from 'Qux';\n\n// {Qux: [{start: 409, end: 450, names: {Baz: {by: 'Foo'}, Bar: {}}}]}\nexport type {Foo as Baz, Bar} from 'Qux';\n\n// {Qux: [{start: 478, end: 510, namespace: 'Foo'}]}\nexport type * as Foo from 'Qux';\n\n// {Qux: [{start: 533, end: 558}]}\nexport type * from 'Qux';\n\n/**\n * Exports.\n */\n// {start: 578, end: 596}\nexport default 42;\n\n// [{start: 614, end: 644, names: {baz: {by: 'foo'}}, types: {Bar: {}}}]\nexport {foo as baz, type Bar};\n\n// {foo: {start: 668, end: 689, kind: 'const'}}\nexport const foo = 2;\n\n// [{start: 711, end: 741, names: {Baz: {by: 'Foo'}, Bar: {}}}]\nexport type {Foo as Baz, Bar};\n\n// {T: {start: 758, end: 781}}\nexport type T = number;\n\n// {I: [{start: 803, end: 836}]}\nexport interface I {\n  foo: number;\n}\n\n// {N: [{start: 858, end: 891}]}\nexport namespace N {\n  foo: number;\n}\n\n// {start: 901, end: 915}\nmodule.exports = 42;\n\n// {foo: {start: 917, end: 931, startsWithModule: true}}\nmodule.exports.foo = 2;\n```\n\nLet its content be stored as a string in the variable `source`.\nThen it can be parsed like this:\n\n```ts\nimport {parseImportsExports} from 'parse-imports-exports';\n\nconst importsExports = parseImportsExports(source);\n\n// Now `importsExports` has the following shape (the `start` and `end` indices, which indicate\n// the beginning and end of the corresponding statement in the source, may differ):\nconst importsExportsShape = {\n  /**\n   * Imports.\n   */\n  // import {foo as baz, type Bar} from 'Qux';\n  namedImports: {Qux: [{start: 17, end: 58, names: {baz: {by: 'foo'}}, types: {Bar: {}}}]},\n\n  // import Foo, * as foo from 'Qux';\n  namespaceImports: {Qux: [{start: 80, end: 112, namespace: 'foo', default: 'Foo'}]},\n\n  // const foo = await import('Qux');\n  dynamicImports: {Qux: [{start: 114, end: 127}]},\n\n  // const foo = require('Qux');\n  requires: {Qux: [{start: 128, end: 134}]},\n\n  // import type {Foo as Baz, Bar} from 'Qux';\n  typeNamedImports: {Qux: [{start: 142, end: 175, names: {Baz: {by: 'Foo'}, Bar: {}}}]},\n\n  // import type * as Foo from 'Qux';\n  typeNamespaceImports: {Qux: [{start: 201, end: 233, namespace: 'Foo'}]},\n\n  // type Foo = typeof import('Qux');\n  typeDynamicImports: {Qux: [{start: 137, end: 141}]},\n\n  /**\n   * Reexports.\n   */\n  // export {foo as baz, type Bar} from 'Qux';\n  namedReexports: {Qux: [{start: 254, end: 295, names: {baz: {by: 'foo'}}, types: {Bar: {}}}]},\n\n  // export * as foo from 'Qux';\n  namespaceReexports: {Qux: [{start: 319, end: 346, namespace: 'foo'}]},\n\n  // export * from 'Qux';\n  starReexports: {Qux: [{start: 365, end: 385}]},\n\n  // export type {Foo as Baz, Bar} from 'Qux';\n  typeNamedReexports: {Qux: [{start: 409, end: 450, names: {Baz: {by: 'Foo'}, Bar: {}}}]},\n\n  // export type * as Foo from 'Qux';\n  typeNamespaceReexports: {Qux: [{start: 478, end: 510, namespace: 'Foo'}]},\n\n  // export type * from 'Qux';\n  typeStarReexports: {Qux: [{start: 533, end: 558}]},\n\n  /**\n   * Exports.\n   */\n  // export default 42;\n  defaultExport: {start: 578, end: 596},\n\n  // export {foo as baz, type Bar};\n  namedExports: [{start: 614, end: 644, names: {baz: {by: 'foo'}}, types: {Bar: {}}}],\n\n  // export const foo = 2;\n  declarationExports: {foo: {start: 668, end: 689, kind: 'const'}},\n\n  // export type {Foo as Baz, Bar};\n  typeNamedExports: [{start: 711, end: 741, names: {Baz: {by: 'Foo'}, Bar: {}}}],\n\n  // export type T = number;\n  typeExports: {T: {start: 758, end: 781}},\n\n  // export interface I {foo: number};\n  interfaceExports: {I: [{start: 803, end: 836}]},\n\n  // export namespace N {foo: number};\n  namespaceExports: {N: [{start: 858, end: 891}]},\n\n  // module.exports = 42;\n  commonJsNamespaceExport: {start, end},\n\n  // module.exports.foo = 2;\n  commonJsExports: {foo: {start, end, startsWithModule: true}},\n};\n```\n\n## Install\n\nRequires [node](https://nodejs.org/en/) version 10 or higher:\n\n```sh\nnpm install parse-imports-exports\n```\n\n`parse-imports-exports` works in any environment that supports ES2018\n(because package uses [RegExp Named Capture Groups](https://github.com/tc39/proposal-regexp-named-groups)).\n\n## API\n\n`parse-imports-exports` exports one runtime value — the `parseImportsExports` function:\n\n```ts\nimport {parseImportsExports} from 'parse-imports-exports';\n\nimport type {ImportsExports, Options} from 'parse-imports-exports';\n\nconst importsExports: ImportsExports = parseImportsExports('some source code (as string)');\n// or with optional options:\nconst importsExports = parseImportsExports('some source code (as string)', options);\n\n// all option fields are optional boolean with default `false` value\nconst options: Options = {\n  /**\n   * If `true`, then we ignore `module.exports = ...`/`(module.)exports.foo = ...` expressions\n   * during parsing (maybe a little faster).\n   * By default (if `false` or skipped option), `module.exports = ...`/`(module.)exports.foo = ...`\n   * expressions are parsed.\n   */\n  ignoreCommonJsExports: false;\n  /**\n   * If `true`, then we ignore `import(...)` expressions during parsing (maybe a little faster).\n   * By default (if `false` or skipped option), `import(...)` expressions are parsed.\n   */\n  ignoreDynamicImports: false;\n  /**\n   * If `true`, then we ignore regular expression literals (`/.../`)\n   * during parsing (maybe a little faster).\n   * By default (if `false` or skipped option), regular expression literals are parsed.\n   */\n  ignoreRegexpLiterals: false;\n  /**\n   * If `true`, then we ignore `require(...)` expressions during parsing (maybe a little faster).\n   * By default (if `false` or skipped option), `require(...)` expressions are parsed.\n   */\n  ignoreRequires: false;\n  /**\n   * If `true`, then we ignore string literals during parsing (maybe a little faster).\n   * By default (if `false` or skipped option), string literals are parsed, that is,\n   * the text inside them cannot be interpreted as another expression.\n   */\n  ignoreStringLiterals: false;\n};\n```\n\n`parse-imports-exports` also exports types included in the API:\n\n```ts\nexport type {\n  /**\n   * Parsed JSON presentation of imports, exports and reexports of ECMAScript/TypeScript module.\n   */\n  ImportsExports,\n  /**\n   * Kind of exported declaration.\n   */\n  Kind,\n  /**\n   * Options of `parseImportsExports` function.\n   */\n  Options,\n};\n```\n\n## License\n\n[MIT][license-url]\n\n[conventional-commits-image]: https://img.shields.io/badge/Conventional_Commits-1.0.0-yellow.svg 'The Conventional Commits specification'\n[conventional-commits-url]: https://www.conventionalcommits.org/en/v1.0.0/\n[license-image]: https://img.shields.io/badge/license-MIT-blue.svg 'The MIT License'\n[license-url]: LICENSE\n[npm-image]: https://img.shields.io/npm/v/parse-imports-exports.svg 'parse-imports-exports'\n[npm-url]: https://www.npmjs.com/package/parse-imports-exports\n[prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg 'Prettier code formatter'\n[prettier-url]: https://prettier.io/\n[size-image]: https://img.shields.io/bundlephobia/minzip/parse-imports-exports 'parse-imports-exports'\n[size-url]: https://bundlephobia.com/package/parse-imports-exports\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoomcode%2Fparse-imports-exports","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoomcode%2Fparse-imports-exports","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoomcode%2Fparse-imports-exports/lists"}