@avaelus/super-project-utils
TypeScript icon, indicating that this package has built-in type declarations

1.1.5 • Public • Published

Documentation for Code Module

Introduction

This documentation describes a TypeScript module designed to facilitate mapping and configuration handling for routing configurations in a web application context. The module includes utility functions and classes.

Functions and Classes

1. mapValuesAsKeys
export function mapValuesAsKeys<
  T extends Record<string, string | { _: string }>,
  RequiredKeys extends keyof T
>(source: T): Record<string, keyof T & RequiredKeys> {
  // Function logic described in the implementation
}
  • Description: This function maps values of an object (source) to keys, handling both string values directly and objects with a _ property as keys.
  • Parameters:
    • source: An object where values can be strings or objects with a _ property.
  • Returns: A new object where keys are values from source and values are keys from source corresponding to those values.
  • Usage: Used in various parts of the module to convert configurations and blueprints into key-value mappings.
2. mapRouteToValue
export function mapRouteToValue(
  routes: Record<string, string | { _: string }>,
  replaceValue = ""
) {
  // Function logic described in the implementation
}
  • Description: This function maps routes to a specified replaceValue, based on the mappings generated by mapValuesAsKeys.
  • Parameters:
    • routes: An object where values can be strings or objects with a _ property.
    • replaceValue: Optional parameter to replace mapped values.
  • Returns: A cloned object with route values replaced by replaceValue.
  • Usage: Primarily used to generate configurations or mappings with default values.
3. routeEnum
export function routeEnum<T>(obj: T) {
  // Function logic described in the implementation
}
  • Description: This function flattens nested objects and arrays into an enumeration of key-value pairs.
  • Parameters:
    • obj: The object or array to be flattened.
  • Returns: An object where keys are string representations of values found within obj.
  • Usage: Used to simplify nested structures into a flat list of values, often used in configuration mapping.
4. RoutesConfig Class
export class RoutesConfig<r, config> {
  // Class implementation described in the provided code
}
  • Description: This class generates a configuration map (configMap) based on provided route blueprints (routes).
  • Properties:
    • routes: Contains the route blueprints used to generate the configuration.
    • configMap: Final mapping of routes to their configurations.
    • rEnum: Enumerated values derived from routes.
  • Methods:
    • constructor: Initializes the class and populates configMap based on routes and optional configuration (c).
    • for: Retrieves configuration for a specified route path (path).
    • hydrate: Replaces placeholders in a route path with corresponding parameters.
  • Usage: Essential for managing and retrieving configurations based on predefined blueprints.
5. RoutesConfigFromBluePrints Class
export class RoutesConfigFromBluePrints<bp, config> {
  // Class implementation described in the provided code
}
  • Description: This class extends RoutesConfig and initializes it using blueprint configurations (blueprints).
  • Properties:
    • blueprints: Blueprint configurations for routes.
    • routes: Generated routes from mMap(blueprints).
    • configMap: Configuration mapping similar to RoutesConfig.
  • Methods:
    • constructor: Initializes RoutesConfig using blueprint configurations.
  • Usage: Simplifies the setup of RoutesConfig instances using predefined blueprints.

Testing

  • Framework: The module is tested using chai and mocha, ensuring functionalities like routeEnum and mapValuesAsKeys behave as expected under different scenarios.
  • Purpose: Tests validate correct behavior across nested structures, empty inputs, and mixed data types, ensuring reliability and accuracy in a TypeScript environment.

Conclusion

This documentation provides an overview of the module's functionalities, utility functions (mapValuesAsKeys, mapRouteToValue, routeEnum), and classes (RoutesConfig, RoutesConfigFromBluePrints). It outlines how each component contributes to handling routing configurations and mappings within a TypeScript application, ensuring clarity and ease of use for developers integrating the module.

Readme

Keywords

none

Package Sidebar

Install

npm i @avaelus/super-project-utils

Weekly Downloads

10

Version

1.1.5

License

SEE LICENSE IN license

Unpacked Size

62.1 kB

Total Files

47

Last publish

Collaborators

  • rorys0