@altostra/core
Version:
Core library for shared types and logic
14 lines (13 loc) • 958 B
TypeScript
import type { AnyFunction } from "../common/Types";
import type { Dict, Key } from "./Common";
export declare function functionsRecord<TValue extends AnyFunction, TKey extends Key = string>(defaultFunc: TValue, defaults?: Dict<TValue, TKey>): Record<TKey, TValue>;
/**
* Wraps an object with a proxy that returns a provided default whenever a missing key is accessed.
* @param defaultValue A value or function to return a value from
* the new proxy if no value is defined in the `default` object.
* @param defaults The object which you want to proxy.
* @returns A new proxy object with a handler that checks the value in
* the `defaults` object by the key and if it is not defined than sets the value to `defaultValue`,
* otherwise returns the value from the `defaults` object.
*/
export declare function record<TValue, TKey extends Key = string>(defaultValue: TValue | ((key: TKey) => TValue), defaults?: Dict<TValue, TKey>): Record<TKey, TValue>;