@rjsf/utils
Version:
Utility functions for @rjsf/core
18 lines (17 loc) • 1.07 kB
TypeScript
import type { EnumOptionsType, OptionValueFormat, StrictRJSFSchema, RJSFSchema } from './types.js';
/** Decodes a string from a DOM value attribute back to a typed enum value.
*
* When `format` is `'realValue'`, does a reverse lookup: finds the enum option
* whose `String(value)` matches the input string and returns the original typed value.
* For object/array values that were encoded as indices, falls back to index resolution.
*
* When `format` is `'indexed'` (the default), uses index-based resolution via
* `enumOptionsValueForIndex`.
*
* @param value - The string value(s) from the DOM
* @param enumOptions - The available enum options
* @param [format='indexed'] - How the values were encoded on the DOM
* @param emptyValue - The value to return for empty/missing selections
* @returns The original typed enum value(s)
*/
export default function enumOptionValueDecoder<S extends StrictRJSFSchema = RJSFSchema>(value: string | string[], enumOptions: EnumOptionsType<S>[] | undefined, format?: OptionValueFormat, emptyValue?: unknown): unknown;