```ts
/**
 * Parses a single line of CSV into its fields on commas. Handles quoted fields with embedded quotes.
 * @param line - The CSV line to parse.
 * @returns An array of fields.
 */
export function parseCsvLine(line: string): string[] {
    const result: string[] = [];
    let field = '';
    let inQuotes = false;

    for (let i = 0; i < line.length; i++) {
        if (line[i] === '"') {
            if (inQuotes) {
                // Check for doubled quote inside a quoted field
                if (i + 1 < line.length && line[i + 1] === '"') {
                    field += '"';
                    i++;
                } else {
                    throw new Error('Unquoted double quote');
                }
            } else {
                inQuotes = true;
            }
        } else if (line[i] === ',' && !inQuotes) {
            result.push(field.trim());
            field = '';
        } else {
            field += line[i];
        }
    }

    // Push the last field
    if (inQuotes) throw new Error('Unquoted double quote');
    result.push(field.trim());

    return result;
}
```