{"library":"parse-imports-exports","title":"ECMAScript/TypeScript Import and Export Parser","description":"parse-imports-exports is a JavaScript/TypeScript library designed for fast and easy parsing of ECMAScript and TypeScript import and export declarations. It currently stands at version 0.2.4, indicating it is in active development and pre-1.0, so the API might evolve. The library focuses on extracting structured information about module dependencies from syntactically correct and well-formatted code, supporting both standard ES module syntax and TypeScript-specific constructs like `import type` and `export type`. It is optimized for efficiency and is not a full Abstract Syntax Tree (AST) parser, but rather targets specific module-related statements, including dynamic `import()` and `require()` calls.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install parse-imports-exports"],"cli":null},"imports":["import { parseImportsExports } from 'parse-imports-exports';","import type { ImportExportResult } from 'parse-imports-exports';","import { parseImportsExports, ImportExportResult } from 'parse-imports-exports';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { parseImportsExports } from 'parse-imports-exports';\n\nconst source = `\n/**\n * Imports.\n */\nimport {foo as baz, type Bar} from 'Qux';\nimport Foo, * as foo from 'Qux';\nconst dynamicQux = await import('Qux');\nconst commonJSQux = require('Qux');\nimport type {Foo as Baz, Bar} from 'Qux';\n\n/**\n * Reexports.\n */\nexport {foo as baz, type Bar} from 'Qux';\nexport * as foo from 'Qux';\nexport * from 'Qux';\n\n/**\n * Exports.\n */\nexport default 42;\nexport const myVar = 2;\nexport type T = number;\n`;\n\nconst importsExports = parseImportsExports(source);\n\nconsole.log(JSON.stringify(importsExports, null, 2));\n/*\nExample output (indices may vary):\n{\n  \"namedImports\": {\n    \"Qux\": [\n      {\n        \"start\": 42,\n        \"end\": 83,\n        \"names\": {\n          \"baz\": {\n            \"by\": \"foo\"\n          }\n        },\n        \"types\": {\n          \"Bar\": {}\n        }\n      }\n    ]\n  },\n  \"namespaceImports\": {\n    \"Qux\": [\n      {\n        \"start\": 85,\n        \"end\": 117,\n        \"namespace\": \"foo\",\n        \"default\": \"Foo\"\n      }\n    ]\n  },\n  \"dynamicImports\": {\n    \"Qux\": [\n      {\n        \"start\": 129,\n        \"end\": 165\n      }\n    ]\n  },\n  \"requires\": {\n    \"Qux\": [\n      {\n        \"start\": 177,\n        \"end\": 206\n      }\n    ]\n  },\n  \"typeNamedImports\": {\n    \"Qux\": [\n      {\n        \"start\": 218,\n        \"end\": 251,\n        \"names\": {\n          \"Baz\": {\n            \"by\": \"Foo\"\n          }\n        },\n        \"types\": {\n          \"Bar\": {}\n        }\n      }\n    ]\n  },\n  \"namedReexports\": {\n    \"Qux\": [\n      {\n        \"start\": 279,\n        \"end\": 320,\n        \"names\": {\n          \"baz\": {\n            \"by\": \"foo\"\n          }\n        },\n        \"types\": {\n          \"Bar\": {}\n        }\n      }\n    ]\n  },\n  \"namespaceReexports\": {\n    \"Qux\": [\n      {\n        \"start\": 322,\n        \"end\": 349,\n        \"namespace\": \"foo\"\n      }\n    ]\n  },\n  \"wildcardReexports\": {\n    \"Qux\": [\n      {\n        \"start\": 351,\n        \"end\": 371\n      }\n    ]\n  },\n  \"defaultExports\": [\n    {\n      \"start\": 399,\n      \"end\": 415\n    }\n  ],\n  \"namedExports\": [\n    {\n      \"start\": 427,\n      \"end\": 443,\n      \"names\": {\n        \"myVar\": {}\n      }\n    }\n  ],\n  \"typeExports\": [\n    {\n      \"start\": 455,\n      \"end\": 471,\n      \"names\": {\n        \"T\": {}\n      }\n    }\n  ]\n}\n*/","lang":"typescript","description":"Demonstrates how to use `parseImportsExports` to analyze a TypeScript/ECMAScript source string and extract a detailed breakdown of all import, export, and re-export declarations, including dynamic imports and CommonJS `require` statements.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}