feat: update Keepa and Stalker functionalities with enhanced price extraction logic and test cases

This commit is contained in:
Victor Noguera
2026-05-19 19:59:20 -04:00
parent 0552d183b3
commit 7bda3710ed
4 changed files with 30 additions and 24 deletions

View File

@@ -1355,7 +1355,11 @@ function extractCurrentPrice(csv: unknown): number | null {
function extractLatestPositiveKeepaPrice(history: unknown): number | null {
if (!Array.isArray(history)) return null;
for (let i = history.length - 1; i >= 0; i--) {
// Keepa CSV histories are [time, value, time, value, ...]. Only odd indexes
// are prices; even indexes are Keepa timestamps and can look like huge prices.
for (let i = history.length - 1; i >= 1; i--) {
if (i % 2 === 0) continue;
const value = extractNumber(history[i]);
if (value != null && value > 0) return value / 100;
}