/
githubmirror
/
react-hook-form
Обзор
Документация
Войти
/
githubmirror
/
react-hook-form
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/utils/flatten.ts
31 строка
785 B
Jayesh Bhade
🐞 fix(flatten): preserve File and Blob values as leaf nodes (#13652)
09 авг 2026, 01:51
Не верифицирован
09 авг 2026, 01:51
01665bb
Код
Авторство
О чём код?
import type { FieldValues } from '../types'; import isDateObject from './isDateObject'; import { isObjectType } from './isObject'; const isFileLike = (value: unknown) => (typeof Blob !== 'undefined' && value instanceof Blob) || (typeof File !== 'undefined' && value instanceof File); export const flatten = (obj: FieldValues) => { const output: FieldValues = {}; for (const key of Object.keys(obj)) { if ( isObjectType(obj[key]) && obj[key] !== null && !isDateObject(obj[key]) && !isFileLike(obj[key]) ) { const nested = flatten(obj[key]); for (const nestedKey of Object.keys(nested)) { output[`${key}.${nestedKey}`] = nested[nestedKey]; } } else { output[key] = obj[key]; } } return output; };