Files
AndreaSlopFotografie/web/src/lib/slideCounter.ts
T
SluijsensandClaude Sonnet 5.5 b03b18f58e Redesigns the testimonials section
A landscape photo overlaps a card with the shoot type, quote and names. The controls are two arrows with an X / Y counter; the dots are gone and nothing moves by itself. A change slides the whole slide horizontally, also on a swipe. Reviews get an optional imagePosition for the crop, normalised by normalizeImagePosition; slideCounter writes the counter. Both helpers have property tests next to example tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-06 01:24:14 +01:00

14 lines
738 B
TypeScript

// The visible counter under the testimonials, e.g. "2 / 3": the current
// review (counted from 1) out of the total. index is zero-based. Odd input
// is made safe instead of thrown at: a total below 1 or not a finite number
// counts as 1, and an index outside the range moves to the nearest end, so
// the result always reads X / Y with 1 <= X <= Y (FR-TR-12).
export function slideCounter(index: number, count: number): string {
const total = Number.isFinite(count)
? Math.min(Math.max(1, Math.trunc(count)), Number.MAX_SAFE_INTEGER)
: 1;
const current = Number.isFinite(index) ? Math.trunc(index) : 0;
const position = Math.min(Math.max(current, 0), total - 1);
return `${position + 1} / ${total}`;
}