UNPKG

@cloudbet/market-helper

Version:

SDK to generate localized sport market information

51 lines 2.28 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import { selectionCountPerLine } from './sports-core'; import { throwIfInvalidMarketType, throwIfUndefined } from './utility'; /** @file exposed functions that are not considered part of the public api for internal purposes. Use at own risk. */ export function getRawLines(marketData, marketType, submarketKey) { var _a; throwIfInvalidMarketType(marketType); throwIfUndefined(marketData, 'marketData'); throwIfUndefined(submarketKey, 'submarketKey'); var submarket = (_a = marketData === null || marketData === void 0 ? void 0 : marketData.submarkets) === null || _a === void 0 ? void 0 : _a[submarketKey]; if (!submarket) { return [[], null]; } var _b = selectionCountPerLine(marketType, submarket), lineSelectionCount = _b[0], error = _b[1]; if (error) { return [[], error]; } var count = lineSelectionCount.count, hasLay = lineSelectionCount.hasLay; var selections = submarket.selections || []; // in dynamic markets count will be zero var lines = new Array(count > 0 ? selections.length / count : 1); for (var i = 0; i < selections.length; i++) { var selection = selections[i]; var isLaySelection = hasLay && i % 2 === 1; var lineIndex = Math.floor(i / count); var line = lines[lineIndex] || new Array(hasLay ? count / 2 : count); lines[lineIndex] = line; var offset = lineIndex * count; var outcomeIndex = Math.floor((i - offset) / (hasLay ? 2 : 1)); var rawSelection = __assign(__assign({}, selection), { index: i }); if (isLaySelection) { line[outcomeIndex].lay = rawSelection; } else { line[outcomeIndex] = { back: rawSelection }; } } return [lines, null]; } export { isMarketTotals, isMarketHandicap, isMarketCorrectScore, } from './marketUtils'; //# sourceMappingURL=internal.js.map