detective
find all require() calls by walking the AST
Last updated 12 years ago by substack .
MIT · Repository · Original npm · Tarball · package.json
$ npm install detective 
SYNC missed versions from official npm registry.

detective

find all calls to require() by walking the AST

build status

example

strings

strings_src.js:

var a = require('a');
var b = require('b');
var c = require('c');

strings.js:

var detective = require('detective');
var fs = require('fs');

var src = fs.readFileSync(__dirname + '/strings_src.js');
var requires = detective(src);
console.dir(requires);

output:

$ node examples/strings.js
[ 'a', 'b', 'c' ]

methods

var detective = require('detective');

detective(src, opts)

Give some source body src, return an array of all the require() calls with string arguments.

The options parameter opts is passed along to detective.find().

var found = detective.find(src, opts)

Give some source body src, return found with:

  • found.strings - an array of each string found in a require()
  • found.expressions - an array of each stringified expression found in a require() call
  • found.nodes (when opts.nodes === true) - an array of AST nodes for each argument found in a require() call

Optionally:

  • opts.word - specify a different function name instead of "require"
  • opts.nodes - when true, populate found.nodes
  • opts.isRequire(node) - a function returning whether an AST CallExpression node is a require call
  • opts.parse - supply options directly to acorn with some support for esprima-style options range and loc
  • opts.ecmaVersion - default: 9

install

With npm do:

npm install detective

license

MIT

Current Tags

  • 5.2.1                                ...           latest (2 years ago)

41 Versions

  • 5.2.1                                ...           2 years ago
  • 5.2.0                                ...           6 years ago
  • 5.1.0                                ...           7 years ago
  • 5.0.2                                ...           7 years ago
  • 5.0.1                                ...           7 years ago
  • 5.0.0                                ...           7 years ago
  • 4.7.1                                ...           7 years ago
  • 4.7.0                                ...           7 years ago
  • 4.6.0                                ...           7 years ago
  • 4.5.0                                ...           8 years ago
  • 4.4.0                                ...           8 years ago
  • 4.3.2                                ...           8 years ago
  • 4.3.1                                ...           9 years ago
  • 4.3.0                                ...           9 years ago
  • 4.2.0                                ...           9 years ago
  • 4.1.1                                ...           9 years ago
  • 4.1.0                                ...           9 years ago
  • 4.0.3                                ...           9 years ago
  • 4.0.2                                ...           10 years ago
  • 4.0.1                                ...           10 years ago
  • 4.0.0                                ...           10 years ago
  • 3.1.0                                ...           11 years ago
  • 3.0.0                                ...           11 years ago
  • 2.4.1                                ...           11 years ago
  • 2.4.0                                ...           11 years ago
  • 2.3.0                                ...           11 years ago
  • 2.2.0                                ...           11 years ago
  • 2.1.2                                ...           11 years ago
  • 2.1.1                                ...           12 years ago
  • 2.1.0                                ...           12 years ago
  • 2.0.0                                ...           12 years ago
  • 1.1.0                                ...           12 years ago
  • 0.2.1                                ...           12 years ago
  • 0.2.0                                ...           12 years ago
  • 0.1.1                                ...           13 years ago
  • 0.1.0                                ...           13 years ago
  • 0.0.4                                ...           13 years ago
  • 0.0.3                                ...           13 years ago
  • 0.0.2                                ...           13 years ago
  • 0.0.1                                ...           13 years ago
  • 0.0.0                                ...           13 years ago
Maintainers (1)
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE