UNPKG

cmpstr

Version:

CmpStr is a lightweight, fast and well performing package for calculating string similarity

58 lines (57 loc) 2.49 kB
/** * Registry Utility * src/utils/Registry.ts * * This module provides a Registry function that allows for registering, * removing, checking, getting, and listing class constructors. * * It is designed to manage class extensions, ensuring that all registered * classes extend a specified base constructor. * * @module Utils/Registry * @author Paul Köhler (komed3) * @license MIT */ import type { RegistryService, RegistryConstructor } from './Types'; /** * Global registry object to hold multiple registries. * Each registry is keyed by a string identifier. * * @type {Record<string, RegistryService<any>>} */ export declare const registry: Record<string, RegistryService<any>>; /** * Factory object to hold factory functions for creating instances. * This is used to create instances of registered classes. * * @type {Record<string, ( cls: string, ...args: any[] ) => InstanceType<any>>} */ export declare const factory: Record<string, (cls: string, ...args: any[]) => InstanceType<any>>; /** * Registry function to create a service for managing class constructors. * * @param {string} reg - The name of the registry * @param {RegistryConstructor<T>} ctor - The base constructor that all registered classes must extend * @returns {RegistryService<T>} - An object with methods to register, remove, check, get, and list classes * @throws {Error} If the registry already exists (overwriting is forbidden) */ export declare function Registry<T>(reg: string, ctor: RegistryConstructor<T>): RegistryService<T>; /** * Resolve a class constructor from a specific registry. * * @param {string} reg - The name of the registry * @param {T|string} cls - The class itself or name of the class to resolve * @returns {T|undefined} - The class constructor if found, otherwise undefined * @throws {ReferenceError} If the registry does not exist */ export declare function resolveCls<T extends RegistryConstructor<any>>(reg: string, cls: T | string): T; /** * Create an instance of a class from a specific registry. * * @param {string} reg - The name of the registry * @param {T|string} cls - The class itself or name of the class to instantiate * @param {...any} args - Arguments to pass to the class constructor * @returns {T} - An instance of the class * @throws {Error} If the class cannot be instantiated */ export declare function createFromRegistry<T extends RegistryConstructor<any>>(reg: string, cls: T | string, ...args: any[]): InstanceType<T>;