File size: 782 Bytes
ec4cf41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
export function parseBetIdList(input) {
  const tokens = String(input ?? '')
    .split(/[,\s]+/)
    .map((token) => token.trim())
    .filter(Boolean);

  if (tokens.length === 0) {
    return { ok: false, error: 'Please provide at least one bet ID.' };
  }

  const ids = [];
  const invalid = [];

  for (const token of tokens) {
    if (!/^\d+$/.test(token)) {
      invalid.push(token);
      continue;
    }

    const value = Number(token);
    if (!Number.isSafeInteger(value) || value <= 0) {
      invalid.push(token);
      continue;
    }

    if (!ids.includes(value)) {
      ids.push(value);
    }
  }

  if (invalid.length > 0) {
    return {
      ok: false,
      error: `Invalid bet ID value(s): ${invalid.join(', ')}`,
    };
  }

  return { ok: true, ids };
}