5.2.1 • Published 2 years ago

detective v5.2.1

Weekly downloads
2,013,975
License
MIT
Repository
github
Last release
2 years ago

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

5.2.1

2 years ago

5.2.0

5 years ago

5.1.0

6 years ago

5.0.2

6 years ago

5.0.1

6 years ago

5.0.0

6 years ago

4.7.1

6 years ago

4.7.0

6 years ago

4.6.0

6 years ago

4.5.0

7 years ago

4.4.0

7 years ago

4.3.2

7 years ago

4.3.1

8 years ago

4.3.0

8 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

9 years ago

4.0.1

9 years ago

4.0.0

9 years ago

3.1.0

10 years ago

3.0.0

10 years ago

2.4.1

10 years ago

2.4.0

10 years ago

2.3.0

10 years ago

2.2.0

11 years ago

2.1.2

11 years ago

2.1.1

11 years ago

2.1.0

11 years ago

2.0.0

11 years ago

1.1.0

11 years ago

0.2.1

12 years ago

0.2.0

12 years ago

0.1.1

12 years ago

0.1.0

12 years ago

0.0.4

12 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