npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@avaelus/super-project-utils

v1.1.5

Published

Shared utility library

Downloads

15

Readme

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.