@orpc/openapi-client
Version:
<div align="center"> <image align="center" src="https://orpc.dev/logo.webp" width=280 alt="oRPC logo" /> </div>
55 lines (53 loc) • 1.62 kB
text/typescript
/**
* parse a form data with bracket notation
*
* @example
* ```ts
* const form = new FormData()
* form.append('a', '1')
* form.append('user[name]', 'John')
* form.append('user[age]', '20')
* form.append('user[friends][]', 'Bob')
* form.append('user[friends][]', 'Alice')
* form.append('user[friends][]', 'Charlie')
* form.append('thumb', new Blob(['hello']), 'thumb.png')
*
* parseFormData(form)
* // {
* // a: '1',
* // user: {
* // name: 'John',
* // age: '20',
* // friends: ['Bob', 'Alice', 'Charlie'],
* // },
* // thumb: form.get('thumb'),
* // }
* ```
*
* @see {@link https://orpc.dev/docs/openapi/bracket-notation Bracket Notation Docs}
*/
declare function parseFormData(form: FormData): any;
/**
* Get the issue message from the error.
*
* @param error - The error (can be anything) can contain `data.issues` (standard schema issues)
* @param path - The path of the field that has the issue follow [bracket notation](https://orpc.dev/docs/openapi/bracket-notation)
*
* @example
* ```tsx
* const { error, data, execute } = useServerAction(someAction)
*
* return <form action={(form) => execute(parseFormData(form))}>
* <input name="user[name]" type="text" />
* <p>{getIssueMessage(error, 'user[name]')}</p>
*
* <input name="user[age]" type="number" />
* <p>{getIssueMessage(error, 'user[age]')}</p>
*
* <input name="images[]" type="file" />
* <p>{getIssueMessage(error, 'images[]')}</p>
* </form>
*
*/
declare function getIssueMessage(error: unknown, path: string): string | undefined;
export { getIssueMessage, parseFormData };