(value: unknown, node: FormKitNode)
| 27 | } |
| 28 | |
| 29 | function omitFileValues(value: unknown, node: FormKitNode): unknown { |
| 30 | if (!value || typeof value !== 'object') return value |
| 31 | const sanitized: Record<string | number, unknown> | unknown[] = Array.isArray( |
| 32 | value |
| 33 | ) |
| 34 | ? [...value] |
| 35 | : { ...(value as Record<string | number, unknown>) } |
| 36 | node.children.forEach((child) => { |
| 37 | if (isPlaceholder(child)) return |
| 38 | const key = child.name as string | number |
| 39 | if (child.props.type === 'file') { |
| 40 | if (Array.isArray(sanitized)) { |
| 41 | // Deleting from an array would leave a hole that serializes to null — |
| 42 | // store the file input’s empty value to keep list positions intact. |
| 43 | sanitized[key as number] = [] |
| 44 | } else { |
| 45 | delete sanitized[key as keyof typeof sanitized] |
| 46 | } |
| 47 | return |
| 48 | } |
| 49 | const childValue = (value as Record<string | number, unknown>)[key] |
| 50 | if (childValue !== undefined) { |
| 51 | ;(sanitized as Record<string | number, unknown>)[key] = omitFileValues( |
| 52 | childValue, |
| 53 | child |
| 54 | ) |
| 55 | } |
| 56 | }) |
| 57 | return sanitized |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Creates a new save-to-local-storage plugin. |
no test coverage detected