@bemedev/decompose
Version:
Decompose object and so more
23 lines • 1.41 kB
TypeScript
import { DEFAULT_OPTIONS } from './constants';
import type { Decompose, DecomposeOptions, Ru } from '../types.types';
import type { NotUndefined } from '@bemedev/types/lib/types/commons.types';
export type GetByKey_F = <const T extends Ru, const K extends keyof Decompose<T, typeof DEFAULT_OPTIONS>>(obj: T, key: Extract<K, string>) => Decompose<T, typeof DEFAULT_OPTIONS>[K];
export type GetByKeyDefined_F = <const T extends Ru, const K extends keyof Decompose<T, typeof DEFAULT_OPTIONS>>(obj: T, key: Extract<K, string>) => NotUndefined<Decompose<T, typeof DEFAULT_OPTIONS>[K]>;
export type GetByKeyOption_F = <const O extends DecomposeOptions = typeof DEFAULT_OPTIONS>(val: O) => <const T extends Ru, const K extends keyof Decompose<T, O>>(obj: T, key: Extract<K, string>) => Decompose<T, O>[K];
export interface GetByKey {
(obj: any, key: string): any;
low: (obj: any, key: string) => any;
typed: GetByKey_F;
defined: GetByKeyDefined_F;
options: GetByKeyOption_F;
}
/**
* Retrieves a value from an object by a specified key.
* @param obj The object to retrieve the value from
* @param key The key to retrieve the value for, can be a nested key (e.g. 'a.b.c')
* @returns The value associated with the specified key in the object
*
* @see {@linkcode Decompose} for more details on object decomposition.
*/
export declare const getByKey: GetByKey;
//# sourceMappingURL=get.d.ts.map