https://github.com/putoutjs/parse-import-specifiers
Simplest possible way to parse ImportSpecifiers
https://github.com/putoutjs/parse-import-specifiers
Last synced: 4 months ago
JSON representation
Simplest possible way to parse ImportSpecifiers
- Host: GitHub
- URL: https://github.com/putoutjs/parse-import-specifiers
- Owner: putoutjs
- License: mit
- Created: 2023-06-07T11:46:38.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-03-06T13:51:02.000Z (over 2 years ago)
- Last Synced: 2025-08-25T11:53:49.176Z (10 months ago)
- Language: JavaScript
- Size: 26.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# parse-import-specifiers [![NPM version][NPMIMGURL]][NPMURL]
[NPMIMGURL]: https://img.shields.io/npm/v/parse-import-specifiers.svg?style=flat&longCache=true
[NPMURL]: https://npmjs.org/package/parse-import-specifiers "npm"
Parse [`ImportSpecifiers`](https://github.com/estree/estree/blob/master/es2015.md#importspecifier) to `3 arrays` according to type.
## Reasoning
There is `3` types of `ImportSpecifiers`:
- ✅[`ImportDefaultSpecifier`](https://github.com/estree/estree/blob/master/es2015.md#importdefaultspecifier)
```js
import test from 'supertape';
```
- ✅[`ImportNamespaceSpecifier`](https://github.com/estree/estree/blob/master/es2015.md#importnamespacespecifier)
```js
import * as test from 'supertape';
```
- ✅[`ImportSpecifier`](https://github.com/estree/estree/blob/master/es2015.md#importspecifier)
```js
import {stub} from 'supertape';
```
So:
- ☝️ *When you [generate code](https://github.com/putoutjs/printer) you should remember that after code transformations `ImportDefaultSpecifier` can be at the placce of an array.*
- ☝️ *When you check [specifiers to destructure](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout/lib/multiple-properties-destructuring#readme) you should distinguish Import Specifiers from each other to determine what to do next*.
## Install
```
npm i parse-import-specifiers
```
## API
```js
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