{"name":"parse-imports-exports","version":"0.2.1","keywords":["esm","export","import","parse","parser","typescript"],"author":{"name":"uid11"},"license":"MIT","_id":"parse-imports-exports@0.2.1","maintainers":[{"name":"uid-11222","email":"UID.11222@gmail.com"}],"homepage":"https://github.com/joomcode/parse-imports-exports#readme","bugs":{"url":"https://github.com/joomcode/parse-imports-exports/issues"},"dist":{"shasum":"04c8c0de7731a0b1d656cba16e88b4b5fe819bf0","tarball":"http://registry-npm.ywwl.com/parse-imports-exports/download/parse-imports-exports-0.2.1.tgz","fileCount":31,"integrity":"sha512-HCwGW6X6WzOEhbaYPMUg6Cz9aDqouNpWUlDLn0tq7RLhSvvWF1KvU6vGeUr/aNR+ePGimkbwbhifF/2IjpRdBg==","signatures":[{"sig":"MEUCIH4wnjlVyb5HHTueZ/sJER1IhN2yOaJPHujWdwFoVejfAiEAoFS/S8kah1rA6tdLIEyjQX67TVYNcPbjdnTtA47QgFw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":127391,"size":22798,"noattachment":false,"key":"/parse-imports-exports/-/parse-imports-exports-0.2.1.tgz"},"type":"module","types":"./index.d.ts","exports":{".":{"types":"./index.d.ts","import":"./index.js","require":"./index.cjs"}},"gitHead":"e430e1a6ee5433fd47ae5f19609c4fe50d2ddc21","scripts":{"test":"export _START=$(date +%s%3N) && npm run prettier && npm run build && node ./build/spec/index.spec.js","build":"tsc","release":"npm publish ./build/src","prebuild":"rm -fr ./build/*","prettier":"prettier --cache --cache-strategy=content --write .","postbuild":"node ./build/convertEsmToCjs.js","prerelease":"npm test && cp LICENSE package.json README.md ./build/src && rm ./build/src/types.cjs ./build/src/types.js"},"_npmUser":{"name":"uid-11222","email":"UID.11222@gmail.com"},"repository":{"url":"git+https://github.com/joomcode/parse-imports-exports.git","type":"git"},"_npmVersion":"10.8.1","description":"Fast and easy parser for declarations of import and export in ECMAScript/TypeScript","directories":{},"sideEffects":false,"_nodeVersion":"20.16.0","dependencies":{"parse-statements":"1.0.11"},"_hasShrinkwrap":false,"packageManager":"npm@10","devDependencies":{"prettier":">=3.4","typescript":">=5.7"},"_npmOperationalInternal":{"tmp":"tmp/parse-imports-exports_0.2.1_1738722951102_0.4770643941505526","host":"s3://npm-registry-packages-npm-production"},"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","publish_time":1738722951325,"_cnpm_publish_time":1738722951325,"dist-tags":{"latest":"0.2.4"}}