Skip to content

Commit

Permalink
Update transformer to handle values like Coupe/ Convertible
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchernchong committed Dec 21, 2024
1 parent 553d789 commit 34d7bf5
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/utils/processCSV.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,29 @@ export const processCSV = async (filePath: string) => {
dynamicTyping: true,
skipEmptyLines: true,
transform: (value, field) => {
const trimmedValue = value.trim();

// Handle empty number field
if (field === "number" && value === "") {
if (field === "number" && trimmedValue === "") {
return 0;
}

// Clean up make field
if (field === "make") {
return value.trim().replace(/\./g, "");
return trimmedValue.replace(/\./g, "");
}

// Clean up vehicle_type field
if (field === "vehicle_type") {
return trimmedValue.replace(/\s*\/\s*/g, "/");
}

// Handle numeric values with commas
if (/\d+,\d+/.test(value)) {
return Number.parseInt(value.replace(/,/g, ""), 10);
if (/\d+,\d+/.test(trimmedValue)) {
return Number.parseInt(trimmedValue.replace(/,/g, ""), 10);
}

return value;
return trimmedValue;
},
});

Expand Down

0 comments on commit 34d7bf5

Please sign in to comment.