diff --git a/docmd/injection.md b/docmd/injection.md index b5e66f7..8095dc4 100644 --- a/docmd/injection.md +++ b/docmd/injection.md @@ -93,3 +93,7 @@ circular depencencies will issue a warning in the console and the injected argum ### prototype inheritance cdi can work with prototype inheritance and will also resolve dependencies in parent prototypes. For more details visit {@tutorial prototype_inheritance} + + +### Find your module +The ModuleResolver has a method **getModuleNames(regex)**. With this method you can query all existing modules and their alias with a regular expression to find modules like controller, models etc. \ No newline at end of file diff --git a/docs/ModuleResolver.html b/docs/ModuleResolver.html index d551b8b..b5bff9c 100644 --- a/docs/ModuleResolver.html +++ b/docs/ModuleResolver.html @@ -339,7 +339,7 @@
Retrieves a list of module names which match a regular expression
+Name | + + +Type | + + + + + +Description | +
---|---|---|
regex |
+
+
+ + + +RegExp + + + + | + + + + + ++ |
An array of matched module names
+So lets look at it in action: // now you got your bike with injected wheels, which got the size information injected
circular depencencies will issue a warning in the console and the injected argument will be null.
cdi can work with prototype inheritance and will also resolve dependencies in parent prototypes. For more details visit Prototype Inheritance
+The ModuleResolver has a method getModuleNames(regex). With this method you can query all existing modules and their alias with a regular expression to find modules like controller, models etc.
diff --git a/src/ModuleResolver.js b/src/ModuleResolver.js index 7077cbf..5d5d0a7 100644 --- a/src/ModuleResolver.js +++ b/src/ModuleResolver.js @@ -127,6 +127,15 @@ class ModuleResolver { fs.writeFileSync(this.cacheFile, JSON.stringify(this.cache, null, '\t')); } + /** + * Retrieves a list of module names which match a regular expression + * @param {RegExp} regex + * @return {Array} An array of matched module names + */ + getModuleNames(regex) { + return Object.keys(this.cache.moduleMap).filter(name => regex.test(name)); + } + } module.exports = ModuleResolver; diff --git a/test/ModuleResolver.test.js b/test/ModuleResolver.test.js index 601f4dd..0c6e7c2 100644 --- a/test/ModuleResolver.test.js +++ b/test/ModuleResolver.test.js @@ -58,6 +58,12 @@ describe("Module Resolver", function () { expect(moduleResolver.getResolvedModules().fileCache['gibberish.md']).not.exist; }); + it("searching for modules by regex", function() { + let moduleResolver = new ModuleResolver([simpleClassPath], null, moduleAnalyzerMock); + expect(moduleResolver.getModuleNames(/class.*/)).to.eql([]); + expect(moduleResolver.getModuleNames(/Class.*/)).to.have.members(["Class6", "Class7", "Class8"]); + }); + }); describe("Caching", function () {