parse-import-specifiers

Simplest possible way to parse ImportSpecifiers

MIT 4 个版本
安装
npm install parse-import-specifiers
yarn add parse-import-specifiers
pnpm add parse-import-specifiers
bun add parse-import-specifiers
README

parse-import-specifiers NPM version

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

版本列表
1.0.3 2024-03-06
1.0.2 2023-06-07
1.0.1 2023-06-07
1.0.0 2023-06-07