java.lang.Object
com.liferay.frontend.js.loader.modules.extender.npm.ModuleNameUtil

public class ModuleNameUtil extends Object
Provides utility methods to manipulate module names.

There are several concepts that must be understood when using this class:

  • module name: the name of an NPM module deployed to the portal
    • Syntax: {module name}
    • Example: lib/index
  • module file name: the file name implementing an NPM module deployed to the portal
    • Syntax: {module file name}
    • Example: lib/index.js
  • package ID: the unique ID of an NPM package deployed to the portal
    • Syntax: {bundle ID}/{package name}@{package version}
    • Example: 625/isarray@1.0.0
  • module ID: the unique ID of an NPM module deployed to the portal
    • Syntax: {bundle ID}/{package name}@{package version}/{module name}
    • Example: 625/isarray@1.0.0/lib/index
  • Constructor Details

    • ModuleNameUtil

      public ModuleNameUtil()
  • Method Details

    • getDependencyPath

      public static String getDependencyPath(String moduleName, String dependency)
      Resolve dependency path based on current module's path.
      Parameters:
      moduleName - the module's name
      dependency - the dependency's name
      Returns:
      the full path of the dependency if it is local, the given dependency otherwise
    • getModuleId

      public static String getModuleId(JSPackage jsPackage, String moduleName)
      Returns the module ID with the NPM package and module name.
      Parameters:
      jsPackage - the NPM package
      moduleName - the module's name
      Returns:
      the module ID
    • getModuleResolvedId

      public static String getModuleResolvedId(JSPackage jsPackage, String moduleName)
      Returns the module resolved ID with the NPM package and module name.
      Parameters:
      jsPackage - the NPM package
      moduleName - the module's name
      Returns:
      the module ID
    • getPackageName

      public static String getPackageName(String moduleName)
      Returns the package name portion of a full module name.

      Example:

       
       getPackageName("isarray/lib/index") returns "isarray"
       
       

      Parameters:
      moduleName - the module's name
      Returns:
      the package name or null if the module name is a reserved or local one
    • getPackagePath

      public static String getPackagePath(String moduleName)
      Returns the path portion of a full module name.

      Example:

       
       getPackagePath("isarray/lib/index") returns "lib/index"
       
       

      Parameters:
      moduleName - the module's name
      Returns:
      the path portion of a full module name or null in any other case
    • isLocalModuleName

      public static boolean isLocalModuleName(String moduleName)
    • isReservedModuleName

      public static boolean isReservedModuleName(String moduleName)
    • toFileName

      public static String toFileName(String moduleName)
      Returns the file name implementing the module.
      Parameters:
      moduleName - the module's name
      Returns:
      the file name
    • toModuleName

      public static String toModuleName(String fileName)
      Returns the module's name given the file name implementing it.
      Parameters:
      fileName - the file name implementing the module
      Returns:
      the module's name