require-regex
v1.0.0
Published
A regex for require statements
Downloads
2
Readme
require-regex
A regex for require statements - based on requires-regex with some enhancements.
Install
$ npm install require-regex
Usage
const requireRegex = require('require-regex');
requireRegex().exec('const foo = require(\'bar\');');
//=> ['var foo = require(\'bar\')',
// 'foo',
// 'bar',
// index: 0,
// input: 'var foo = require(\'bar\');']
const code = `
const insertCss = require('insert-css');
const stylis = require('stylis');
const insert = styles => {
const assembleTemplate = require('assemble-template');
if (typeof window == 'object') {
const styleElement = insertCss(styles);
styleElement.setAttribute('class', 'vxv_style');
}
};
`;
const regex = new RegExp(requireRegex().source, 'gm');
code.match(regex);
// => ['const insertCss = require(\'insert-css\');',
// 'const stylis = require(\'stylis\');',
// 'const assembleTemplate = require(\'assemble-template\');']
re().test('require(\'foo\');');
// => true
License
MIT © Tobias Herber