nhb-toolbox
Version:
A versatile collection of smart, efficient, and reusable utility functions and classes for everyday development needs.
19 lines • 1.16 kB
TypeScript
import type { ParsedFormData, SerializedForm } from './types';
/**
* * Serialize form data into an object or a query string.
* - **N.B.** Be cautious when using this in SSR (Server-Side Rendering) environments (such as `Next.js` Server Components), as it may not work as expected.
*
* @param form - The form element to serialize.
* @param toQueryString - Whether to return the result as a query string. If false, returns an object.
* @returns The serialized form data as an object or query string.
*/
export declare function serializeForm<T extends boolean = false>(form: HTMLFormElement, toQueryString?: T): SerializedForm<T>;
/**
* * Parse form data from a `FormData` object or query string into a structured object format.
*
* @param data - The `FormData` object or query string to parse.
* @param parsePrimitives - Whether to parse string values into primitive types (e.g., boolean, number, array, object). Defaults to `true`.
* @returns The parsed form data as an object.
*/
export declare function parseFormData<T extends FormData | string>(data: T, parsePrimitives?: boolean): ParsedFormData<T>;
//# sourceMappingURL=transform.d.ts.map