Skip to content

Latest commit

 

History

History
29 lines (24 loc) · 1.07 KB

.verb.md

File metadata and controls

29 lines (24 loc) · 1.07 KB

Usage

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 match
  • 1 - require statements inside quoted strings, otherwise undefined.
  • 2 - variable name before require(), if defined, otherwise undefined
  • 3 - leading quote inside require(), this is used as a reference to match ends on a trailing quote of the same type
  • 4 - the full name inside the require() statement. For example, in require("@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.