parse-import-specifiers
v1.0.3
Published
Simplest possible way to parse ImportSpecifiers
Downloads
21,575
Maintainers
Readme
parse-import-specifiers
Parse ImportSpecifiers
to 3 arrays
according to type.
Reasoning
There is 3
types of ImportSpecifiers
:
import test from 'supertape';
import * as test from 'supertape';
import {stub} from 'supertape';
So:
- ☝️ When you generate code you should remember that after code transformations
ImportDefaultSpecifier
can be at the placce of an array. - ☝️ When you check specifiers to destructure you should distinguish Import Specifiers from each other to determine what to do next.
Install
npm i parse-import-specifiers
API
const {parseImportSpecifiers} = require('parse-imports-specifiers');
const {
defaults,
namespaces,
imports,
} = parseImportSpecifiers(specifiers);
for (const spec of defaults) {}
for (const spec of namespaces) {}
for (const spec of imports) {}
License
MIT