{"name":"parse-imports","version":"0.0.2","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.2","homepage":"https://github.com/TomerAberbach/parse-imports","bugs":{"url":"https://github.com/TomerAberbach/parse-imports/issues"},"dist":{"shasum":"345d24577482d0b1d1298dd894d639d90ca5296c","tarball":"http://registry-npm.ywwl.com/parse-imports/download/parse-imports-0.0.2.tgz","fileCount":25,"integrity":"sha512-xhjirq4bew+gUaH0WPES7aZ8Ww+dXF7iQviqVbBzxJCeCnc4bxuGet2Rm2DLXMRjP0OUIMwE0qcsJRdVOb2Lnw==","signatures":[{"sig":"MEYCIQDfcf5EtQVpE4bwmhKF43uRP736jnlezQLv3EFZ1umcZAIhAMXTgpf5JKGsceix+OoMFphy/TZPBZD24KWfjX6I3+eL","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":50440,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJe2szNCRA9TVsSAnZWagAAdPIQAI2R7Kn2kaT6RYx1dBLo\nP1aBpMlAfUTjuYA6dEUV1YRBXGPZOrVY8XDHexqqiQPdQYpDYeC8jeXsyIsY\nM/NezIpyVgDrRXriCGzTztLFDjaue9Snn54V0wHhhOyyt6BrthqElkMolDkl\nhGFfVZvvA93YEf47wK4IvYKkX43INmSwIemUlH83yJhOIyObhtmY70roiZmR\nVAcPvtIVM6nEcm9YOuffHiEpcg9QxzE9J47Nlom2gIMX6pG1Q0q/JbESbGsM\nTSDrWz5p2rfUhfP2hV9tS1g85UqSzhA6Ef75O/zak7dhIfvxUVgbEufz+NsB\ncCvHVnfQOEFFnQYlde1SIDTL6h1WztVvlaBox/6xsA8GB7btq5Bc3ZXlUhx3\nbQ5L5txl8ZDOWpL3SkeX1kAZRHmLE0fNEfWqu097quLPmEWHYyZynSvXekNo\noaU5sL/D1Zy9ImN+EYBSGytctE+yqCTZasepDIKsJq41p+J75AZ0Tazg5Oz/\nIs48Iwij4wNX8XRjDh1pclRIRP4xwoYTX0W+hBtVokd2WJvcii3k9wfLH2Hk\njE3KMr25h0lQLICuANxmPun7x9wkhRVNXZafKP4b4SUfWWRjThQ/GUppraUp\nQFGgHsCRgLaLJCMPSMEOJvvSOp2ccd50OOtShaHJYFXadH5T5A8EEKRi8iaF\nj8cU\r\n=rYFA\r\n-----END PGP SIGNATURE-----\r\n","size":10406,"noattachment":false,"key":"/parse-imports/-/parse-imports-0.0.2.tgz"},"main":"dist/main/index.js","module":"dist/module/index.js","engines":{"node":">= 10"},"gitHead":"81f282fc154c663e4c61b46450dc4427cb711d75","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 -c ./eslint.config.js --cache --ext mjs,cjs,js --ignore-path .gitignore --ignore-pattern \"**/fixtures/**/*\"","lint:prettier:base":"prettier --loglevel silent"},"_npmUser":{"name":"tomeraberbach","email":"tomeraberbach@gmail.com"},"repository":{"url":"git+https://github.com/TomerAberbach/parse-imports.git","type":"git"},"_npmVersion":"6.14.5","description":"A blazing fast ES module imports parser.","directories":{},"_nodeVersion":"14.3.0","dependencies":{"slashes":"2.0.2","es-module-lexer":"0.3.20"},"_hasShrinkwrap":false,"devDependencies":{"ava":"3.8.2","husky":"4.2.5","eslint":"7.1.0","rimraf":"3.0.2","prettier":"2.0.5","cross-env":"7.0.2","@ava/babel":"1.0.1","@babel/cli":"7.10.1","fast-check":"1.24.2","@babel/core":"7.10.2","lint-staged":"10.2.7","microbundle":"0.12.0","npm-run-all":"4.1.5","babel-eslint":"10.1.0","power-assert":"1.6.1","shift-fuzzer":"1.0.2","get-all-files":"2.0.1","shift-codegen":"7.0.0","ava-fast-check":"1.1.2","command-exists":"1.2.9","@babel/register":"7.10.1","@commitlint/cli":"8.3.5","@babel/preset-env":"7.10.2","eslint-plugin-ava":"10.3.0","babel-plugin-unassert":"3.0.1","eslint-config-prettier":"6.11.0","eslint-plugin-prettier":"3.1.3","babel-preset-power-assert":"3.0.0","@commitlint/config-conventional":"8.3.4"},"_npmOperationalInternal":{"tmp":"tmp/parse-imports_0.0.2_1591397580523_0.20140386701606205","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":1591397580676,"maintainers":[{"name":"tomeraberbach","email":"tomeraberbach@gmail.com"}],"_cnpm_publish_time":1591397580676,"dist-tags":{"latest":"3.0.0"}}