JSPM

sleuth

0.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4080
  • Score
    100M100P100Q118891F
  • License MIT

Like detective, find all calls to require by walking the AST, however also supply the variable name used if available

Package Exports

  • sleuth

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 (sleuth) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

sleuth Flattr this!experimental

Like detective, find all calls to require by walking the AST, however also supply the variable name used if available

Usage

sleuth

requires = sleuth(walk|ast|src)

Takes either:

  • Plain JavaScript: src.
  • An esprima-like ast object.
  • A walk function, which is expected to take a function and call it on each node in the tree. Mostly for ease of use with modules like astw.

Returns an object whose keys represent the variable names used to require a module, and whose values are the required module strings detected.

Example

var esprima = require('esprima')
var walkers = require('astw')
var files = require('fs')

var src = files.readFileSync(__filename, 'utf8')
var ast = esprima.parse(src)

// Walk the generated AST
var result = sleuth(ast)
console.log(result)

// Or you can try it this way:
var result = sleuth(walkers(src))
console.log(result)

Which should give you back something like this:

{
  esprima: 'esprima',
  walkers: 'astw',
  files: 'fs'
}

License

MIT. See LICENSE.md for details.