{"name":"parse-imports","version":"0.0.5","keywords":["esm","imports","module","parser","imports"],"author":{"url":"https://tomeraberba.ch","name":"Tomer Aberbach","email":"tomeraberbach@gmail.com"},"license":"Apache 2.0","_id":"parse-imports@0.0.5","homepage":"https://github.com/TomerAberbach/parse-imports","bugs":{"url":"https://github.com/TomerAberbach/parse-imports/issues"},"ava":{"babel":true,"files":["**/{*.,}test.js"],"require":["@babel/register"]},"dist":{"shasum":"80e505b9558d6fa8d760b9f0be64f42f65bf4d17","tarball":"http://registry-npm.ywwl.com/parse-imports/download/parse-imports-0.0.5.tgz","fileCount":25,"integrity":"sha512-yA6mDNotJmyAXcEdi2AjiHfI8Llk+/uv/jgBgvzFVP8iGaHC5L3rR6VQk/1qEE3SvLUsDQ2GdQMfPTi0qrmt8Q==","signatures":[{"sig":"MEQCICgmDhF3efaHW/xSNGCbw0tmVLY7bi1ZVQ1Cm7afeUXEAiA0Cz342CXlygDjcNTxlv0YxeuEvGA2VFegAU4Y5pu7mA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":51046,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf78ldCRA9TVsSAnZWagAAohsP/RfXyja+bB4kRtRvsRl+\nJWljZvdd5MsWaN12ODIg/yazobYohRX1ME1WJjQF67FLnxGV0QIgaL2M2MHf\n1PKZ5DvnYPK3aiN1uMWSRUm4+3J3bZuQlSsfX1YTHxT0u+w+NPxnqtNYsVRU\n5CDw2yNTVeDQnIf4mD4gGzpkFAM3f/0xmKWVR5X9euVcZ5TxvFgqMHV9tDRu\nBazgiy+CSb3ifQXLCGcOl9n/Y5uOHDJAKeBEvq6brKe/LVptz1H9DZfe0S1i\nvzjp/QCl4I0+G3B+TvjMO/UWQNzwY+JVkSCizCQxiKMQedG2oe0gNJiNIOH7\nI2mdNgoNQidkMq3Hqgc1Zg+49dBOdY9QF9apTcpUY10sBw+unBzIu4nm1Ne+\nvPPsfHnJqzEpID8eulH0pCx4bTMzuVJL6gt4wj4O08x/hSKEmFE0jkky4Ehl\n7h+tnNamInOLjWrQ+iWzKqR9xkPa5Sc9TwCbSpwkSRoTeCvt1N/whyUQEm+Z\nIGh0jFEFMU0Lr79fxXB+XoKLWEbU49tDaKG4P8w05t3d69aruRdhtYyLeXv3\nBaYpA/ci9sLJhu5/To78dojDElrD4TnSUz8Wuig9a9EebDuzo+T9QdlUQN7c\nG2J0VJwoiJXj0L02IaBq9QpMK+U8ubwWjfUgputIfPGqo5EsCdjtZsDyjV6p\n8qsH\r\n=k31L\r\n-----END PGP SIGNATURE-----\r\n","size":10550,"noattachment":false,"key":"/parse-imports/-/parse-imports-0.0.5.tgz"},"main":"dist/main/index.js","husky":{"hooks":{"pre-push":"pnpm run test","commit-msg":"commitlint -E HUSKY_GIT_PARAMS","pre-commit":"lint-staged"}},"module":"dist/module/index.js","engines":{"node":">= 10"},"gitHead":"0fc879bd8ece5f9129b58883be278196cc56c8cd","scripts":{"lint":"run-s lint:*","test":"ava","clean":"rimraf dist","license":"addlicense $(git diff --name-only HEAD)","build:dev":"pnpm run build:base -- -d dist src","build:base":"babel --delete-dir-on-start -D --no-copy-ignored --keep-file-extension --ignore \"src/**/*.test.js,src/**/fixtures/**/*\"","build:main":"cross-env NODE_ENV=main pnpm run build:base -- -d dist/main src","build:prod":"run-p build:main build:module","lint:eslint":"pnpm run lint:eslint:base -- --fix .","build:module":"cross-env NODE_ENV=module pnpm run build:base -- -d dist/module src","lint:prettier":"pnpm run lint:prettier:base -- --write .","lint:eslint:base":"eslint --cache --ext mjs,cjs,js --ignore-path .gitignore --ignore-pattern \"**/fixtures/**/*\"","lint:prettier:base":"prettier --loglevel silent"},"_npmUser":{"name":"tomeraberbach","email":"tomeraberbach@gmail.com"},"prettier":"@tomer/prettier-config","commitlint":{"extends":"@commitlint/config-conventional"},"repository":{"url":"git+https://github.com/TomerAberbach/parse-imports.git","type":"git"},"_npmVersion":"6.14.8","description":"A blazing fast ES module imports parser.","directories":{},"_nodeVersion":"15.3.0","browserslist":["node >= 10"],"dependencies":{"slashes":"2.0.2","es-module-lexer":"0.3.26"},"eslintConfig":{"extends":"@tomer"},"_hasShrinkwrap":false,"devDependencies":{"ava":"3.15.0","husky":"4.3.6","eslint":"7.16.0","rimraf":"3.0.2","prettier":"2.2.1","cross-env":"7.0.3","@ava/babel":"1.0.1","@babel/cli":"7.12.10","fast-check":"2.10.0","@babel/core":"7.12.10","@types/node":"14.14.19","lint-staged":"10.5.3","npm-run-all":"4.1.5","babel-eslint":"10.1.0","power-assert":"1.6.1","shift-fuzzer":"1.0.2","shift-codegen":"7.0.3","ava-fast-check":"4.0.0","command-exists":"1.2.9","@babel/register":"7.12.10","@commitlint/cli":"11.0.0","@babel/preset-env":"7.12.11","@tomer/eslint-config":"0.0.14","babel-plugin-unassert":"3.0.1","@tomer/prettier-config":"0.0.2","babel-preset-power-assert":"3.0.0","@commitlint/config-conventional":"11.0.0"},"_npmOperationalInternal":{"tmp":"tmp/parse-imports_0.0.5_1609550172596_0.9305100507371993","host":"s3://npm-registry-packages"},"readme":"<h1 align=\"center\">\n  parse-imports\n</h1>\n\n<div align=\"center\">\n  <a href=\"https://npmjs.org/package/parse-imports\">\n    <img src=\"https://badgen.now.sh/npm/v/parse-imports\" alt=\"version\" />\n  </a>\n  <a href=\"https://github.com/TomerAberbach/parse-imports/actions\">\n    <img src=\"https://github.com/TomerAberbach/parse-imports/workflows/CI/badge.svg\" alt=\"CI\" />\n  </a>\n  <a href=\"https://github.com/sponsors/TomerAberbach\">\n    <img src=\"https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86\" alt=\"Sponsor\">\n  </a>\n</div>\n\n<div align=\"center\">\n  A blazing fast ES module imports parser.\n</div>\n\n## Features\n\n- Uses the superb WASM-based\n  [`es-module-lexer`](https://github.com/guybedford/es-module-lexer) under the\n  hood\n- Identifies module specifier types (e.g. relative file import, package import,\n  builtin import, etc.)\n- Unescapes module specifier escape sequences\n- Collects default, named, and namespace imports\n- Works with dynamic imports\n- Resolves module specifier paths via `require.resolve`\n\n## Install\n\n```sh\n$ npm i parse-imports\n```\n\n## Usage\n\n```js\nimport { parseImports } from 'parse-imports'\n\nconst code = `\n  import a from 'b'\n  import * as c from './d'\n  import { e as f, g as h, i } from '/j'\n  import k, { l as m } from 'n'\n  import o, * as p from \"./q\"\n  import r, { s as t, u } from \"/v\"\n  import fs from 'fs'\n\n  ;(async () => {\n    await import(\"w\")\n    await import(\"x\" + \"y\")\n  })()\n`\n\n// Lazily iterate over iterable of imports\nfor (const $import of await parseImports(code)) {\n  console.log($import)\n}\n\n// Or get as an array of imports\nconst imports = [...(await parseImports(code))]\n\nconsole.log(imports[0])\n//=>\n// {\n//   startIndex: 3,\n//   endIndex: 20,\n//   isDynamicImport: false,\n//   moduleSpecifier: {\n//     type: 'package',\n//     startIndex: 17,\n//     endIndex: 20,\n//     isConstant: true,\n//     code: `'b'`,\n//     value: 'b',\n//     resolved: undefined\n//   },\n//   importClause: {\n//     default: 'a',\n//     named: [],\n//     namespace: undefined\n//   }\n// }\n\nconsole.log(imports[1])\n//=>\n// {\n//   startIndex: 23,\n//   endIndex: 47,\n//   isDynamicImport: false,\n//   moduleSpecifier: {\n//     type: 'relative',\n//     startIndex: 42,\n//     endIndex: 47,\n//     isConstant: true,\n//     code: `'./d'`,\n//     value: './d',\n//     resolved: undefined\n//   },\n//   importClause: {\n//     default: undefined,\n//     named: [],\n//     namespace: 'c'\n//   }\n// }\n\nconsole.log(imports[5])\n//=>\n// {\n//   startIndex: 153,\n//   endIndex: 186,\n//   isDynamicImport: false,\n//   moduleSpecifier: {\n//     type: 'absolute',\n//     startIndex: 182,\n//     endIndex: 186,\n//     isConstant: true,\n//     code: '\"/v\"',\n//     value: '/v',\n//     resolved: undefined\n//   },\n//   importClause: {\n//     default: 'r',\n//     named: [\n//       { specifier: 's', binding: 't' },\n//       { specifier: 'u', binding: 'u' }\n//     ],\n//     namespace: undefined\n//   }\n// }\n\nconsole.log(imports[7])\n//=>\n// {\n//   startIndex: 238,\n//   endIndex: 249,\n//   isDynamicImport: true,\n//   moduleSpecifier: {\n//     type: 'package',\n//     startIndex: 245,\n//     endIndex: 248,\n//     isConstant: true,\n//     code: '\"w\"',\n//     value: 'w',\n//     resolved: undefined\n//   },\n//   importClause: undefined\n// }\n\nconsole.log(imports[8])\n//=>\n// {\n//   startIndex: 260,\n//   endIndex: 277,\n//   isDynamicImport: true,\n//   moduleSpecifier: {\n//     type: 'unknown',\n//     startIndex: 267,\n//     endIndex: 276,\n//     isConstant: false,\n//     code: '\"x\" + \"y\"',\n//     value: undefined,\n//     resolved: undefined\n//   },\n//   importClause: undefined\n// }\n```\n\n## API\n\nUse `parseImports` when you're able to await a `Promise` result and\n`parseImportsSync` otherwise.\n\n> [!IMPORTANT]\n>\n> You can only call `parseImportsSync` once the WASM has loaded. You can be sure\n> this has happened by awaiting the exported `wasmLoadPromise`.\n\nSee the [type definitions](./src/index.d.ts) for details.\n\n### Types\n\n<!-- eslint-skip -->\n\n```ts\ntype ModuleSpecifierType =\n  | 'invalid'\n  | 'absolute'\n  | 'relative'\n  | 'builtin'\n  | 'package'\n  | 'unknown'\n\ntype Import = {\n  startIndex: number\n  endIndex: number\n  isDynamicImport: boolean\n  moduleSpecifier: {\n    type: ModuleSpecifierType\n    startIndex: number\n    endIndex: number\n    isConstant: boolean\n    code: string\n    value?: string\n    resolved?: string\n  }\n  importClause?: {\n    default?: string\n    named: string[]\n    namespace?: string\n  }\n}\n```\n\n#### `Import`\n\n`code.substring(startIndex, endIndex)` returns the full import statement or\nexpression.\n`code.substring(moduleSpecifier.startIndex, moduleSpecifier.endIndex)` returns\nthe module specifier including quotes.\n\n`moduleSpecifier.isConstant` is `true` when the import is not a dynamic import\n(`isDynamicImport` is `false`), or when the import is a dynamic import where the\nspecifier is a simple string literal (e.g. `import('fs')`, `import(\"fs\")`,\n``import(`fs`)``).\n\nIf `moduleSpecifier.isConstant` is `false`, then `moduleSpecifier.type` is\n`'unknown'`. Otherwise, it is set according to the following rules:\n\n- `'invalid'` if the module specifier is the empty string\n- `'absolute'` if the module specifier is an absolute file path\n- `'relative'` if the module specifier is a relative file path\n- `'builtin'` if the module specifier is the name of a builtin Node.js package\n- `'package'` otherwise\n\n`moduleSpecifier.code` is the module specifier as it was written in the code.\nFor non-constant dynamic imports it could be a complex expression.\n\n`moduleSpecifier.value` is `moduleSpecifier.code` without string literal quotes\nand unescaped if `moduleSpecifier.isConstant` is `true`. Otherwise, it is\n`undefined`.\n\n`moduleSpecifier.resolved` is set if the `resolveFrom` option is set and\n`moduleSpecifier.value` is not `undefined`.\n\n`importClause` is only `undefined` if `isDynamicImport` is `true`.\n\n`importClause.default` is the default import identifier or `undefined` if the\nimport statement does not have a default import.\n\n`importClause.named` is the array of objects representing the named imports of\nthe import statement. It is empty if the import statement does not have any\nnamed imports. Each object in the array has a `specifier` field set to the\nimported identifier and a `binding` field set to the identifier for accessing\nthe imported value. For example, `import { a, x as y } from 'something'` would\nhave the following array for `importClause.named`:\n`[{ specifier: 'a', binding: 'a' }, { specifier: 'x', binding: 'y' }]`.\n\n`importClause.namespace` is the namespace import identifier or `undefined` if\nthe import statement does not have a namespace import.\n\n## Contributing\n\nStars are always welcome!\n\nFor bugs and feature requests,\n[please create an issue](https://github.com/TomerAberbach/parse-imports/issues/new).\n\nFor pull requests, please read the\n[contributing guidelines](https://github.com/TomerAberbach/parse-imports/blob/main/contributing.md).\n\n## License\n\n[Apache 2.0](https://github.com/TomerAberbach/parse-imports/blob/main/license)\n\nThis is not an official Google product.\n","publish_time":1609550172784,"maintainers":[{"name":"tomeraberbach","email":"tomeraberbach@gmail.com"}],"_cnpm_publish_time":1609550172784,"dist-tags":{"latest":"3.0.0"}}