@rjsf/utils
Version:
Utility functions for @rjsf/core
37 lines (36 loc) • 2.62 kB
TypeScript
import type { Experimental_CustomMergeAllOf, FormContextType, PathSchema, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types.js';
/** Returns the `formData` with only the elements specified in the `fields` list
*
* @param formData - The data for the `Form`
* @param fields - The fields to keep while filtering
* @deprecated - To be removed as an exported `@rjsf/utils` function in a future release
*/
export declare function getUsedFormData<T = any>(formData: T | undefined, fields: string[]): T | undefined;
/** Returns the list of field names from inspecting the `pathSchema` as well as using the `formData`
*
* @param pathSchema - The `PathSchema` object for the form
* @param [formData] - The form data to use while checking for empty objects/arrays
* @deprecated - To be removed as an exported `@rjsf/utils` function in a future release
*/
export declare function getFieldNames<T = any>(pathSchema: PathSchema<T>, formData?: T): string[][];
/** Returns true when a form value is considered empty: null/undefined/'', an empty array, or a plain
* object whose every own value is itself empty (recursive). Scalars like `0` and `false` are not empty.
*
* @param value - The value to check
* @returns - True if the value is considered empty, false otherwise
*/
export declare function isValueEmpty(value: unknown): boolean;
/** A recursive, schema-driven filter that walks `schema` and `formData` in lockstep, keeping only
* values that are described by the schema. Handles `$ref`, `allOf`, `anyOf`, `oneOf`, `if/then/else`,
* `patternProperties`, `additionalProperties`, `propertyNames`, and `dependencies`. Optional object
* properties whose schema-filtered content is entirely empty (per `isValueEmpty`) are pruned; required
* properties and scalar values are always kept when schema-defined.
*
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
* @param schema - The schema for which to filter the formData
* @param [rootSchema] - The root schema, used primarily to look up `$ref`s
* @param [formData] - The data for the `Form`
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
* @returns - The `formData` after omitting extra data, or `undefined` when `formData` is undefined
*/
export default function omitExtraData<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema?: S, formData?: T, experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): T | undefined;