UNPKG

@zvenigora/ng-eval-core

Version:

An expression evaluator for Angular

43 lines (42 loc) 2.38 kB
import { Registry } from '../common'; import { EvalOptions } from '../eval'; export type BaseContext = Record<string | number | symbol, unknown>; export type Context = Registry<unknown, unknown> | BaseContext; export declare function isRegistryContext(context?: Context): boolean; /** * Converts a context object to a Context instance. * @param context - The context object to convert. * @param options - Optional evaluation options. * @returns The converted Context instance. */ export declare const fromContext: (context?: Context, options?: EvalOptions) => Context; /** * Retrieves the value associated with the specified key from the given context. * If the context is an instance of Registry, it uses the `get` method to retrieve the value. * If the context is an object, it accesses the value using the key as a property name. * If the context is neither an instance of Registry nor an object, it returns undefined. * * @param context The context from which to retrieve the value. * @param key The key associated with the value to retrieve. * @returns The value associated with the specified key, or undefined if not found. */ export declare const getContextValue: (context?: Context, key?: unknown) => unknown; /** * Sets a value in the given context object. * If the context is an instance of Registry, the value is set using the key. * If the context is a plain object, the value is set using the key as a property name. * @param context - The context object. * @param key - The key or property name. * @param value - The value to be set. */ export declare const setContextValue: (context: Context, key: unknown, value: unknown) => void; /** * Retrieves the key from the given context object. * If the context is an instance of Registry, it searches for the key in a case-insensitive manner if specified. * If the context is an instance of Object, it uses the getKeyValue function to retrieve the key-value pair. * @param context - The context object. * @param key - The key to retrieve. * @param caseInsensitive - Specifies whether the search should be case-insensitive (only applicable for Registry instances). * @returns The retrieved key, or undefined if the key is not found. */ export declare const getContextKey: (context: Context, key: string | number | symbol, caseInsensitive: boolean) => string | number | symbol | undefined;