Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
import-modules
Advanced tools
The import-modules npm package is designed to dynamically import all modules from a specified directory. This can be particularly useful for loading multiple modules without having to manually require each one, streamlining the process of module management in Node.js applications.
Import all modules from a directory
This feature allows you to import all modules from a specified directory. The `importModules` function takes the path to the directory as an argument and returns an object containing all the modules in that directory.
const importModules = require('import-modules');
const modules = importModules('path/to/directory');
console.log(modules);
Filter modules by file extension
This feature allows you to filter the modules by file extension. By passing a filter option, you can specify which files to include, such as only JavaScript files.
const importModules = require('import-modules');
const jsModules = importModules('path/to/directory', { filter: '**/*.js' });
console.log(jsModules);
Custom module key
This feature allows you to customize the keys of the imported modules. By setting the `camelize` option to false, the keys will not be camelized, preserving the original file names.
const importModules = require('import-modules');
const modules = importModules('path/to/directory', { camelize: false });
console.log(modules);
The require-all package provides similar functionality by requiring all modules within a directory. It offers options for filtering files and customizing the module keys. Compared to import-modules, require-all is more focused on requiring modules rather than importing them, but the end result is quite similar.
The glob package allows you to match files using patterns, which can then be required or imported manually. While it does not directly import modules, it provides powerful file matching capabilities that can be used in conjunction with require or import statements. This makes it more flexible but requires additional steps compared to import-modules.
The readdirp package is a recursive version of fs.readdir, allowing you to read directories and their subdirectories. It can be used to find files and then require or import them manually. Like glob, it offers more flexibility but requires additional steps to achieve the same functionality as import-modules.
Import all modules in a directory
This package is intentionally simple. Not interested in more features.
$ npm install import-modules
.
└── directory
├── foo-bar.js
└── baz-faz.js
const importModules = require('import-modules');
const modules = importModules('directory');
console.log(modules);
//=> {fooBar: [Function], bazFaz: [Function]}
Type: string
Default: __dirname
Directory to import modules from. Unless you've set the fileExtensions
option, that means any .js
, .json
, .node
files, in that order. Does not recurse. Ignores the caller file and files starting with .
or _
.
Type: object
Type: boolean
Default: true
Convert dash-style names (foo-bar
) and snake-style names (foo_bar
) to camel-case (fooBar
).
Type: string[]
Default: ['.js', '.json', '.node']
File extensions to look for. Order matters.
FAQs
Import all modules in a directory
The npm package import-modules receives a total of 277,889 weekly downloads. As such, import-modules popularity was classified as popular.
We found that import-modules demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.