ts-client-lib 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -0
- package/auth/TSJWT.d.ts +29 -0
- package/auth/TSJWT.js +44 -0
- package/auth/TSOAuth.d.ts +132 -0
- package/auth/TSOAuth.js +230 -0
- package/devices/TSCordova.d.ts +5 -0
- package/devices/TSCordova.js +52 -0
- package/entities/TSCountries.d.ts +14 -0
- package/entities/TSCountries.js +1188 -0
- package/entities/TSCurrencies.d.ts +35 -0
- package/entities/TSCurrencies.js +604 -0
- package/entities/TSMobilePhones.d.ts +167 -0
- package/entities/TSMobilePhones.js +206 -0
- package/entities/TSMoney.d.ts +149 -0
- package/entities/TSMoney.js +311 -0
- package/entities/currency-amount.d.ts +13 -0
- package/entities/currency-amount.js +43 -0
- package/finance/TSBonus.d.ts +197 -0
- package/finance/TSBonus.js +530 -0
- package/finance/TSKYC.d.ts +563 -0
- package/finance/TSKYC.js +1066 -0
- package/finance/TSTax.d.ts +49 -0
- package/finance/TSTax.js +106 -0
- package/finance/bonus-money.d.ts +41 -0
- package/finance/bonus-money.js +61 -0
- package/games/TSBetSlip.d.ts +72 -0
- package/games/TSBetSlip.js +179 -0
- package/games/TSBetSystem.d.ts +4 -0
- package/games/TSBetSystem.js +48 -0
- package/games/TSLotto.d.ts +35 -0
- package/games/TSLotto.js +205 -0
- package/games/TSPool.d.ts +28 -0
- package/games/TSPool.js +88 -0
- package/package.json +93 -0
- package/utils/TSArray.d.ts +9 -0
- package/utils/TSArray.js +87 -0
- package/utils/TSBoolean.d.ts +4 -0
- package/utils/TSBoolean.js +24 -0
- package/utils/TSCache.d.ts +167 -0
- package/utils/TSCache.js +531 -0
- package/utils/TSDate.d.ts +8 -0
- package/utils/TSDate.js +67 -0
- package/utils/TSHeuristic.d.ts +20 -0
- package/utils/TSHeuristic.js +197 -0
- package/utils/TSLZS.d.ts +42 -0
- package/utils/TSLZS.js +343 -0
- package/utils/TSLog.d.ts +40 -0
- package/utils/TSLog.js +110 -0
- package/utils/TSNumber.d.ts +6 -0
- package/utils/TSNumber.js +68 -0
- package/utils/TSObject.d.ts +29 -0
- package/utils/TSObject.js +312 -0
- package/utils/TSPagination.d.ts +282 -0
- package/utils/TSPagination.js +425 -0
- package/utils/TSPaginationMulti.d.ts +77 -0
- package/utils/TSPaginationMulti.js +356 -0
- package/utils/TSString.d.ts +10 -0
- package/utils/TSString.js +107 -0
- package/utils/TSValidator.d.ts +16 -0
- package/utils/TSValidator.js +74 -0
- package/utils/TSWorker.d.ts +3 -0
- package/utils/TSWorker.js +32 -0
- package/utils/diacritics-removal-map.d.ts +5 -0
- package/utils/diacritics-removal-map.js +341 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export interface TSTier {
|
|
2
|
+
rate: number;
|
|
3
|
+
floor: number;
|
|
4
|
+
ceiling: number;
|
|
5
|
+
}
|
|
6
|
+
export interface TSTaxTiers {
|
|
7
|
+
product: number;
|
|
8
|
+
deduct: any;
|
|
9
|
+
exciseRate: number;
|
|
10
|
+
tiers: TSTier[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Colon-delimited `deduct` DSL (pairs: key, value, key, value, …), e.g. `"income:1:floor:1:bonus:1"`.
|
|
14
|
+
* Use for client-visible specs so users know which TSTax instructions apply before calling the backend.
|
|
15
|
+
*/
|
|
16
|
+
export declare function encodeDeductSpec(pairs: Record<string, string | number | boolean>): string;
|
|
17
|
+
/** Parses a `deduct` string into key/value pairs (values are strings, matching `find()`). */
|
|
18
|
+
export declare function decodeDeductSpec(s: string): Record<string, string>;
|
|
19
|
+
/**
|
|
20
|
+
* Normalizes `tax.deduct` in place: `null`/`undefined` → `{}`, string → object via {@link decodeDeductSpec}.
|
|
21
|
+
* Idempotent for plain objects. Call before `outcome` / `income` when `find()` was not used.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseDeductInPlace(tax: TSTaxTiers): void;
|
|
24
|
+
/**
|
|
25
|
+
* [{
|
|
26
|
+
product: 1,
|
|
27
|
+
deduct: "income:1:floor:1:bonus:1",
|
|
28
|
+
exciseRate: 10,
|
|
29
|
+
tiers: [ { rate: 15, floor: 0, ceiling: 0 } ]
|
|
30
|
+
* }]
|
|
31
|
+
*/
|
|
32
|
+
export declare class TSTax {
|
|
33
|
+
taxes: TSTaxTiers[];
|
|
34
|
+
constructor(taxes?: TSTaxTiers[]);
|
|
35
|
+
income(tax: TSTaxTiers, income: number): {
|
|
36
|
+
value: number;
|
|
37
|
+
percent: number;
|
|
38
|
+
};
|
|
39
|
+
outcome(tax: TSTaxTiers, { outcome, income, reward, max }: {
|
|
40
|
+
outcome: number;
|
|
41
|
+
income: number;
|
|
42
|
+
reward?: number;
|
|
43
|
+
max?: number;
|
|
44
|
+
}): {
|
|
45
|
+
value: number;
|
|
46
|
+
percent: number;
|
|
47
|
+
};
|
|
48
|
+
find(product: number): TSTaxTiers;
|
|
49
|
+
}
|
package/finance/TSTax.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TSTax = void 0;
|
|
4
|
+
exports.encodeDeductSpec = encodeDeductSpec;
|
|
5
|
+
exports.decodeDeductSpec = decodeDeductSpec;
|
|
6
|
+
exports.parseDeductInPlace = parseDeductInPlace;
|
|
7
|
+
var TSArray_1 = require("../utils/TSArray");
|
|
8
|
+
/**
|
|
9
|
+
* Colon-delimited `deduct` DSL (pairs: key, value, key, value, …), e.g. `"income:1:floor:1:bonus:1"`.
|
|
10
|
+
* Use for client-visible specs so users know which TSTax instructions apply before calling the backend.
|
|
11
|
+
*/
|
|
12
|
+
function encodeDeductSpec(pairs) {
|
|
13
|
+
var keys = Object.keys(pairs).sort();
|
|
14
|
+
var parts = [];
|
|
15
|
+
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
|
|
16
|
+
var k = keys_1[_i];
|
|
17
|
+
parts.push(k, String(pairs[k]));
|
|
18
|
+
}
|
|
19
|
+
return parts.join(':');
|
|
20
|
+
}
|
|
21
|
+
/** Parses a `deduct` string into key/value pairs (values are strings, matching `find()`). */
|
|
22
|
+
function decodeDeductSpec(s) {
|
|
23
|
+
var t = s.trim();
|
|
24
|
+
if (!t)
|
|
25
|
+
return {};
|
|
26
|
+
return TSArray_1.TSArray.toPair(t.split(':'));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Normalizes `tax.deduct` in place: `null`/`undefined` → `{}`, string → object via {@link decodeDeductSpec}.
|
|
30
|
+
* Idempotent for plain objects. Call before `outcome` / `income` when `find()` was not used.
|
|
31
|
+
*/
|
|
32
|
+
function parseDeductInPlace(tax) {
|
|
33
|
+
if (tax.deduct == null) {
|
|
34
|
+
tax.deduct = {};
|
|
35
|
+
}
|
|
36
|
+
else if (typeof tax.deduct === 'string') {
|
|
37
|
+
tax.deduct = tax.deduct ? decodeDeductSpec(tax.deduct) : {};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Caller must have run {@link parseDeductInPlace} on `tax` so `deduct` is an object. */
|
|
41
|
+
function taxableWorth(outcome, income, reward, tax) {
|
|
42
|
+
var d = tax.deduct;
|
|
43
|
+
var skipIncome = (typeof reward === 'number') || (!d.income && typeof reward !== 'number');
|
|
44
|
+
return outcome - (skipIncome ? 0 : income);
|
|
45
|
+
}
|
|
46
|
+
function tierOutcomeIfMatch(tax, t, outcome, income, worth, max) {
|
|
47
|
+
if (worth < t.floor || (worth > t.ceiling && worth !== max))
|
|
48
|
+
return null;
|
|
49
|
+
var percent = t.rate;
|
|
50
|
+
var taxPrecent = percent / 100;
|
|
51
|
+
var d = tax.deduct;
|
|
52
|
+
if (d.floor) {
|
|
53
|
+
var value = (outcome - income - tax.tiers[0].floor > 0) ? (outcome - tax.tiers[0].floor) * -taxPrecent : 0;
|
|
54
|
+
return { value: value, percent: percent };
|
|
55
|
+
}
|
|
56
|
+
return { value: worth * -taxPrecent, percent: percent };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* [{
|
|
60
|
+
product: 1,
|
|
61
|
+
deduct: "income:1:floor:1:bonus:1",
|
|
62
|
+
exciseRate: 10,
|
|
63
|
+
tiers: [ { rate: 15, floor: 0, ceiling: 0 } ]
|
|
64
|
+
* }]
|
|
65
|
+
*/
|
|
66
|
+
var TSTax = /** @class */ (function () {
|
|
67
|
+
function TSTax(taxes) {
|
|
68
|
+
if (taxes === void 0) { taxes = []; }
|
|
69
|
+
this.taxes = taxes;
|
|
70
|
+
}
|
|
71
|
+
TSTax.prototype.income = function (tax, income) {
|
|
72
|
+
parseDeductInPlace(tax);
|
|
73
|
+
if (!tax.exciseRate) {
|
|
74
|
+
return { value: 0, percent: 0 };
|
|
75
|
+
}
|
|
76
|
+
var percent = tax.exciseRate, value = income / (1 + (percent / 100));
|
|
77
|
+
return { value: value, percent: percent };
|
|
78
|
+
};
|
|
79
|
+
TSTax.prototype.outcome = function (tax, _a) {
|
|
80
|
+
var outcome = _a.outcome, income = _a.income, _b = _a.reward, reward = _b === void 0 ? undefined : _b, _c = _a.max, max = _c === void 0 ? Infinity : _c;
|
|
81
|
+
parseDeductInPlace(tax);
|
|
82
|
+
if (!tax.tiers || tax.tiers.length < 1) {
|
|
83
|
+
return { value: outcome - (typeof reward === 'number' ? 0 : income), percent: 0 };
|
|
84
|
+
}
|
|
85
|
+
if (!Number(tax.tiers[tax.tiers.length - 1].ceiling)) {
|
|
86
|
+
tax.tiers[tax.tiers.length - 1].ceiling = max;
|
|
87
|
+
}
|
|
88
|
+
var worth = taxableWorth(outcome, income, reward, tax);
|
|
89
|
+
for (var _i = 0, _d = tax.tiers; _i < _d.length; _i++) {
|
|
90
|
+
var t = _d[_i];
|
|
91
|
+
var hit = tierOutcomeIfMatch(tax, t, outcome, income, worth, max);
|
|
92
|
+
if (hit)
|
|
93
|
+
return hit;
|
|
94
|
+
}
|
|
95
|
+
return { value: 0, percent: 0 };
|
|
96
|
+
};
|
|
97
|
+
TSTax.prototype.find = function (product) {
|
|
98
|
+
var tax = this.taxes.find(function (t) { return t.product === product; });
|
|
99
|
+
if (!tax)
|
|
100
|
+
return {};
|
|
101
|
+
parseDeductInPlace(tax);
|
|
102
|
+
return tax;
|
|
103
|
+
};
|
|
104
|
+
return TSTax;
|
|
105
|
+
}());
|
|
106
|
+
exports.TSTax = TSTax;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bonus amounts + **TSMoney** — semantics and strict DTO helpers.
|
|
3
|
+
*
|
|
4
|
+
* **Semantics (align with `BonusEligibility.calculateValue`)**
|
|
5
|
+
* - **`fixed`**: `value` is an integer in **minor units** (same as `TSMoney.amount`).
|
|
6
|
+
* - **`percentage`**: `value` is a percent (e.g. `10` → 10%). `depositAmount` / `activityAmount` are in
|
|
7
|
+
* **major (display) units** (e.g. dollars). Optional **`maxValue`** caps the result in those same units.
|
|
8
|
+
* - **`tiered` / `dynamic`**: same numeric rules as `calculateValue`; money output uses `fromDecimal`
|
|
9
|
+
* where the computed value is fractional.
|
|
10
|
+
*
|
|
11
|
+
* Optional **`valueMoney` / `maxValueMoney` / `minDepositMoney`** mirror the legacy fields for strict
|
|
12
|
+
* transport (GraphQL/JSON). If present, they must match — use `assertCoherentMoneyFields`.
|
|
13
|
+
*/
|
|
14
|
+
import { TSMoney } from '../entities/TSMoney';
|
|
15
|
+
import { type CurrencyCode } from '../entities/TSCurrencies';
|
|
16
|
+
export type TSMoneyJSON = {
|
|
17
|
+
amount: number;
|
|
18
|
+
currency: CurrencyCode;
|
|
19
|
+
};
|
|
20
|
+
export interface BonusMoneyFields {
|
|
21
|
+
currency: CurrencyCode;
|
|
22
|
+
valueType: 'fixed' | 'percentage' | 'tiered' | 'dynamic';
|
|
23
|
+
value: number;
|
|
24
|
+
valueMoney?: TSMoneyJSON;
|
|
25
|
+
maxValueMoney?: TSMoneyJSON;
|
|
26
|
+
minDepositMoney?: TSMoneyJSON;
|
|
27
|
+
}
|
|
28
|
+
export declare function parseMoneyJSON(input: TSMoneyJSON): TSMoney;
|
|
29
|
+
export declare function toMoneyJSON(m: TSMoney): TSMoneyJSON;
|
|
30
|
+
/**
|
|
31
|
+
* Ensures optional money DTO fields agree with `currency` / `value` (fixed).
|
|
32
|
+
*/
|
|
33
|
+
export declare function assertCoherentMoneyFields(t: BonusMoneyFields): void;
|
|
34
|
+
/**
|
|
35
|
+
* Fail fast if template references an unknown ISO/registry currency.
|
|
36
|
+
*/
|
|
37
|
+
export declare function assertKnownCurrenciesOnTemplate(template: {
|
|
38
|
+
currency: CurrencyCode;
|
|
39
|
+
supportedCurrencies?: readonly CurrencyCode[];
|
|
40
|
+
}): void;
|
|
41
|
+
export declare function hasCurrencyCode(code: string): boolean;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bonus amounts + **TSMoney** — semantics and strict DTO helpers.
|
|
4
|
+
*
|
|
5
|
+
* **Semantics (align with `BonusEligibility.calculateValue`)**
|
|
6
|
+
* - **`fixed`**: `value` is an integer in **minor units** (same as `TSMoney.amount`).
|
|
7
|
+
* - **`percentage`**: `value` is a percent (e.g. `10` → 10%). `depositAmount` / `activityAmount` are in
|
|
8
|
+
* **major (display) units** (e.g. dollars). Optional **`maxValue`** caps the result in those same units.
|
|
9
|
+
* - **`tiered` / `dynamic`**: same numeric rules as `calculateValue`; money output uses `fromDecimal`
|
|
10
|
+
* where the computed value is fractional.
|
|
11
|
+
*
|
|
12
|
+
* Optional **`valueMoney` / `maxValueMoney` / `minDepositMoney`** mirror the legacy fields for strict
|
|
13
|
+
* transport (GraphQL/JSON). If present, they must match — use `assertCoherentMoneyFields`.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.parseMoneyJSON = parseMoneyJSON;
|
|
17
|
+
exports.toMoneyJSON = toMoneyJSON;
|
|
18
|
+
exports.assertCoherentMoneyFields = assertCoherentMoneyFields;
|
|
19
|
+
exports.assertKnownCurrenciesOnTemplate = assertKnownCurrenciesOnTemplate;
|
|
20
|
+
exports.hasCurrencyCode = hasCurrencyCode;
|
|
21
|
+
var TSMoney_1 = require("../entities/TSMoney");
|
|
22
|
+
var TSCurrencies_1 = require("../entities/TSCurrencies");
|
|
23
|
+
function parseMoneyJSON(input) {
|
|
24
|
+
return TSMoney_1.TSMoney.fromInteger(input.amount, input.currency);
|
|
25
|
+
}
|
|
26
|
+
function toMoneyJSON(m) {
|
|
27
|
+
return m.toJSON();
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Ensures optional money DTO fields agree with `currency` / `value` (fixed).
|
|
31
|
+
*/
|
|
32
|
+
function assertCoherentMoneyFields(t) {
|
|
33
|
+
if (t.valueMoney) {
|
|
34
|
+
if (t.valueMoney.currency !== t.currency) {
|
|
35
|
+
throw new TypeError('valueMoney.currency must match template.currency');
|
|
36
|
+
}
|
|
37
|
+
if (t.valueType === 'fixed' && t.valueMoney.amount !== t.value) {
|
|
38
|
+
throw new TypeError('valueMoney.amount must equal value for fixed valueType');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (t.maxValueMoney && t.maxValueMoney.currency !== t.currency) {
|
|
42
|
+
throw new TypeError('maxValueMoney.currency must match template.currency');
|
|
43
|
+
}
|
|
44
|
+
if (t.minDepositMoney && t.minDepositMoney.currency !== t.currency) {
|
|
45
|
+
throw new TypeError('minDepositMoney.currency must match template.currency');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Fail fast if template references an unknown ISO/registry currency.
|
|
50
|
+
*/
|
|
51
|
+
function assertKnownCurrenciesOnTemplate(template) {
|
|
52
|
+
var _a;
|
|
53
|
+
(0, TSCurrencies_1.resolveCurrency)(String(template.currency));
|
|
54
|
+
for (var _i = 0, _b = (_a = template.supportedCurrencies) !== null && _a !== void 0 ? _a : []; _i < _b.length; _i++) {
|
|
55
|
+
var c = _b[_i];
|
|
56
|
+
(0, TSCurrencies_1.resolveCurrency)(String(c));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function hasCurrencyCode(code) {
|
|
60
|
+
return (0, TSCurrencies_1.hasCurrency)(code);
|
|
61
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export interface TSBSSelection {
|
|
2
|
+
k: string;
|
|
3
|
+
m: string;
|
|
4
|
+
o: number;
|
|
5
|
+
id: string;
|
|
6
|
+
sk?: string;
|
|
7
|
+
s?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface TSBSEventSelection {
|
|
10
|
+
k: string;
|
|
11
|
+
e: any;
|
|
12
|
+
s: TSBSSelection;
|
|
13
|
+
}
|
|
14
|
+
export type TSBSCallback = (stake: number, odd: number, keys: (string | number)[], group?: number | string) => {
|
|
15
|
+
payout: number;
|
|
16
|
+
stake: number;
|
|
17
|
+
};
|
|
18
|
+
export type TSBSResult = {
|
|
19
|
+
numberOfBets: number;
|
|
20
|
+
totalStake: number;
|
|
21
|
+
totalOdds: number;
|
|
22
|
+
minPayOut?: number;
|
|
23
|
+
maxPayOut: number;
|
|
24
|
+
};
|
|
25
|
+
export type TSBSMode = 'single' | 'multiple' | 'multiple+' | 'system';
|
|
26
|
+
export declare class TSBetSlip {
|
|
27
|
+
static get modes(): Array<TSBSMode>;
|
|
28
|
+
static initModes({ modes, multiplePlus }: {
|
|
29
|
+
modes?: TSBSMode[] | TSBSMode;
|
|
30
|
+
multiplePlus?: string;
|
|
31
|
+
}): Array<TSBSMode>;
|
|
32
|
+
static filterMode(modes: Array<TSBSMode> | TSBSMode): Array<TSBSMode> | TSBSMode;
|
|
33
|
+
static accumulator(selections: TSBSSelection[], data: Record<string, number | string>, cb?: TSBSCallback): TSBSResult;
|
|
34
|
+
static multiplicator(selections: TSBSSelection[], data: number, cb?: TSBSCallback): TSBSResult;
|
|
35
|
+
static aggregator(selections: Record<string, TSBSSelection>, data: Record<string, unknown> & {
|
|
36
|
+
_?: unknown[][];
|
|
37
|
+
}, cb?: TSBSCallback): TSBSResult;
|
|
38
|
+
/** Combined odds and selection keys for one system row; `null` if row is invalid. */
|
|
39
|
+
private static aggregatorRowOddsAndKeys;
|
|
40
|
+
static cb(stake: number, odd: number, _keys: (string | number)[], _group?: number | string): {
|
|
41
|
+
payout: number;
|
|
42
|
+
stake: number;
|
|
43
|
+
};
|
|
44
|
+
static rules({ minBet, maxBet, maxPayout, minSelection, maxSelection }?: {
|
|
45
|
+
minBet?: number | undefined;
|
|
46
|
+
maxBet?: number | undefined;
|
|
47
|
+
maxPayout?: number | undefined;
|
|
48
|
+
minSelection?: number | undefined;
|
|
49
|
+
maxSelection?: number | undefined;
|
|
50
|
+
}, overrides?: Record<string, unknown>): {
|
|
51
|
+
stake: {
|
|
52
|
+
min: number;
|
|
53
|
+
max: number;
|
|
54
|
+
};
|
|
55
|
+
payout: {
|
|
56
|
+
max: number;
|
|
57
|
+
};
|
|
58
|
+
selection: {
|
|
59
|
+
min: number;
|
|
60
|
+
max: number;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
static isValid({ rules, selection, stake, balance, payout }: {
|
|
64
|
+
rules?: ReturnType<typeof TSBetSlip.rules>;
|
|
65
|
+
selection: number;
|
|
66
|
+
stake: number;
|
|
67
|
+
balance: number;
|
|
68
|
+
payout: number;
|
|
69
|
+
}): unknown[];
|
|
70
|
+
static validate(rules: Record<string, unknown>, data: Record<string, unknown>, prefix: (p: string | number) => string): unknown[];
|
|
71
|
+
static areDuplicate(selections: TSBSSelection[], separator?: string): boolean;
|
|
72
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
+
if (ar || !(i in from)) {
|
|
16
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
+
ar[i] = from[i];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.TSBetSlip = void 0;
|
|
24
|
+
var TSObject_1 = require("../utils/TSObject");
|
|
25
|
+
var TSString_1 = require("../utils/TSString");
|
|
26
|
+
var TSValidator_1 = require("../utils/TSValidator");
|
|
27
|
+
var TSBetSlip = /** @class */ (function () {
|
|
28
|
+
function TSBetSlip() {
|
|
29
|
+
}
|
|
30
|
+
Object.defineProperty(TSBetSlip, "modes", {
|
|
31
|
+
get: function () {
|
|
32
|
+
return ['single', 'multiple', 'multiple+', 'system'];
|
|
33
|
+
},
|
|
34
|
+
enumerable: false,
|
|
35
|
+
configurable: true
|
|
36
|
+
});
|
|
37
|
+
TSBetSlip.initModes = function (_a) {
|
|
38
|
+
var modes = _a.modes, multiplePlus = _a.multiplePlus;
|
|
39
|
+
var modesArr;
|
|
40
|
+
if (!modes) {
|
|
41
|
+
modesArr = __spreadArray([], TSBetSlip.modes, true);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
var filtered = TSBetSlip.filterMode(modes);
|
|
45
|
+
modesArr = Array.isArray(filtered) ? filtered : [filtered];
|
|
46
|
+
}
|
|
47
|
+
// multiplePlus = tab | multiple
|
|
48
|
+
if (multiplePlus !== 'tab') {
|
|
49
|
+
var mpIndex = modesArr.indexOf('multiple+');
|
|
50
|
+
if (mpIndex !== -1) {
|
|
51
|
+
modesArr.splice(mpIndex, 1);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return modesArr;
|
|
55
|
+
};
|
|
56
|
+
TSBetSlip.filterMode = function (modes) {
|
|
57
|
+
var _a;
|
|
58
|
+
if (Array.isArray(modes)) {
|
|
59
|
+
return modes.filter(function (m) { return TSBetSlip.modes.indexOf(m) > -1; });
|
|
60
|
+
}
|
|
61
|
+
return (_a = TSBetSlip.modes.find(function (m) { return m === modes; })) !== null && _a !== void 0 ? _a : modes;
|
|
62
|
+
};
|
|
63
|
+
TSBetSlip.accumulator = function (selections, data, cb) {
|
|
64
|
+
if (cb === void 0) { cb = TSBetSlip.cb; }
|
|
65
|
+
var result = { numberOfBets: 0, totalStake: 0, totalOdds: 0, minPayOut: Infinity, maxPayOut: 0 };
|
|
66
|
+
selections.forEach(function (s) {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
var sk = (_a = s.sk) !== null && _a !== void 0 ? _a : '';
|
|
69
|
+
var stakeSelection = Number(data[sk]) || 0, odd = Number(s.o) || 0;
|
|
70
|
+
if (stakeSelection) {
|
|
71
|
+
result.numberOfBets++;
|
|
72
|
+
var _c = cb(stakeSelection, odd, [sk], sk), payout = _c.payout, stake = _c.stake;
|
|
73
|
+
var minP = (_b = result.minPayOut) !== null && _b !== void 0 ? _b : Infinity;
|
|
74
|
+
if (payout < minP) {
|
|
75
|
+
result.minPayOut = payout;
|
|
76
|
+
}
|
|
77
|
+
result.totalStake += stake;
|
|
78
|
+
result.maxPayOut += payout;
|
|
79
|
+
result.totalOdds += odd;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return result;
|
|
83
|
+
};
|
|
84
|
+
TSBetSlip.multiplicator = function (selections, data, cb) {
|
|
85
|
+
if (cb === void 0) { cb = TSBetSlip.cb; }
|
|
86
|
+
var result = { numberOfBets: 0, totalStake: 0, totalOdds: 1, maxPayOut: 0 }, keys = [];
|
|
87
|
+
selections.forEach(function (s) { var _a; return (keys.push((_a = s.sk) !== null && _a !== void 0 ? _a : ''), result.totalOdds *= Number(s.o) || 1); });
|
|
88
|
+
if (data) {
|
|
89
|
+
result.numberOfBets = 1;
|
|
90
|
+
}
|
|
91
|
+
var _a = cb(data, result.totalOdds, keys), payout = _a.payout, stake = _a.stake;
|
|
92
|
+
result.maxPayOut = payout;
|
|
93
|
+
result.totalStake = stake;
|
|
94
|
+
return result;
|
|
95
|
+
};
|
|
96
|
+
TSBetSlip.aggregator = function (selections, data, cb) {
|
|
97
|
+
var _a, _b;
|
|
98
|
+
if (cb === void 0) { cb = TSBetSlip.cb; }
|
|
99
|
+
var result = { numberOfBets: 0, totalStake: 0, totalOdds: 0, minPayOut: Infinity, maxPayOut: 0 };
|
|
100
|
+
var indexGroups = (_a = data._) !== null && _a !== void 0 ? _a : [];
|
|
101
|
+
for (var k in data) {
|
|
102
|
+
if (k === '_')
|
|
103
|
+
continue;
|
|
104
|
+
var selectionIndexs = indexGroups[parseInt(k, 10)];
|
|
105
|
+
if (!data[k] || !selectionIndexs)
|
|
106
|
+
continue;
|
|
107
|
+
if (!Array.isArray(selectionIndexs))
|
|
108
|
+
return result;
|
|
109
|
+
result.numberOfBets += selectionIndexs.length;
|
|
110
|
+
for (var i in selectionIndexs) {
|
|
111
|
+
var row = selectionIndexs[i];
|
|
112
|
+
var rowOutcome = TSBetSlip.aggregatorRowOddsAndKeys(selections, row);
|
|
113
|
+
if (rowOutcome === null)
|
|
114
|
+
return result;
|
|
115
|
+
var _c = cb(Number(data[k]), rowOutcome.odds, rowOutcome.keys, "".concat(k, "_").concat(i)), payout = _c.payout, stake = _c.stake;
|
|
116
|
+
var minP = (_b = result.minPayOut) !== null && _b !== void 0 ? _b : Infinity;
|
|
117
|
+
if (payout < minP)
|
|
118
|
+
result.minPayOut = payout;
|
|
119
|
+
result.totalOdds += rowOutcome.odds;
|
|
120
|
+
result.maxPayOut += payout;
|
|
121
|
+
result.totalStake += stake;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
125
|
+
};
|
|
126
|
+
/** Combined odds and selection keys for one system row; `null` if row is invalid. */
|
|
127
|
+
TSBetSlip.aggregatorRowOddsAndKeys = function (selections, row) {
|
|
128
|
+
if (!row || typeof row[Symbol.iterator] !== 'function')
|
|
129
|
+
return null;
|
|
130
|
+
var odds = 1;
|
|
131
|
+
var keys = [];
|
|
132
|
+
for (var _i = 0, row_1 = row; _i < row_1.length; _i++) {
|
|
133
|
+
var j = row_1[_i];
|
|
134
|
+
var key = String(j);
|
|
135
|
+
var sel = selections[key];
|
|
136
|
+
if (!sel)
|
|
137
|
+
continue;
|
|
138
|
+
odds *= Number(sel.o);
|
|
139
|
+
keys.push(key);
|
|
140
|
+
}
|
|
141
|
+
return { odds: odds, keys: keys };
|
|
142
|
+
};
|
|
143
|
+
TSBetSlip.cb = function (stake, odd, _keys, _group) {
|
|
144
|
+
return { payout: stake * odd, stake: stake };
|
|
145
|
+
};
|
|
146
|
+
TSBetSlip.rules = function (_a, overrides) {
|
|
147
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.minBet, minBet = _c === void 0 ? 0.3 : _c, _d = _b.maxBet, maxBet = _d === void 0 ? 999999999 : _d, _e = _b.maxPayout, maxPayout = _e === void 0 ? 999999999 : _e, _f = _b.minSelection, minSelection = _f === void 0 ? 1 : _f, _g = _b.maxSelection, maxSelection = _g === void 0 ? 99 : _g;
|
|
148
|
+
if (overrides === void 0) { overrides = {}; }
|
|
149
|
+
var rules = {
|
|
150
|
+
stake: { min: minBet, max: maxBet }, payout: { max: maxPayout }, selection: { min: minSelection, max: maxSelection }
|
|
151
|
+
};
|
|
152
|
+
TSObject_1.TSObject.forOwn(rules, function (r, k) {
|
|
153
|
+
var o = overrides[String(k)];
|
|
154
|
+
if (o) {
|
|
155
|
+
Object.assign(r, o);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
return rules;
|
|
159
|
+
};
|
|
160
|
+
TSBetSlip.isValid = function (_a) {
|
|
161
|
+
var _b = _a.rules, rules = _b === void 0 ? TSBetSlip.rules() : _b, selection = _a.selection, stake = _a.stake, balance = _a.balance, payout = _a.payout;
|
|
162
|
+
return TSBetSlip.validate(rules, {
|
|
163
|
+
selection: { amount: selection }, stake: { amount: stake, balance: balance }, payout: { amount: payout }
|
|
164
|
+
}, function (prefix) { return 'BSE' + TSString_1.TSString.cfChar(String(prefix)); });
|
|
165
|
+
};
|
|
166
|
+
TSBetSlip.validate = function (rules, data, prefix) {
|
|
167
|
+
var validations = [];
|
|
168
|
+
TSObject_1.TSObject.forOwn(rules, function (r, k) {
|
|
169
|
+
validations = validations.concat(new TSValidator_1.TSValidator(__assign(__assign({}, r), data[String(k)])).compare(prefix(k)));
|
|
170
|
+
});
|
|
171
|
+
return validations;
|
|
172
|
+
};
|
|
173
|
+
TSBetSlip.areDuplicate = function (selections, separator) {
|
|
174
|
+
if (separator === void 0) { separator = '@'; }
|
|
175
|
+
return new Set(selections.map(function (s) { var _a; return ((_a = s.sk) !== null && _a !== void 0 ? _a : '').toString().split(separator)[0]; })).size != selections.length;
|
|
176
|
+
};
|
|
177
|
+
return TSBetSlip;
|
|
178
|
+
}());
|
|
179
|
+
exports.TSBetSlip = TSBetSlip;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TSBetSystem = void 0;
|
|
4
|
+
var TSBetSystem = /** @class */ (function () {
|
|
5
|
+
function TSBetSystem() {
|
|
6
|
+
}
|
|
7
|
+
TSBetSystem.generate = function (selectionKeys, cut, max, banker) {
|
|
8
|
+
var _a;
|
|
9
|
+
if (cut === void 0) { cut = 1; }
|
|
10
|
+
if (max === void 0) { max = 9; }
|
|
11
|
+
if (banker === void 0) { banker = []; }
|
|
12
|
+
var results = [];
|
|
13
|
+
if (selectionKeys.length > max && cut === 1) {
|
|
14
|
+
return results;
|
|
15
|
+
}
|
|
16
|
+
for (var i = cut; i < selectionKeys.length && i < max; i++) {
|
|
17
|
+
var c = TSBetSystem.combine(selectionKeys, i, banker);
|
|
18
|
+
if ((_a = c === null || c === void 0 ? void 0 : c[0]) === null || _a === void 0 ? void 0 : _a.length) {
|
|
19
|
+
results.push(c);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return results;
|
|
23
|
+
};
|
|
24
|
+
TSBetSystem.combine = function (selections, size, banker) {
|
|
25
|
+
if (banker === void 0) { banker = []; }
|
|
26
|
+
var combinations = [], combine = function (current, start) {
|
|
27
|
+
if (current.length === size) {
|
|
28
|
+
combinations.push(current.slice());
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
var _loop_1 = function (i) {
|
|
32
|
+
var currentNumber = e(selections[i]);
|
|
33
|
+
if (currentNumber != null && current.indexOf(currentNumber) === -1 && current.every(function (n) { return e(n) !== currentNumber; })) {
|
|
34
|
+
current.push(selections[i]);
|
|
35
|
+
combine(current, i + 1);
|
|
36
|
+
current.pop();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
for (var i = start; i < selections.length; i++) {
|
|
40
|
+
_loop_1(i);
|
|
41
|
+
}
|
|
42
|
+
}, e = function (s) { return (s === null || s === void 0 ? void 0 : s.substring(0, 24)) || null; };
|
|
43
|
+
combine(banker, 0);
|
|
44
|
+
return combinations;
|
|
45
|
+
};
|
|
46
|
+
return TSBetSystem;
|
|
47
|
+
}());
|
|
48
|
+
exports.TSBetSystem = TSBetSystem;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface ITSLotto {
|
|
2
|
+
max: number;
|
|
3
|
+
pick: number;
|
|
4
|
+
extra: number;
|
|
5
|
+
tickets: number;
|
|
6
|
+
sort?: boolean;
|
|
7
|
+
randomize?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class TSLotto {
|
|
10
|
+
options: ITSLotto;
|
|
11
|
+
numbers: Array<number>;
|
|
12
|
+
selections: Array<Array<number>>;
|
|
13
|
+
bonus: Array<Array<number>>;
|
|
14
|
+
get render(): {
|
|
15
|
+
numbers: number[];
|
|
16
|
+
selections: number[][];
|
|
17
|
+
bonus: number[][];
|
|
18
|
+
lines: number[][];
|
|
19
|
+
options: ITSLotto;
|
|
20
|
+
};
|
|
21
|
+
set lotto(data: any);
|
|
22
|
+
constructor(options?: ITSLotto);
|
|
23
|
+
fillLine(line: Array<number>, existingLine?: Array<number>): void;
|
|
24
|
+
randomLine(index: number): void;
|
|
25
|
+
addLine(line?: Array<number>): number;
|
|
26
|
+
shufleLines(): void;
|
|
27
|
+
adjustLines(tickets: number): void;
|
|
28
|
+
clearLine(index: number): void;
|
|
29
|
+
deleteLine(index: number): void;
|
|
30
|
+
emptyLine(length: number): number[];
|
|
31
|
+
validateLine(index: number): boolean;
|
|
32
|
+
clear(): void;
|
|
33
|
+
toggle(line: number, index: number): void;
|
|
34
|
+
isComplete(index?: number): boolean;
|
|
35
|
+
}
|