import { type Signal } from '@angular/core'; import { type Params } from '@angular/router'; import { DefaultValueOptions, InjectorOptions, ParseOptions, RequiredOptions } from 'ngxtension/shared'; type ParamsTransformFn = (params: Params) => ReadT; /** * The `ParamsOptions` type defines options for configuring the behavior of the `injectParams` function. * * @template ReadT - The expected type of the read value. * @template WriteT - The type of the value to be written. * @template DefaultValueT - The type of the default value. */ export type ParamsOptions = ParseOptions & DefaultValueOptions & InjectorOptions & RequiredOptions; /** * Base interface for parameter injection function overloads */ interface InjectParamsBase { /** * @returns A `Signal` that emits the entire parameters object. */ (): Signal; /** * @param {string} key - The name of the parameter to retrieve. * @returns {Signal} A `Signal` that emits the value of the specified parameter, or `null` if it's not present. */ (key: string): Signal; /** * @param {string} key - The name of the parameter to retrieve. * @param {ParamsOptions} options - Configuration options with required flag that ensures a non-null return. * @returns {Signal} A `Signal` that emits the value of the specified parameter. Throws an error if the parameter is not present. */ (key: string, options: ParamsOptions & { required: true; }): Signal; /** * @param {string} key - The name of the parameter to retrieve. * @param {ParamsOptions} options - Configuration options with both parse and required that ensures a non-null return. * @returns {Signal} A `Signal` that emits the parsed value. Throws an error if the parameter is not present. */ (key: string, options: ParamsOptions & { parse: (v: string) => ReadT; required: true; }): Signal; /** * @param {string} key - The name of the parameter to retrieve. * @param {ParamsOptions} options - Configuration options with both parse and defaultValue that ensures a non-null return. * @returns {Signal} A `Signal` that emits the parsed and transformed value, or the default value. */ (key: string, options: ParamsOptions & { parse: (v: string) => ReadT; defaultValue: ReadT; }): Signal; /** * @param {string} key - The name of the parameter to retrieve. * @param {ParamsOptions} options - Configuration options with defaultValue that ensures a non-null return. * @returns {Signal} A `Signal` that emits the transformed value of the specified parameter, or the default value. */ (key: string, options: ParamsOptions & { defaultValue: ReadT; }): Signal; /** * @param {string} key - The name of the parameter to retrieve. * @param {ParamsOptions} options - Configuration options with parse function that ensures a typed return. * @returns {Signal} A `Signal` that emits the parsed value of the specified parameter, or `null` if it's not present. */ (key: string, options: ParamsOptions & { parse: (v: string) => ReadT; }): Signal; /** * @param {string} key - The name of the parameter to retrieve. * @param {ParamsOptions} options - Optional configuration options for the parameter. * @returns {Signal} A `Signal` that emits the transformed value of the specified parameter, or `null` if it's not present. */ (key?: string, options?: ParamsOptions): Signal; /** * It retrieves the value of a parameter based on a custom transform function applied to the parameters object. * * @template ReadT - The expected type of the read value. * @param {ParamsTransformFn} fn - A transform function that takes the parameters object (`params: Params`) and returns the desired value. * @param options - Optional configuration options for the parameter. * @returns {Signal} A `Signal` that emits the transformed value based on the provided custom transform function. */ (fn: ParamsTransformFn, options?: InjectorOptions): Signal; (keyOrParamsTransform?: string | ((params: Params) => T), options?: ParamsOptions): Signal; } /** * Interface defining the global variant of injectParams */ type InjectParamsGlobal = InjectParamsBase; /** * Interface for the injectParams function with global property */ interface InjectParamsFn extends InjectParamsBase { /** * Global variant of `injectParams` that retrieves params from the leaf (deepest) `ActivatedRoute` in the router state tree. * This allows you to access all route parameters from the entire route hierarchy, including child routes, * regardless of where your component is positioned in the component tree. * * @example * // Get all params from route hierarchy * const params = injectParams.global(); * * @example * // Get specific param from route hierarchy * const childId = injectParams.global('childId'); * * @example * // Transform params from route hierarchy * const allKeys = injectParams.global((params) => Object.keys(params)); * * @example * // With parse option * const productId = injectParams.global('productId', { parse: numberAttribute }); */ global: InjectParamsGlobal; } /** * Injects the params from the current route. * If a key is provided, it will return the value of that key. * If a transform function is provided, it will return the result of that function. * Otherwise, it will return the entire params object. * * Type overloads are defined in the InjectParamsFn interface. * * @example * const userId = injectParams('id'); // returns the value of the 'id' param * const userId = injectParams(p => p['id'] as string); // same as above but can be used with a custom transform function * const params = injectParams(); // returns the entire params object * */ export declare const injectParams: InjectParamsFn; export {};