esm-import-regex
v1.0.0
Published
Regular expressions for matching ESM import statements.
Downloads
3
Readme
esm-import-regex
Regular expressions for matching ESM import statements.
Installation
npm i esm-import-regex
Usage
const importRegex = require('esm-import-regex');
const regex1 = importRegex();
console.log(regex1.exec('import defaultMember from "module-name";'));
// [
// 'import defaultMember from "module-name";',
// 'defaultMember ',
// 'module-name',
// index: 0,
// input: 'import defaultMember from "module-name";',
// groups: undefined
// ]
const regex2 = importRegex();
console.log(regex2.exec('import \'module-name\''));
// [
// "import 'module-name'",
// undefined,
// 'module-name',
// index: 0,
// input: "import 'module-name'",
// groups: undefined
// ]
Match results
0
- full match1
- entire export statement if present2
- module to import from
Tests
Tests validate parsing all the MDN import
examples.
npm run test
License
MIT