import-processor: Reworked comments for coerceCustomValue

This commit is contained in:
Andy Grunwald
2026-05-24 16:15:57 +02:00
parent 844be42151
commit 868bdee615
+11 -9
View File
@@ -221,21 +221,23 @@ function isValidEmail(email: string): boolean {
return emailRegex.test(email); return emailRegex.test(email);
} }
// `0` and `1` are intentionally absent: in custom columns they are far more // Values considered as boolean during import.
// often counts/ids/quantities than boolean flags, so they fall through to // Numbers (0, 1) are intentionally absent.
// numeric coercion below. The reserved `subscribed` column has its own
// parser above that still accepts `1`/`0` as booleans.
const BOOLEAN_TRUE = new Set(['true', 'yes']); const BOOLEAN_TRUE = new Set(['true', 'yes']);
const BOOLEAN_FALSE = new Set(['false', 'no']); const BOOLEAN_FALSE = new Set(['false', 'no']);
// Strict integer-or-decimal pattern. Rejects leading zeros (preserves IDs,
// zips, phone numbers), scientific notation, `+` prefix, and `.5` / `42.`. // Strict integer-or-decimal number detection pattern.
// Valid: 0, 42, -42, 3.14
// Rejected: 007, +42, 1.2.3, 1e5
const NUMERIC_RE = /^-?(0|[1-9]\d*)(\.\d+)?$/; const NUMERIC_RE = /^-?(0|[1-9]\d*)(\.\d+)?$/;
/** /**
* Coerce a raw CSV cell to its natural JSON primitive so post-import type * Coerces a raw string into its most natural primitive type: `boolean`,
* inference (ContactService.getAvailableFields) can detect booleans and * `number`, or `string`. Values that match neither are
* numbers on custom fields. Values that match neither recogniser are
* returned unchanged. * returned unchanged.
*
* @param value The raw string to coerce.
* @returns The coerced value as `boolean`, `number`, or `string`.
*/ */
export function coerceCustomValue(value: string): string | boolean | number { export function coerceCustomValue(value: string): string | boolean | number {
const trimmed = value.trim(); const trimmed = value.trim();