match-requires 
Match require statements in a string. Returns an array of matching require statements. Each match is an object with line number, variable name, and module name. Statements in code comments are ignored.
Install
Install with npm:
npm i match-requires --save-dev
Run tests
npm test
Usage
var re = require('match-requires');
console.log(re('require(\'a-b-c\');\nvar fooBar = require(\'foo-bar\');'))
Returns:
[ { line: 1,
variable: '',
module: 'a-b-c',
original: 'require(\'a-b-c\');' },
{ line: 2,
variable: 'fooBar',
module: 'foo-bar',
original: 'var fooBar = require(\'foo-bar\');' } ]
To ignore require statements found in code comments, pass true as the second arg:
re('/* require(\'a-b-c\');*/\nvar fooBar = require(\'foo-bar\');');
Returns:
[ { line: 2,
variable: 'fooBar',
module: 'foo-bar',
original: 'var fooBar = require(\'foo-bar\');' } ]
You may also pass a custom function for stripping code comments.
var str = '/* require(\'a-b-c\');*/\nvar fooBar = require(\'foo-bar\');';
re(str, function(content) {
return content.replace(/foo/, '');
});
Author
Jon Schlinkert
License
Copyright (c) 2014 Jon Schlinkert
Released under the MIT license
This file was generated by verb on November 23, 2014.