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.
detect-import-require
Advanced tools
This is like detective, but with a narrow focus and thin API, specifically aimed at supporting either import
and/or require
statements, and not much more.
npm install detect-import-require --save
Given the following file:
source.js
var foo = require('a').foo
var bar = require('./blah.js')
import { uniq } from 'lodash'
import { resolve } from 'path'
var fs = require('fs')
var detect = require('detect-import-require')
var src = fs.readFileSync('source.js', 'utf8')
console.log(detect(src))
//=> [ 'a', './blah.js', 'lodash', 'path' ]
modules = detect(src, [opt])
Returns an array of module names (require paths) from the given src
String or Buffer, which is assumed to be ES6/ES5. By default, looks for import
and require
statements. Results are not de-duplicated, and are in the order they are found.
Options:
imports
(Boolean) - whether to look for import
statements, default truerequires
(Boolean) - whether to look for require
statements, default truemodules = detect.find(src, [opt])
Takes the same options as above, but returns an object with the following additional data:
{
strings: [],
expressions: [],
nodes: []
}
Where strings
is the array of module names, expressions
is an array of expressions from dynamic require()
statements, and nodes
is an array of AST nodes for each found require/import statement.
Expressions do not appear in imports, and look like this:
[
"path.join(__dirname, '/foo.js')",
"__dirname + '/file.js'"
]
MIT, see LICENSE.md for details.
FAQs
list require and import paths from a JavaScript source
The npm package detect-import-require receives a total of 55 weekly downloads. As such, detect-import-require popularity was classified as not popular.
We found that detect-import-require 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.