THe main export is a function that must be called. This ensures that a new regex is returned each time the function is called.
const regex = require('{%= name %}')();
const match = regex.exec('const foo = require(\'@bar/baz\');');
console.log(match);
// [ 'const foo = require(\'@bar/baz\');',
// undefined,
// 'foo',
// '\'',
// '@bar/baz',
// 'bar',
// 'baz',
// index: 0,
// input: 'const foo = require(\'@bar/baz\');' ]
Match results
0
- the full match1
- require statements inside quoted strings, otherwise undefined.2
- variable name beforerequire()
, if defined, otherwise undefined3
- leading quote insiderequire()
, this is used as a reference to match ends on a trailing quote of the same type4
- the full name inside therequire()
statement. For example, inrequire("@foo/bar")
, the full name is@foo/bar
.5
- the first segment of a scoped name. For example,foo
in@foo/bar
. Otherwise undefined.6
- the second segment of a scoped name. For example,bar
in@foo/bar
. Otherwise undefined.