Download src/parser.js from Syntrex/ROIBot: direct link, hf CLI and curl.
- Browser
- Download file 2.16 kB
-
https://huggingface.co/spaces/Syntrex/ROIBot/resolve/176f0fc8d66e2544bca2268187d00cd61ba2500f/src/parser.js
- Command line
-
hf download hf://spaces/Syntrex/ROIBot@176f0fc8d66e2544bca2268187d00cd61ba2500f/src/parser.js
-
curl -L -o parser.js https://huggingface.co/spaces/Syntrex/ROIBot/resolve/176f0fc8d66e2544bca2268187d00cd61ba2500f/src/parser.js
2.16 kB
| function parseStake(input) { | |
| const source = String(input ?? '').trim(); | |
| const currencyMatch = source.match(/^\$?\s*(\d+(?:\.\d{1,2})?)$/); | |
| if (!currencyMatch) { | |
| return null; | |
| } | |
| return Number(currencyMatch[1]); | |
| } | |
| function parseOdds(sourceInput) { | |
| const source = String(sourceInput ?? '').trim(); | |
| const americanMatch = source.match(/^([+-]\d{3,})$/); | |
| if (americanMatch) { | |
| return americanMatch[1]; | |
| } | |
| const decimalMatch = source.match(/^(\d+(?:\.\d{1,3})?)$/); | |
| if (decimalMatch) { | |
| const decimal = Number(decimalMatch[1]); | |
| if (decimal >= 1.01) { | |
| return decimalMatch[1]; | |
| } | |
| } | |
| return null; | |
| } | |
| function normalizeDecimalOdds(oddsInput) { | |
| if (!oddsInput) { | |
| return null; | |
| } | |
| if (/^[+-]\d+$/.test(oddsInput)) { | |
| const american = Number(oddsInput); | |
| if (american > 0) { | |
| return Number((1 + american / 100).toFixed(4)); | |
| } | |
| return Number((1 + 100 / Math.abs(american)).toFixed(4)); | |
| } | |
| const decimal = Number(oddsInput); | |
| if (Number.isFinite(decimal) && decimal >= 1.01) { | |
| return Number(decimal.toFixed(4)); | |
| } | |
| return null; | |
| } | |
| export function parseBetInput(fields) { | |
| const book = String(fields.book ?? '').trim(); | |
| const sport = String(fields.sport ?? '').trim(); | |
| const prop = String(fields.prop ?? '').trim(); | |
| const oddsInput = parseOdds(fields.odds); | |
| const stake = parseStake(fields.stake); | |
| const normalizedDecimalOdds = normalizeDecimalOdds(oddsInput); | |
| const missingFields = []; | |
| if (!book) { | |
| missingFields.push('book'); | |
| } | |
| if (!sport) { | |
| missingFields.push('sport'); | |
| } | |
| if (!oddsInput || !normalizedDecimalOdds) { | |
| missingFields.push('odds'); | |
| } | |
| if (!prop) { | |
| missingFields.push('prop'); | |
| } | |
| if (stake === null || stake <= 0) { | |
| missingFields.push('stake'); | |
| } | |
| return { | |
| ok: missingFields.length === 0, | |
| missingFields, | |
| bet: missingFields.length === 0 | |
| ? { | |
| book, | |
| sport, | |
| oddsInput, | |
| normalizedDecimalOdds, | |
| prop, | |
| stake, | |
| rawInput: `book: ${book}\nsport: ${sport}\nprop: ${prop}\nodds: ${oddsInput}\nstake: ${stake}`, | |
| } | |
| : null, | |
| }; | |
| } | |