{"id":19584772,"url":"https://github.com/flex-development/import-regex","last_synced_at":"2025-09-15T18:32:12.935Z","repository":{"id":63756502,"uuid":"569991429","full_name":"flex-development/import-regex","owner":"flex-development","description":"Import statement regex","archived":false,"fork":false,"pushed_at":"2024-04-23T00:34:38.000Z","size":3415,"stargazers_count":2,"open_issues_count":10,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-11T22:47:13.149Z","etag":null,"topics":["dynamic-import","ecmascript","import","regex","static-import","typescript"],"latest_commit_sha":null,"homepage":"https://github.com/flex-development/import-regex","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flex-development.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/funding.yml","license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":["flex-development"]}},"created_at":"2022-11-24T04:47:12.000Z","updated_at":"2024-05-08T07:01:29.000Z","dependencies_parsed_at":"2023-09-29T02:32:36.412Z","dependency_job_id":"ac0ca1c1-d85c-4e52-8725-27211bf2b6b7","html_url":"https://github.com/flex-development/import-regex","commit_stats":{"total_commits":134,"total_committers":2,"mean_commits":67.0,"dds":0.4477611940298507,"last_synced_commit":"9334c02567085999165e8e8d05a18f4c35c699da"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Fimport-regex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Fimport-regex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Fimport-regex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Fimport-regex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flex-development","download_url":"https://codeload.github.com/flex-development/import-regex/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233142860,"owners_count":18631409,"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":["dynamic-import","ecmascript","import","regex","static-import","typescript"],"created_at":"2024-11-11T07:49:38.275Z","updated_at":"2025-09-15T18:32:07.236Z","avatar_url":"https://github.com/flex-development.png","language":"JavaScript","funding_links":["https://github.com/sponsors/flex-development"],"categories":[],"sub_categories":[],"readme":"# import-regex\n\n[![github release](https://img.shields.io/github/v/release/flex-development/import-regex.svg?include_prereleases\u0026sort=semver)](https://github.com/flex-development/import-regex/releases/latest)\n[![npm](https://img.shields.io/npm/v/@flex-development/import-regex.svg)](https://npmjs.com/package/@flex-development/import-regex)\n[![codecov](https://codecov.io/github/flex-development/import-regex/branch/main/graph/badge.svg?token=2FBWJR3AKR)](https://codecov.io/github/flex-development/import-regex)\n[![module type: esm](https://img.shields.io/badge/module%20type-esm-brightgreen)](https://github.com/voxpelli/badges-cjs-esm)\n[![license](https://img.shields.io/github/license/flex-development/import-regex.svg)](LICENSE.md)\n[![conventional commits](https://img.shields.io/badge/-conventional%20commits-fe5196?logo=conventional-commits\u0026logoColor=ffffff)](https://conventionalcommits.org/)\n[![typescript](https://img.shields.io/badge/-typescript-3178c6?logo=typescript\u0026logoColor=ffffff)](https://typescriptlang.org/)\n[![vitest](https://img.shields.io/badge/-vitest-6e9f18?style=flat\u0026logo=vitest\u0026logoColor=ffffff)](https://vitest.dev/)\n[![yarn](https://img.shields.io/badge/-yarn-2c8ebb?style=flat\u0026logo=yarn\u0026logoColor=ffffff)](https://yarnpkg.com/)\n\n`import` statement regex.\n\n## Contents\n\n- [What is this?](#what-is-this)\n- [When should I use this?](#when-should-i-use-this)\n- [Install](#install)\n- [Use](#use)\n- [API](#api)\n- [Types](#types)\n- [Related](#related)\n- [Contribute](#contribute)\n\n## What is this?\n\nThis package contains regular expressions for matching [dynamic][1] and [static][2] `import` statements.\n\n## When should I use this?\n\nUse this package when you need to match dynamic or static `import` statements.\n\n**Note**:\n\n- Statements in docblock (`/** */`), multiline (`/* */`), and single-line (`//`) comments are ignored\n- Expressions are ECMAScript-compatible. They have **not** been tested with other flavors (PCRE, PCRE2, etc)\n\n## Install\n\nThis package is [ESM only][3].\n\n```sh\nyarn add @flex-development/import-regex\n```\n\nFrom Git:\n\n```sh\nyarn add @flex-development/import-regex@flex-development/import-regex\n```\n\n\u003cblockquote\u003e\n  \u003csmall\u003e\n    See \u003ca href='https://yarnpkg.com/features/protocols#git'\u003eGit - Protocols | Yarn\u003c/a\u003e\n    \u0026nbsp;for details on requesting a specific branch, commit, or tag.\n  \u003c/small\u003e\n\u003c/blockquote\u003e\n\n## Use\n\nSuppose we have the following module:\n\n```ts\nimport * as regexp from '@flex-development/import-regex'\nimport { omit } from '@flex-development/tutils'\nimport { dedent } from 'ts-dedent'\n\nconst code: string = dedent`\n  import { defineBuildConfig, type Config } from '@flex-development/mkbuild'\n  import type {\n    Join,\n    Nullable,\n    Opaque,\n    Simplify\n  } from '@flex-development/tutils'\n  import * as color from 'colorette'\n  import consola from 'consola'\n  import tsconfig from './tsconfig.json' assert { type: 'json' }\n\n  const { readPackage } = await import('read-pkg')\n\n  const se2 = 'side-effect-2.mjs'\n\n  await import('./side-effect.mjs')\n  await import(se2)\n`\n\nconst print = (matches: IterableIterator\u003cRegExpMatchArray\u003e): void =\u003e {\n  console.debug([...matches].map(match =\u003e omit(match, ['input'])))\n}\n\nprint(code.matchAll(regexp.STATIC_IMPORT_REGEX))\nprint(code.matchAll(regexp.DYNAMIC_IMPORT_REGEX))\n```\n\n...running that yields:\n\n```sh\n[\n  {\n    '0': \"import { defineBuildConfig, type Config } from '@flex-development/mkbuild'\",\n    '1': undefined,\n    '2': '{ defineBuildConfig, type Config }',\n    '3': '@flex-development/mkbuild',\n    '4': undefined,\n    index: 0,\n    groups: [Object: null prototype] {\n      type: undefined,\n      imports: '{ defineBuildConfig, type Config }',\n      specifier: '@flex-development/mkbuild',\n      assertion: undefined\n    }\n  },\n  {\n    '0': 'import type {\\n' +\n      '  Join,\\n' +\n      '  Nullable,\\n' +\n      '  Opaque,\\n' +\n      '  Simplify\\n' +\n      \"} from '@flex-development/tutils'\",\n    '1': 'type',\n    '2': '{\\n  Join,\\n  Nullable,\\n  Opaque,\\n  Simplify\\n}',\n    '3': '@flex-development/tutils',\n    '4': undefined,\n    index: 75,\n    groups: [Object: null prototype] {\n      type: 'type',\n      imports: '{\\n  Join,\\n  Nullable,\\n  Opaque,\\n  Simplify\\n}',\n      specifier: '@flex-development/tutils',\n      assertion: undefined\n    }\n  },\n  {\n    '0': \"import * as color from 'colorette'\",\n    '1': undefined,\n    '2': '* as color',\n    '3': 'colorette',\n    '4': undefined,\n    index: 164,\n    groups: [Object: null prototype] {\n      type: undefined,\n      imports: '* as color',\n      specifier: 'colorette',\n      assertion: undefined\n    }\n  },\n  {\n    '0': \"import consola from 'consola'\",\n    '1': undefined,\n    '2': 'consola',\n    '3': 'consola',\n    '4': undefined,\n    index: 199,\n    groups: [Object: null prototype] {\n      type: undefined,\n      imports: 'consola',\n      specifier: 'consola',\n      assertion: undefined\n    }\n  },\n  {\n    '0': \"import tsconfig from './tsconfig.json' assert { type: 'json' }\",\n    '1': undefined,\n    '2': 'tsconfig',\n    '3': './tsconfig.json',\n    '4': \"{ type: 'json' }\",\n    index: 229,\n    groups: [Object: null prototype] {\n      type: undefined,\n      imports: 'tsconfig',\n      specifier: './tsconfig.json',\n      assertion: \"{ type: 'json' }\"\n    }\n  }\n]\n[\n  {\n    '0': \"const { readPackage } = await import('read-pkg')\",\n    '1': '{ readPackage }',\n    '2': \"import('read-pkg')\",\n    '3': \"'read-pkg'\",\n    '4': undefined,\n    index: 293,\n    groups: [Object: null prototype] {\n      imports: '{ readPackage }',\n      expression: \"import('read-pkg')\",\n      specifier: \"'read-pkg'\",\n      options: undefined\n    }\n  },\n  {\n    '0': \"await import('./side-effect.mjs')\",\n    '1': undefined,\n    '2': \"import('./side-effect.mjs')\",\n    '3': \"'./side-effect.mjs'\",\n    '4': undefined,\n    index: 376,\n    groups: [Object: null prototype] {\n      imports: undefined,\n      expression: \"import('./side-effect.mjs')\",\n      specifier: \"'./side-effect.mjs'\",\n      options: undefined\n    }\n  },\n  {\n    '0': 'await import(se2)',\n    '1': undefined,\n    '2': 'import(se2)',\n    '3': 'se2',\n    '4': undefined,\n    index: 410,\n    groups: [Object: null prototype] {\n      imports: undefined,\n      expression: 'import(se2)',\n      specifier: 'se2',\n      options: undefined\n    }\n  }\n]\n```\n\n## API\n\nThis package exports the identifiers `DYNAMIC_IMPORT_REGEX` and `STATIC_IMPORT_REGEX`.\n\nThere is no default export.\n\n### `DYNAMIC_IMPORT_REGEX`\n\n- **Source**: [`src/import-dynamic.ts`](src/import-dynamic.ts)\n\nDynamic `import` statement regex. Ignores matches in comments.\n\n**Requires unicode support ([flag `u`][4])**.\n\n### `STATIC_IMPORT_REGEX`\n\n- **Source**: [`src/import-static.ts`](src/import-static.ts)\n\nStatic `import` statement regex. Ignores matches in comments.\n\n## Types\n\nThis package is fully typed with [TypeScript][5].\n\n## Related\n\n- [`export-regex`][6] \u0026mdash; `export` statement regex\n\n## Contribute\n\nSee [`CONTRIBUTING.md`](CONTRIBUTING.md).\n\n[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import\n[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/import\n[3]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n[4]: https://javascript.info/regexp-unicode\n[5]: https://www.typescriptlang.org\n[6]: https://github.com/flex-development/export-regex\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflex-development%2Fimport-regex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflex-development%2Fimport-regex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflex-development%2Fimport-regex/lists"}