UNPKG

extension-methods

Version:

This library allows you to create extension methods for a given object the fatest way

31 lines (30 loc) 1.78 kB
export interface ProxyReference { [key: string]: any; } export interface Extender<_Extension extends ProxyReference> { get<T extends object>(target: T, name: string, proxy: T): any; } export interface FunctionCook { <T extends object>(value: Function, target: T, proxy: T): Function; } export declare function defaultCookFunction<T extends object>(value: Function, target: T): Function; export declare type PriorityOptions = 'extender' | 'object'; /** * Returns an instance of Extender<P> to be used to extend objects * @typeparam P Type of the ProxyReference * @param proxyReference The ProxyReference from where the extension method will be retrieved * @param cookFunction a function to prepare functions to be returned. By default, all functions returns bound with target * @param priority defines wether object will have priority in method choosing: target object (default) or the extender */ declare function getExtender<P extends ProxyReference>(proxyReference: P, cookFunction?: FunctionCook, priority?: PriorityOptions): Extender<P>; export declare type ExtendedObject<RealObject, Extension> = Extension & RealObject; /** * @typeparam RealObject the type of the object referenced * @typeparam Extension the type of Extender * @param obj the object to be extended * @param extender the Extender instance */ declare function extend<RealObject extends object, Extension extends object>(obj: RealObject, extender: Extender<Extension>): ExtendedObject<RealObject, Extension>; declare type ClassRef<T extends object> = new (...args: any[]) => T; declare function extendClass<T extends object, ClassType extends ClassRef<T>, Extension extends object>(classRef: ClassType, extender: Extender<Extension>): ClassType; export { extend, extendClass, getExtender };