UNPKG

@conform-to/react

Version:

Conform view adapter for react

68 lines 3.27 kB
import type { FormError } from '@conform-to/dom/future'; import type { StandardSchemaV1 } from './standard-schema'; import { ValidateHandler, ValidateResult } from './types'; export declare function isUndefined(value: unknown): value is undefined; export declare function isString(value: unknown): value is string; export declare function isNumber(value: unknown): value is number; export declare function isNullable<T>(value: unknown, typeGuard: (value: unknown) => value is T): value is T | null; export declare function isOptional<T>(value: unknown, typeGuard: (value: unknown) => value is T): value is T | undefined; export declare function getArrayAtPath<Type>(formValue: Record<string, Type> | null, name: string): Array<Type>; /** * Immutably updates a value at the specified path. * Empty path replaces the entire object. */ export declare function updateValueAtPath<Data>(data: Record<string, Data>, name: string, value: Data | Record<string, Data>): Record<string, Data>; /** * Creates a function that updates array indices in field paths. * Returns null to remove fields, or updated path with new index. */ export declare function createPathIndexUpdater(listName: string, update: (index: number) => number | null): (name: string) => string | null; /** * Returns null if error object has no actual error messages, * otherwise returns the error as-is. */ export declare function normalizeFormError<ErrorShape>(error: FormError<ErrorShape> | null): FormError<ErrorShape> | null; export declare function normalizeValidateResult<ErrorShape, Value>(result: ValidateResult<ErrorShape, Value>): { error: FormError<ErrorShape> | null; value?: Value; }; /** * Handles different validation result formats: * - Promise: async validation only * - Array: [syncResult, asyncPromise] * - Object: sync validation only */ export declare function resolveValidateResult<ErrorShape, Value>(result: ReturnType<ValidateHandler<ErrorShape, Value>>): { syncResult: { error: FormError<ErrorShape> | null; value?: Value | undefined; } | undefined; asyncResult: Promise<{ error: FormError<ErrorShape> | null; value?: Value | undefined; }> | undefined; }; export declare function resolveStandardSchemaResult<Value>(result: StandardSchemaV1.Result<Value>): { error: FormError<string> | null; value?: Value; }; /** * Create a copy of the object with the updated properties if there is any change */ export declare function merge<Obj extends Record<string, any>>(obj: Obj, update: Partial<Obj>): Obj; /** * Transforms object keys using a mapping function. * Keys mapped to null are filtered out. */ export declare function transformKeys<Value>(obj: Record<string, Value>, fn: (key: string) => string | null): Record<string, Value>; /** * Appends item to array only if not already present. * Returns original array if item exists, new array if added. */ export declare function appendUniqueItem<Item>(list: Array<Item>, item: Item): Item[]; /** * Maps over array and filters out null results. */ export declare function compactMap<Item>(list: Array<NonNullable<Item>>, fn: (value: Item) => Item | null): Array<Item>; export declare function generateUniqueKey(): string; //# sourceMappingURL=util.d.ts.map