JSPM

is-require

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2521
  • Score
    100M100P100Q111877F
  • License MIT

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

Package Exports

  • is-require

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (is-require) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.