Socket
Socket
Sign inDemoInstall

is-require

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-require

Tests whether an JavaScript AST node is likely to be a valid `require` call.


Version published
Weekly downloads
2.6K
decreased by-6.91%
Maintainers
1
Weekly downloads
 
Created
Source

is-require Flattr this!experimental

Tests whether an JavaScript AST node is likely to be a valid require call. Mostly for convenience, seeing as I've had to copy/paste it a few times now.

Usage

is-require

isRequire = require('is-require')([name])

Returns a function which tests AST nodes for require calls. You can supply your own function name to name to use something other than require.

isRequire(node)

Tests an AST node to see if it is a require call.

var isImports = require('is-require')('imports')
var isRequire = require('is-require')()
var esprima = require('esprima')
var astw = require('astw')
var fs = require('fs')

var src = fs.readFileSync('some-file.js', 'utf8')
var ast = esprima.parse(src)
var walk = astw(ast)

walk(function(node) {
  if (!isRequire(node)) return
  // do things...
})

walk(function(node) {
  if (!isImports(node)) return
  // do things...
})

License

MIT. See LICENSE.md for details.

Keywords

FAQs

Package last updated on 27 Jun 2014

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc