# find-imports

> Find all imported modules in JavaScript files.

Latest version **1.1.0** (published 2018-11-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install find-imports
pnpm add find-imports
yarn add find-imports
bun add find-imports
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2018-11-05 |
| First published | 2016-05-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/find-imports) |
| Module format | CommonJS |
| Dependencies | 22 |
| Unpacked size | 32 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 37 |
| Author | Cheton Wu |
| Maintainers | cheton |

## Links

- npm: https://www.npmjs.com/package/find-imports
- Repository: https://github.com/cheton/find-imports
- Issues: https://github.com/cheton/find-imports/issues
- npm.io page: https://npm.io/package/find-imports

## Dependencies (22)

- [glob](https://npm.io/package/glob.md) ^7.1.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [esprima](https://npm.io/package/esprima.md) ^3.1.3
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.0.0
- [ensure-array](https://npm.io/package/ensure-array.md) ^1.0.0
- [@babel/preset-env](https://npm.io/package/@babel/preset-env.md) ^7.0.0
- [@babel/plugin-syntax-import-meta](https://npm.io/package/@babel/plugin-syntax-import-meta.md) ^7.0.0
- [@babel/plugin-proposal-decorators](https://npm.io/package/@babel/plugin-proposal-decorators.md) ^7.0.0
- [@babel/plugin-proposal-json-strings](https://npm.io/package/@babel/plugin-proposal-json-strings.md) ^7.0.0
- [@babel/plugin-syntax-dynamic-import](https://npm.io/package/@babel/plugin-syntax-dynamic-import.md) ^7.0.0
- [@babel/plugin-proposal-function-bind](https://npm.io/package/@babel/plugin-proposal-function-bind.md) ^7.0.0
- [@babel/plugin-proposal-function-sent](https://npm.io/package/@babel/plugin-proposal-function-sent.md) ^7.0.0
- [@babel/plugin-proposal-do-expressions](https://npm.io/package/@babel/plugin-proposal-do-expressions.md) ^7.0.0
- [@babel/plugin-proposal-class-properties](https://npm.io/package/@babel/plugin-proposal-class-properties.md) ^7.0.0
- [@babel/plugin-proposal-numeric-separator](https://npm.io/package/@babel/plugin-proposal-numeric-separator.md) ^7.0.0
- [@babel/plugin-proposal-optional-chaining](https://npm.io/package/@babel/plugin-proposal-optional-chaining.md) ^7.0.0
- [@babel/plugin-proposal-pipeline-operator](https://npm.io/package/@babel/plugin-proposal-pipeline-operator.md) ^7.0.0
- [@babel/plugin-proposal-throw-expressions](https://npm.io/package/@babel/plugin-proposal-throw-expressions.md) ^7.0.0
- [@babel/plugin-proposal-export-default-from](https://npm.io/package/@babel/plugin-proposal-export-default-from.md) ^7.0.0
- [@babel/plugin-proposal-export-namespace-from](https://npm.io/package/@babel/plugin-proposal-export-namespace-from.md) ^7.0.0
- [@babel/plugin-proposal-nullish-coalescing-operator](https://npm.io/package/@babel/plugin-proposal-nullish-coalescing-operator.md) ^7.0.0
- [@babel/plugin-proposal-logical-assignment-operators](https://npm.io/package/@babel/plugin-proposal-logical-assignment-operators.md) ^7.0.0

## Recent versions

- 1.1.0 (latest) — 2018-11-05
- 1.0.0 — 2018-10-24
- 0.5.2 — 2017-03-11
- 0.5.1 — 2016-09-30
- 0.5.0 — 2016-05-25
- 0.4.0 — 2016-05-22
- 0.3.1 — 2016-05-20
- 0.3.0 — 2016-05-20
- 0.2.0 — 2016-05-20
- 0.1.0 — 2016-05-19

## README

# find-imports [![build status](https://travis-ci.org/cheton/find-imports.svg?branch=master)](https://travis-ci.org/cheton/find-imports) [![Coverage Status](https://coveralls.io/repos/github/cheton/find-imports/badge.svg?branch=master)](https://coveralls.io/github/cheton/find-imports?branch=master)

[![NPM](https://nodei.co/npm/find-imports.png?downloads=true&stars=true)](https://www.npmjs.com/package/find-imports)

Find all imported modules in JavaScript files. It's useful for bundling 3rd-party libraries into a vendor.js using webpack. For example:

```js
var webpack = require('webpack');
var findImports = require('find-imports');

// Webpack Configuration
module.exports = {
    entry: {
        app: [
            './src/index.js'
        ],
        vendor: findImports('src/**/*.{js,jsx}', { flatten: true })
    },
    output: {
        path: path.join(__dirname, 'dist'),
        filename: '[name].js'
    },
    plugins: [
        new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.js')
    ]
};
```

## Installation

```bash
npm install --save-dev find-imports
```

## Usage
The default options only return package imports:
```js
import findImports from 'find-imports';

const files = [
    // glob pattern
    'src/**/*.{js,jsx}',

    // use negative glob pattern to exclude files
    '!src/**/*.spec.js'
];

findImports(files);
// → { 'src/index.jsx':
//     [ 'lodash',
//       'async',
//       'jsuri',
//       'react',
//       'react-dom',
//       'react-router' ] }
```

To flatten the output:
```js
findImports(files, { flatten: true });
// → [ 'lodash',
//     'async',
//     'jsuri',
//     'react',
//     'react-dom',
//     'react-router' ]

```

To return absolute and relative imports:
```js
findImports(files, {
    absoluteImports: true,
    relativeImports: true
});
// → { 'src/index.jsx':
//     [ 'lodash',
//       'async',
//       'jsuri',
//       'react',
//       'react-dom',
//       'react-router',
//       '/index.styl',
//       './index.css' ] }
```

To only return absolute and relative imports (no packages):
```js
findImports(files, {
    absoluteImports: true,
    relativeImports: true,
    packageImports: false
});
// → { 'src/index.jsx':
//     [ '/index.styl',
//       './index.css' ] }
```

## Options
Below are the options with their default values:
```js
{
    flatten: false,
    packageImports: true,
    absoluteImports: false,
    relativeImports: false
}
```

### flatten
Type: `Boolean` Default: <i>false</i>

Sets <i>true</i> to flatten the output and filter duplicate ones.

### packageImports
Type: `Boolean` Default: <i>true</i>

Sets <i>true</i> to return package imports.

### absoluteImports
Type: `Boolean` Default: <i>false</i>

Sets <i>true</i> to return absolute imports.

### relativeImports
Type: `Boolean` Default: <i>false</i>

Sets <i>false</i> to return relative imports.

## License

Copyright (c) 2016 Cheton Wu

Licensed under the [MIT License](LICENSE).

---
_Source: https://npm.io/package/find-imports · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
