MODULES Uize.Util.ModuleNaming
- Contents
- 1. Introduction
-
2. Static Methods
- 2.1. Uize.Util.ModuleNaming.getModuleNameFromTestModuleName
- 2.2. Uize.Util.ModuleNaming.getNamespace
- 2.3. Uize.Util.ModuleNaming.getTestModuleName
- 2.4. Uize.Util.ModuleNaming.isExtensionModule
- 2.5. Uize.Util.ModuleNaming.isMixinModule
- 2.6. Uize.Util.ModuleNaming.isModuleName
- 2.7. Uize.Util.ModuleNaming.isTestModule
- 2.8. Uize.Util.ModuleNaming.visualSamplerModuleNameFromWidgetClass
- 2.9. Uize.Util.ModuleNaming.visualTestsModuleNameFromWidgetClass
- 3. Static Properties
1. Introduction
The Uize.Util.ModuleNaming
package provides utility methods to help with following the various UIZE conventions for module naming.
DEVELOPERS: Chris van Rensburg
1.1. In a Nutshell
The UIZE JavaScript Framework follows certain conventions when it comes to the naming of modules, and these conventions are observed by various build scripts provided as part of the framework.
The Uize.Util.ModuleNaming
module provides a set of utility methods to make it easier for various build scripts and development tools to follow these conventions.
1.1.1. Module Naming
A string value is considered to be a valid module name if it contains a period-delimited list of one or more JavaScript identifier names.
This means that, in order for a string to be considered a valid module name, it must be matched by the following regular expression...
REGULAR EXPRESSION
/^([a-zA-Z_$][a-zA-Z_$0-9]*)(\.[a-zA-Z_$][a-zA-Z_$0-9]*)*$/
The table below lists some examples of module names to illustrate how the basic convention for module naming covers a variety of different types of modules...
Examples of Module Names | ||
Module Name | Module Type | Notes |
MyNamespace | Namespace Module | top level namespace |
MyNamespace.MySubNamespace | Namespace Module | deeper level namespace |
MyNamespace.MyPackage | Package Module | capital first letter is recommended but not required |
MyNamespace.MyClass | Class Module | capital first letter is recommended but not required |
MyNamespace.xMyExtension | Extension Module | prefixed with lowercase "x" by convention |
MyNamespace.mMyMixin | Mixin Module | prefixed with lowercase "m" by convention |
MyNamespace.Test.MyNamespace.MyClass | Test Module | path under MyNamespace.Test is path of module that is tested by the test module |
As you will notice, additional conventions exist for denoting certain specific types of modules, such as extension modules (see Extension Module Naming), mixin modules (see Mixin Module Naming), and test modules (see Test Module Naming).
The Uize.Util.ModuleNaming.isModuleName
static method can be used to test if a specified string is a module name, according to the aforementioned convention.
1.1.2. Top Level Namespaces
A string is considered to be a top level namespace if it is a valid module name that contains only one segment.
EXAMPLES
Uize MyNamespace
The Uize.Util.ModuleNaming.getNamespace
static method can be used to obtain the top level namespace from a specified module name.
EXAMPLES
Module Name | Top Level Namespace |
Uize | Uize |
Uize.Color | Uize |
Uize.Widgets.Slider.Widget | Uize |
MyNamespace.MyClass.MySubClass | MyNamespace |
1.1.3. Extension Module Naming
A string is considered to be an extension module name if it is a valid module name that has more than one segment, and where the last segment starts with a lowercase "x" and is followed by a capital letter.
Examples of Extension Module Names | |
Module Being Extended | Extension Module Name |
Uize.Color | Uize.Color.xSvgColors |
Uize.Fade | Uize.Fade.xFactory |
Uize.Fx | Uize.Fx.xShadows |
The Uize.Util.ModuleNaming.isExtensionModule
static method can be used to test if a specified string is an extension module name.
1.1.4. Mixin Module Naming
A string is considered to be a mixin module name if it is a valid module name that has more than one segment, and where the last segment starts with a lowercase "m" and is followed by a capital letter.
EXAMPLE
MyNamespace.MyClass.mMyMixin
The Uize.Util.ModuleNaming.isMixinModule
static method can be used to test if a specified string is a mixin module name.
1.1.5. Test Module Naming
A string is considered to be a test module name if it starts with a top level namespace, followed by the segment "Test", followed by a segment name that is identical to the top level namespace, followed by zero or more additional segments.
The methods of the Uize.Util.ModuleNaming
module follow the convention that the name for a test module is derived from the name of the module it is intended to test, by using the top level namespace for that module as a prefix, appending the path segment ".Test.", and then finally appending the name of the module being tested.
This naming convention is best illustrated by the following table of examples...
Examples of Test Module Names | |
Name of Module to Test | Name of Test Module |
Uize | Uize.Test.Uize |
Uize.Widget | Uize.Test.Uize.Widget |
MyNamespace.MyClass.MySubclass | MyNamespace.Test.MyNamespace.MyClass.MySubclass |
The following static methods are useful with respect to test module names...
Uize.Util.ModuleNaming.getModuleNameFromTestModuleName - determines the name of the module being tested by a specified test module |
|
Uize.Util.ModuleNaming.getTestModuleName - determines the name that should be used for the test module for a specified module |
|
Uize.Util.ModuleNaming.isTestModule - determines if the specified module name is a test module name |
1.2. Examples
There are no dedicated showcase example pages for the Uize.Util.ModuleNaming
module.
SEARCH FOR EXAMPLES
Use the link below to search for example pages on the UIZE Web site that reference the Uize.Util.ModuleNaming
module...
SEARCH
1.3. Implementation Info
The Uize.Util.ModuleNaming
module defines the Uize.Util.ModuleNaming
package under the Uize.Util
namespace.
1.3.1. Features Introduced in This Module
The features listed in this section have been introduced in this module.
STATIC METHODS
Uize.Util.ModuleNaming.getModuleNameFromTestModuleName
| Uize.Util.ModuleNaming.getNamespace
| Uize.Util.ModuleNaming.getTestModuleName
| Uize.Util.ModuleNaming.isExtensionModule
| Uize.Util.ModuleNaming.isMixinModule
| Uize.Util.ModuleNaming.isModuleName
| Uize.Util.ModuleNaming.isTestModule
| Uize.Util.ModuleNaming.visualSamplerModuleNameFromWidgetClass
| Uize.Util.ModuleNaming.visualTestsModuleNameFromWidgetClass
STATIC PROPERTIES
Uize.Util.ModuleNaming.moduleName
| Uize.Util.ModuleNaming.pathToResources
1.3.2. Features Overridden in This Module
No features have been overridden in this module.
1.3.3. Features Inherited From Other Modules
This module has no inherited features.
1.3.4. Modules Directly Under This Namespace
There are no modules directly under this namespace.
1.3.5. Unit Tests
The Uize.Util.ModuleNaming
module is unit tested by the Uize.Test.Uize.Util.ModuleNaming
test module.
2. Static Methods
2.1. Uize.Util.ModuleNaming.getModuleNameFromTestModuleName
Returns a string, representing the name of the module that is tested by the specified test module.
SYNTAX
moduleNameSTR = Uize.Util.ModuleNaming.getModuleNameFromTestModuleName (testModuleNameSTR);
This method follows the convention for test module naming. If, according to this convention, the specified module is a test module, then the name for the module that would be tested by the test module is derived from the name of the test module. If, on the other hand, the specified module is not a test module, then the specified module name is returned as is.
EXAMPLES
Uize.Util.ModuleNaming.getModuleNameFromTestModuleName ('Uize.Test.Uize'); // returns 'Uize' Uize.Util.ModuleNaming.getModuleNameFromTestModuleName ('Uize'); // returns 'Uize'
NOTES
compare to the companion Uize.Util.ModuleNaming.getTestModuleName static method |
|
see also the related Uize.Util.ModuleNaming.isTestModule static method |
IMPLEMENTATION INFO
this feature was introduced in this module |
2.2. Uize.Util.ModuleNaming.getNamespace
Returns a string, representing the top level namespace for the specified module.
SYNTAX
topLevelNamespaceSTR = Uize.Util.ModuleNaming.getNamespace (moduleNameSTR);
EXAMPLES
Uize.Util.ModuleNaming.getNamespace ('Uize'); // returns 'Uize' Uize.Util.ModuleNaming.getNamespace ('Uize.Widgets.Log.Widget'); // returns 'Uize' Uize.Util.ModuleNaming.getNamespace ('MyNamespace.MyClass'); // returns 'MyNamespace'
IMPLEMENTATION INFO
this feature was introduced in this module |
2.3. Uize.Util.ModuleNaming.getTestModuleName
Returns a string, representing the name of the corresponding test module for the specified module.
SYNTAX
testModuleNameSTR = Uize.Util.ModuleNaming.getTestModuleName (moduleNameSTR);
This method follows the convention for test module naming. If, according to this convention, the specified module is a non-test module, then the name of that module's corresponding test module is derived from the module's name according to the naming convention. If, on the other hand, the specified module is actually a test module, then the specified test module name is returned as is.
EXAMPLES
Uize.Util.ModuleNaming.getTestModuleName ('Uize'); // returns 'Uize.Test.Uize' Uize.Util.ModuleNaming.getTestModuleName ('Uize.Test.Uize'); // returns 'Uize.Test.Uize'
NOTES
compare to the companion Uize.Util.ModuleNaming.getModuleNameFromTestModuleName static method |
|
see also the related Uize.Util.ModuleNaming.isTestModule static method |
IMPLEMENTATION INFO
this feature was introduced in this module |
2.4. Uize.Util.ModuleNaming.isExtensionModule
Returns a boolean, indicating whether or not the specified string is an extension module name, according to the convention for extension module naming.
SYNTAX
isExtensionModuleBOOL = Uize.Util.ModuleNaming.isExtensionModule (moduleNameSTR);
EXAMPLES
Uize.Util.ModuleNaming.isExtensionModule ('MyNamespace.MyClass.xMyExtension'); // returns true Uize.Util.ModuleNaming.isExtensionModule ('MyNamespace'); // returns false Uize.Util.ModuleNaming.isExtensionModule ('MyNamespace.MyClass'); // returns false Uize.Util.ModuleNaming.isExtensionModule ('MyNamespace.MyClass.xFoo.Bar'); // returns false Uize.Util.ModuleNaming.isExtensionModule ('MyNamespace.MyClass.xfoo'); // returns false Uize.Util.ModuleNaming.isExtensionModule ('MyNamespace.MyClass.x_Foo'); // returns false Uize.Util.ModuleNaming.isExtensionModule ('MyNamespace.MyClass.x$Foo'); // returns false Uize.Util.ModuleNaming.isExtensionModule ('MyNamespace.MyClass.x4Foo'); // returns false Uize.Util.ModuleNaming.isExtensionModule ('MyNamespace.MyClass.mMyMixin'); // returns false
NOTES
compare to the Uize.Util.ModuleNaming.isTestModule and Uize.Util.ModuleNaming.isMixinModule static methods |
IMPLEMENTATION INFO
this feature was introduced in this module |
2.5. Uize.Util.ModuleNaming.isMixinModule
Returns a boolean, indicating whether or not the specified string is a mixin module name, according to the convention for mixin module naming.
SYNTAX
isMixinModuleBOOL = Uize.Util.ModuleNaming.isMixinModule (moduleNameSTR);
EXAMPLES
Uize.Util.ModuleNaming.isMixinModule ('MyNamespace.MyClass.mMyMixin'); // returns true Uize.Util.ModuleNaming.isMixinModule ('MyNamespace'); // returns false Uize.Util.ModuleNaming.isMixinModule ('MyNamespace.MyClass'); // returns false Uize.Util.ModuleNaming.isMixinModule ('MyNamespace.MyClass.mFoo.Bar'); // returns false Uize.Util.ModuleNaming.isMixinModule ('MyNamespace.MyClass.mfoo'); // returns false Uize.Util.ModuleNaming.isMixinModule ('MyNamespace.MyClass.m_Foo'); // returns false Uize.Util.ModuleNaming.isMixinModule ('MyNamespace.MyClass.m$Foo'); // returns false Uize.Util.ModuleNaming.isMixinModule ('MyNamespace.MyClass.m4Foo'); // returns false Uize.Util.ModuleNaming.isMixinModule ('MyNamespace.MyClass.xMyExtension'); // returns false
NOTES
compare to the Uize.Util.ModuleNaming.isTestModule and Uize.Util.ModuleNaming.isExtensionModule static methods |
IMPLEMENTATION INFO
this feature was introduced in this module |
2.6. Uize.Util.ModuleNaming.isModuleName
Returns a boolean, indicating whether or not the specified string is a valid module name.
SYNTAX
isModuleNameBOOL = Uize.Util.ModuleNaming.isModuleName (moduleNameSTR);
EXAMPLES
Uize.Util.ModuleNaming.isModuleName ('Uize'); // returns true Uize.Util.ModuleNaming.isModuleName ('Uize.Widgets.Button'); // returns true Uize.Util.ModuleNaming.isModuleName ('A.B.C'); // returns true Uize.Util.ModuleNaming.isModuleName ('A123456789.B123456789'); // returns true Uize.Util.ModuleNaming.isModuleName ('$Name$Space$.$My$Module$'); // returns true Uize.Util.ModuleNaming.isModuleName ('_Name_Space_._My_Module_'); // returns true Uize.Util.ModuleNaming.isModuleName ('Namespace.'); // returns false Uize.Util.ModuleNaming.isModuleName ('.MyModule'); // returns false Uize.Util.ModuleNaming.isModuleName ('Namespace..MyModule') // returns false Uize.Util.ModuleNaming.isModuleName ('Name-Space.MyModule'); // returns false Uize.Util.ModuleNaming.isModuleName ('Namespace.My-Module'); // returns false Uize.Util.ModuleNaming.isModuleName ('1Namespace.MyModule'); // returns false Uize.Util.ModuleNaming.isModuleName ('Namespace.1MyModule'); // returns false
IMPLEMENTATION INFO
this feature was introduced in this module |
2.7. Uize.Util.ModuleNaming.isTestModule
Returns a boolean, indicating whether or not the specified string is a test module name, according to the convention for test module naming.
SYNTAX
isTestModuleBOOL = Uize.Util.ModuleNaming.isTestModule (moduleNameSTR);
EXAMPLES
Uize.Util.ModuleNaming.isTestModule ('Uize'); // returns false Uize.Util.ModuleNaming.isTestModule ('Uize.Widget'); // returns false Uize.Util.ModuleNaming.isTestModule ('Uize.Test'); // returns false Uize.Util.ModuleNaming.isTestModule ('Uize.Test.Uize'); // returns true Uize.Util.ModuleNaming.isTestModule ('Uize.Test.Uize.Widget'); // returns true Uize.Util.ModuleNaming.isTestModule ('MyNamespace.MyClass'); // returns false Uize.Util.ModuleNaming.isTestModule ('MyNamespace.Test.MyNamespace.MyClass'); // returns true
NOTES
see also the related Uize.Util.ModuleNaming.getTestModuleName and Uize.Util.ModuleNaming.getModuleNameFromTestModuleName static methods |
|
compare to the Uize.Util.ModuleNaming.isExtensionModule and Uize.Util.ModuleNaming.isMixinModule static methods |
IMPLEMENTATION INFO
this feature was introduced in this module |
2.8. Uize.Util.ModuleNaming.visualSamplerModuleNameFromWidgetClass
Returns a string, representing the name of the corresponding visual sampler module for the specified widget class name.
SYNTAX
visualSamplerModuleNameSTR = Uize.Util.ModuleNaming.visualSamplerModuleNameFromWidgetClass ( widgetClassNameSTR );
EXAMPLE
Uize.Util.ModuleNaming.visualSamplerModuleNameFromWidgetClass ('Uize.Widgets.Log.Widget');
RESULT
'Uize.Widgets.Log.VisualSampler'
NOTES
see also the companion Uize.Util.ModuleNaming.visualTestsModuleNameFromWidgetClass static method |
IMPLEMENTATION INFO
this feature was introduced in this module |
2.9. Uize.Util.ModuleNaming.visualTestsModuleNameFromWidgetClass
Returns a string, representing the name of the corresponding visual tests module for the specified widget class name.
SYNTAX
visualTestsModuleNameSTR = Uize.Util.ModuleNaming.visualTestsModuleNameFromWidgetClass ( widgetClassNameSTR );
EXAMPLE
Uize.Util.ModuleNaming.visualTestsModuleNameFromWidgetClass ('Uize.Widgets.Log.Widget');
RESULT
'Uize.Widgets.Log.VisualTests'
NOTES
see also the companion Uize.Util.ModuleNaming.visualSamplerModuleNameFromWidgetClass static method |
IMPLEMENTATION INFO
this feature was introduced in this module |