Socket
Socket
Sign inDemoInstall

detective-es6

Package Overview
Dependencies
2
Maintainers
3
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    detective-es6

Get the dependencies of an ES6 module


Version published
Weekly downloads
926K
decreased by-19.17%
Maintainers
3
Install size
4.16 MB
Created
Weekly downloads
 

Package description

What is detective-es6?

The detective-es6 npm package is designed to analyze JavaScript files to find and extract import/require statements. This is particularly useful for tools that need to understand dependencies between modules in ES6, CommonJS, or similar module systems. It can be used for tasks such as bundling, dependency analysis, and refactoring.

What are detective-es6's main functionalities?

Extract import statements from ES6 modules

This feature allows you to extract all import statements from a string of ES6 module code. It's useful for analyzing module dependencies.

const detective = require('detective-es6');
const src = `import { foo } from 'my-module';`;
const dependencies = detective(src);
console.log(dependencies); // Outputs: ['my-module']

Extract require statements from CommonJS modules

This feature enables the extraction of require statements from CommonJS module code, helping in the analysis of dependencies in a Node.js environment.

const detective = require('detective-es6');
const src = `const foo = require('my-module');`;
const dependencies = detective(src);
console.log(dependencies); // Outputs: ['my-module']

Other packages similar to detective-es6

Readme

Source

detective-es6

CI npm version npm downloads

Get the dependencies of an ES6 module

npm install detective-es6

Usage

const fs = require('fs');
const detective = require('detective-es6');

const mySourceCode = fs.readFileSync('myfile.js', 'utf8');

// Pass in a file's content or an AST
const dependencies = detective(mySourceCode);
  • Supports JSX, Flow, and any other features that node-source-walk supports.

You may also (optionally) configure the detective via a second object argument detective(src, options) that supports the following options:

  • skipTypeImports: (Boolean) whether or not to omit type imports (import type {foo} from "mylib";) in the list of extracted dependencies.
  • skipAsyncImports: (Boolean) whether or not to omit async imports (import('foo')) in the list of extracted dependencies.

License

MIT

Keywords

FAQs

Last updated on 12 May 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc