
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
match-requires
Advanced tools
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.
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.
(TOC generated by verb using markdown-toc)
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 and/or quoted strings.
var str = '/* require(\'a-b-c\');*/\nvar fooBar = require(\'foo-bar\');';
re(str, function(content) {
return require('my-own-comment-stripper')(content);
});
See the generated output that each lib produces for each benchmark.
#1: after-return.js
crequire.js x 153,480 ops/sec ±0.71% (97 runs sampled)
detective.js x 55,015 ops/sec ±1.04% (91 runs sampled)
match-requires.js x 2,439,019 ops/sec ±0.77% (98 runs sampled)
#2: basic.js
crequire.js x 391,131 ops/sec ±0.63% (96 runs sampled)
detective.js x 102,594 ops/sec ±0.84% (99 runs sampled)
match-requires.js x 2,674,151 ops/sec ±0.83% (94 runs sampled)
#3: do-while.js
crequire.js x 102,220 ops/sec ±0.93% (96 runs sampled)
detective.js x 41,635 ops/sec ±0.81% (97 runs sampled)
match-requires.js x 1,535,496 ops/sec ±0.59% (99 runs sampled)
#4: if-statement.js
crequire.js x 121,816 ops/sec ±0.82% (93 runs sampled)
detective.js x 43,148 ops/sec ±1.02% (96 runs sampled)
match-requires.js x 1,750,488 ops/sec ±0.72% (98 runs sampled)
#5: in-method.js
crequire.js x 268,212 ops/sec ±0.64% (97 runs sampled)
detective.js x 55,454 ops/sec ±0.98% (96 runs sampled)
match-requires.js x 2,567,571 ops/sec ±0.77% (95 runs sampled)
#6: multiple.js
crequire.js x 70,591 ops/sec ±0.54% (96 runs sampled)
detective.js x 21,315 ops/sec ±0.96% (98 runs sampled)
match-requires.js x 893,286 ops/sec ±0.77% (96 runs sampled)
requires-regex: Regular expression for matching javascript require statements. | homepage
Install dev dependencies:
$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Jon Schlinkert
Copyright © 2016 Jon Schlinkert Released under the MIT license.
This file was generated by verb on January 08, 2016.
FAQs
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.
The npm package match-requires receives a total of 165 weekly downloads. As such, match-requires popularity was classified as not popular.
We found that match-requires demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.