1 | /**
|
2 | * Creates a test function from a list of module names. The resulting function
|
3 | * accepts a string id and returns whether it matches a module in the list.
|
4 | *
|
5 | * The string id can be a module name (e.g. `lodash`) or a
|
6 | * "module path" (e.g. `lodash/map`).
|
7 | *
|
8 | * @param {Array} modulesNames Array of module names to match against.
|
9 | * @returns {function(String): (boolean)} Predicate function accepting a string id.
|
10 | */
|
11 | export default function getModulesMatcher(modulesNames) {
|
12 | const regexps = modulesNames.map(moduleRegExp);
|
13 | return id => regexps.some(regexp => regexp.test(id));
|
14 | }
|
15 |
|
16 | const moduleRegExp = module => new RegExp(`^${module}(\\/\.+)*$`);
|