(fields: string[], collected: Record<string, string>, configSchema: PluginOptionSchema, initialValues: PluginOptionValues | undefined)
| 22 | * Exported for unit testing. |
| 23 | */ |
| 24 | export function buildFinalValues(fields: string[], collected: Record<string, string>, configSchema: PluginOptionSchema, initialValues: PluginOptionValues | undefined): PluginOptionValues { |
| 25 | const finalValues: PluginOptionValues = {}; |
| 26 | for (const fieldKey of fields) { |
| 27 | const schema = configSchema[fieldKey]; |
| 28 | const value = collected[fieldKey] ?? ''; |
| 29 | if (schema?.sensitive === true && value === '' && initialValues?.[fieldKey] !== undefined) { |
| 30 | continue; |
| 31 | } |
| 32 | if (schema?.type === 'number') { |
| 33 | // Number('') returns 0, not NaN — omit blank number inputs so |
| 34 | // validateUserConfig's required check actually catches them. |
| 35 | if (value.trim() === '') continue; |
| 36 | const num = Number(value); |
| 37 | finalValues[fieldKey] = Number.isNaN(num) ? value : num; |
| 38 | } else if (schema?.type === 'boolean') { |
| 39 | finalValues[fieldKey] = isEnvTruthy(value); |
| 40 | } else { |
| 41 | finalValues[fieldKey] = value; |
| 42 | } |
| 43 | } |
| 44 | return finalValues; |
| 45 | } |
| 46 | type Props = { |
| 47 | title: string; |
| 48 | subtitle: string; |
no test coverage detected