@rjsf/utils
Version:
Utility functions for @rjsf/core
16 lines (15 loc) • 773 B
TypeScript
import type { OptionValueFormat } from './types.js';
/** Encodes an enum option value into a string for a DOM value attribute.
*
* When `format` is `'realValue'`, primitive values are converted via `String()`.
* Non-primitive values (objects, arrays) fall back to the index since
* `String()` would produce `"[object Object]"`.
*
* When `format` is `'indexed'` (the default), returns the index as a string.
*
* @param value - The typed enum value
* @param index - The option's position in the enumOptions array
* @param [format='indexed'] - How to encode the value for the DOM attribute
* @returns The string to use as the DOM value attribute
*/
export default function enumOptionValueEncoder(value: unknown, index: number, format?: OptionValueFormat): string;