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 @@
Parameters:
Source:
@@ -469,7 +469,7 @@
Parameters:
Source:
@@ -519,6 +519,163 @@
Returns:
+

getModuleNames(regex) → {Array}

+ + + + + + +
+

Retrieves a list of module names which match a regular expression

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
regex + + +RegExp + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

An array of matched module names

+
+ + + +
+
+ Type +
+
+ +Array + + +
+
+ + + + + + + + + + + + +

getResolvedModules() → {Object|*}

@@ -573,7 +730,7 @@

get
Source:
@@ -742,7 +899,7 @@

Parameters:
Source:
@@ -828,7 +985,7 @@

writeCache<
Source:
diff --git a/docs/ModuleResolver.js.html b/docs/ModuleResolver.js.html index dc99c10..3ccecb2 100644 --- a/docs/ModuleResolver.js.html +++ b/docs/ModuleResolver.js.html @@ -57,7 +57,6 @@

Source: ModuleResolver.js

this.moduleAnalyzer = moduleAnalyzer; this.nameCollisionMap = []; - let modulePathList = []; let i = moduleSrc.length; while (i--) { this.addModuleSrcDir(moduleSrc[i]); @@ -156,6 +155,15 @@

Source: ModuleResolver.js

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/docs/tutorial-injection.html b/docs/tutorial-injection.html index 5d550a6..426f2e4 100644 --- a/docs/tutorial-injection.html +++ b/docs/tutorial-injection.html @@ -97,6 +97,7 @@

example

So lets look at it in action: // now you got your bike with injected wheels, which got the size information injected

circular dependency

circular depencencies will issue a warning in the console and the injected argument will be null.

prototype inheritance

cdi can work with prototype inheritance and will also resolve dependencies in parent prototypes. For more details visit 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.

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 () {