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
package/games/TSLotto.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.TSLotto = void 0;
|
|
15
|
+
var TSNumber_1 = require("../utils/TSNumber");
|
|
16
|
+
var TSLotto = /** @class */ (function () {
|
|
17
|
+
function TSLotto(options) {
|
|
18
|
+
if (options === void 0) { options = { max: 36, pick: 3, extra: 2, tickets: 5 }; }
|
|
19
|
+
var _this = this;
|
|
20
|
+
this.numbers = [];
|
|
21
|
+
this.selections = [];
|
|
22
|
+
this.bonus = [];
|
|
23
|
+
this.options = options;
|
|
24
|
+
this.numbers = Array.from({ length: options.max }, function (v, i) { return i + 1; });
|
|
25
|
+
this.selections = Array.from({ length: options.tickets }, function () { return _this.emptyLine(options.pick); });
|
|
26
|
+
if (options.extra) {
|
|
27
|
+
this.bonus = Array.from({ length: options.tickets }, function () { return _this.emptyLine(options.extra); });
|
|
28
|
+
}
|
|
29
|
+
if (this.options.randomize) {
|
|
30
|
+
this.selections.forEach(function (l, i) {
|
|
31
|
+
_this.fillLine(l);
|
|
32
|
+
if (options.extra) {
|
|
33
|
+
_this.fillLine(_this.bonus[i], l);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
Object.defineProperty(TSLotto.prototype, "render", {
|
|
39
|
+
get: function () {
|
|
40
|
+
var _this = this;
|
|
41
|
+
var sortNumber = function (a, b) { return a - b; }, formatLines = function () {
|
|
42
|
+
var lines = [];
|
|
43
|
+
_this.selections.forEach(function (l, i) {
|
|
44
|
+
if (_this.options.sort) {
|
|
45
|
+
lines[i] = _this.selections[i] = _this.selections[i].sort(sortNumber);
|
|
46
|
+
if (_this.options.extra) {
|
|
47
|
+
_this.bonus[i] = _this.bonus[i].sort(sortNumber);
|
|
48
|
+
lines[i] = lines[i].concat(_this.bonus[i]);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
lines[i] = _this.selections[i];
|
|
53
|
+
if (_this.options.extra) {
|
|
54
|
+
lines[i] = lines[i].concat(_this.bonus[i]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return { selections: _this.selections, bonus: _this.bonus, lines: lines };
|
|
59
|
+
};
|
|
60
|
+
return __assign(__assign({ options: this.options }, formatLines()), { numbers: this.numbers });
|
|
61
|
+
},
|
|
62
|
+
enumerable: false,
|
|
63
|
+
configurable: true
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(TSLotto.prototype, "lotto", {
|
|
66
|
+
set: function (data) {
|
|
67
|
+
this.options = data.options;
|
|
68
|
+
this.selections = data.selections;
|
|
69
|
+
this.bonus = data.bonus;
|
|
70
|
+
this.numbers = data.numbers;
|
|
71
|
+
},
|
|
72
|
+
enumerable: false,
|
|
73
|
+
configurable: true
|
|
74
|
+
});
|
|
75
|
+
TSLotto.prototype.fillLine = function (line, existingLine) {
|
|
76
|
+
if (existingLine === void 0) { existingLine = []; }
|
|
77
|
+
var index = line.findIndex(Number.isNaN);
|
|
78
|
+
while (index > -1) {
|
|
79
|
+
var random = TSNumber_1.TSNumber.random(1, this.options.max);
|
|
80
|
+
if (line.indexOf(random) === -1 && existingLine.indexOf(random) === -1) {
|
|
81
|
+
line[index] = random;
|
|
82
|
+
}
|
|
83
|
+
index = line.findIndex(Number.isNaN);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
TSLotto.prototype.randomLine = function (index) {
|
|
87
|
+
this.clearLine(index);
|
|
88
|
+
this.fillLine(this.selections[index], this.bonus[index]);
|
|
89
|
+
if (this.options.extra) {
|
|
90
|
+
this.fillLine(this.bonus[index], this.selections[index]);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
TSLotto.prototype.addLine = function (line) {
|
|
94
|
+
var _this = this;
|
|
95
|
+
if (line) {
|
|
96
|
+
var lineLength = this.options.pick + this.options.extra;
|
|
97
|
+
this.selections.unshift([]);
|
|
98
|
+
this.selections[0] = line.slice(0, this.options.pick);
|
|
99
|
+
if (this.options.extra) {
|
|
100
|
+
this.bonus.unshift([]);
|
|
101
|
+
this.bonus[0] = line.slice(this.options.pick, lineLength);
|
|
102
|
+
}
|
|
103
|
+
if (this.selections[0].length + (this.bonus[0] ? this.bonus[0].length : 0) !== lineLength) {
|
|
104
|
+
this.deleteLine(0);
|
|
105
|
+
return -2;
|
|
106
|
+
}
|
|
107
|
+
else if (this.validateLine(0)) {
|
|
108
|
+
this.deleteLine(0);
|
|
109
|
+
return -1;
|
|
110
|
+
}
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
this.selections.push(this.emptyLine(this.options.pick));
|
|
115
|
+
this.bonus.push(this.emptyLine(this.options.extra));
|
|
116
|
+
var lastIndex_1 = this.selections.length - 1;
|
|
117
|
+
if (this.options.randomize) {
|
|
118
|
+
this.selections.forEach(function () {
|
|
119
|
+
_this.fillLine(_this.selections[lastIndex_1]);
|
|
120
|
+
if (_this.options.extra) {
|
|
121
|
+
_this.fillLine(_this.bonus[lastIndex_1], _this.selections[lastIndex_1]);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return lastIndex_1;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
TSLotto.prototype.shufleLines = function () {
|
|
129
|
+
var _this = this;
|
|
130
|
+
this.selections.forEach(function (s, i) { return _this.randomLine(i); });
|
|
131
|
+
};
|
|
132
|
+
TSLotto.prototype.adjustLines = function (tickets) {
|
|
133
|
+
this.options.tickets = tickets;
|
|
134
|
+
var count = this.selections.length;
|
|
135
|
+
for (var j = 0; j < Math.abs(tickets - count); j++) {
|
|
136
|
+
if (tickets - count > 0) {
|
|
137
|
+
this.addLine();
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
this.deleteLine(this.render.lines.length - 1);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
TSLotto.prototype.clearLine = function (index) {
|
|
145
|
+
this.selections[index] = this.emptyLine(this.options.pick);
|
|
146
|
+
this.bonus[index] = this.emptyLine(this.options.extra);
|
|
147
|
+
};
|
|
148
|
+
TSLotto.prototype.deleteLine = function (index) {
|
|
149
|
+
this.bonus.splice(index, 1);
|
|
150
|
+
this.selections.splice(index, 1);
|
|
151
|
+
};
|
|
152
|
+
TSLotto.prototype.emptyLine = function (length) {
|
|
153
|
+
return Array.from({ length: length }, function () { return NaN; });
|
|
154
|
+
};
|
|
155
|
+
TSLotto.prototype.validateLine = function (index) {
|
|
156
|
+
var _this = this;
|
|
157
|
+
var l = this.selections[index].concat(this.bonus[index] || []);
|
|
158
|
+
return l.some(function (v, i) { return l.indexOf(v) !== i || (v > _this.options.max || v < 1); });
|
|
159
|
+
};
|
|
160
|
+
TSLotto.prototype.clear = function () {
|
|
161
|
+
var _this = this;
|
|
162
|
+
this.selections.forEach(function (v, i) { return _this.clearLine(i); });
|
|
163
|
+
};
|
|
164
|
+
TSLotto.prototype.toggle = function (line, index) {
|
|
165
|
+
var sli = this.selections[line].indexOf(this.numbers[index]), bli = this.bonus[line] && this.bonus[line].length ? this.bonus[line].indexOf(this.numbers[index]) : -1, isFull = sli === -1 && bli === -1 && this.isComplete(line);
|
|
166
|
+
if (isFull) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
else if (sli > -1) {
|
|
170
|
+
this.selections[line][sli] = NaN;
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
else if (bli > -1) {
|
|
174
|
+
this.bonus[line][bli] = NaN;
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
var s = this.selections[line].findIndex(Number.isNaN), b = this.bonus[line] && this.bonus[line].length ? this.bonus[line].findIndex(Number.isNaN) : -1;
|
|
178
|
+
if (s > -1 && bli === -1 && sli === -1) {
|
|
179
|
+
this.selections[line][s] = this.numbers[index];
|
|
180
|
+
}
|
|
181
|
+
else if (b > -1 && sli === -1) {
|
|
182
|
+
this.bonus[line][b] = this.numbers[index];
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
TSLotto.prototype.isComplete = function (index) {
|
|
186
|
+
var _this = this;
|
|
187
|
+
var isLineComplete = function (i) {
|
|
188
|
+
var hasNaN = _this.selections[i].findIndex(Number.isNaN) === -1;
|
|
189
|
+
if (_this.options.extra) {
|
|
190
|
+
hasNaN = hasNaN && _this.bonus[i].findIndex(Number.isNaN) === -1;
|
|
191
|
+
}
|
|
192
|
+
return hasNaN;
|
|
193
|
+
};
|
|
194
|
+
if (typeof index !== 'undefined') {
|
|
195
|
+
return isLineComplete(index);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
var isFull_1 = true;
|
|
199
|
+
this.selections.forEach(function (l, i) { return isFull_1 = isFull_1 && isLineComplete(i); });
|
|
200
|
+
return isFull_1;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
return TSLotto;
|
|
204
|
+
}());
|
|
205
|
+
exports.TSLotto = TSLotto;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface ITSPool {
|
|
2
|
+
matches: Array<any>;
|
|
3
|
+
reserve?: Array<any>;
|
|
4
|
+
stake: number;
|
|
5
|
+
size?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface ITSPoolResult {
|
|
8
|
+
selected: Record<string, Array<string>>;
|
|
9
|
+
lines: number;
|
|
10
|
+
stake: number;
|
|
11
|
+
amount: number;
|
|
12
|
+
completed: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare class TSPool {
|
|
15
|
+
private params;
|
|
16
|
+
options: ITSPool;
|
|
17
|
+
result: ITSPoolResult;
|
|
18
|
+
private items;
|
|
19
|
+
private selected;
|
|
20
|
+
constructor(params: ITSPool);
|
|
21
|
+
toggleLine(k: string): ITSPoolResult;
|
|
22
|
+
favoriteLines(kItem?: string, property?: string): ITSPoolResult;
|
|
23
|
+
randomLines(kItem?: string): ITSPoolResult;
|
|
24
|
+
clearLines(): ITSPoolResult;
|
|
25
|
+
key(key: string): string;
|
|
26
|
+
private toggle;
|
|
27
|
+
private get calculate();
|
|
28
|
+
}
|
package/games/TSPool.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TSPool = void 0;
|
|
4
|
+
var TSNumber_1 = require("../utils/TSNumber");
|
|
5
|
+
var TSObject_1 = require("../utils/TSObject");
|
|
6
|
+
var TSString_1 = require("../utils/TSString");
|
|
7
|
+
var TSPool = /** @class */ (function () {
|
|
8
|
+
function TSPool(params) {
|
|
9
|
+
this.params = params;
|
|
10
|
+
this.items = [];
|
|
11
|
+
this.selected = {};
|
|
12
|
+
if (!this.params.reserve) {
|
|
13
|
+
this.params.reserve = [];
|
|
14
|
+
}
|
|
15
|
+
this.options = this.params;
|
|
16
|
+
this.items = this.options.matches.concat(this.options.reserve);
|
|
17
|
+
this.options.size = this.items.length;
|
|
18
|
+
void this.calculate;
|
|
19
|
+
}
|
|
20
|
+
TSPool.prototype.toggleLine = function (k) {
|
|
21
|
+
this.toggle(k);
|
|
22
|
+
return this.calculate;
|
|
23
|
+
};
|
|
24
|
+
TSPool.prototype.favoriteLines = function (kItem, property) {
|
|
25
|
+
if (kItem === void 0) { kItem = 'oc'; }
|
|
26
|
+
if (property === void 0) { property = 'o'; }
|
|
27
|
+
this.clearLines();
|
|
28
|
+
for (var _i = 0, _a = this.items; _i < _a.length; _i++) {
|
|
29
|
+
var i = _a[_i];
|
|
30
|
+
var min = i[kItem].reduce(function (m, c, ci, pool) { return c[property] < pool[m][property] ? ci : m; }, 0);
|
|
31
|
+
this.toggle(i[kItem][min].sk);
|
|
32
|
+
}
|
|
33
|
+
return this.calculate;
|
|
34
|
+
};
|
|
35
|
+
TSPool.prototype.randomLines = function (kItem) {
|
|
36
|
+
if (kItem === void 0) { kItem = 'oc'; }
|
|
37
|
+
this.clearLines();
|
|
38
|
+
for (var _i = 0, _a = this.items; _i < _a.length; _i++) {
|
|
39
|
+
var i = _a[_i];
|
|
40
|
+
var k = TSNumber_1.TSNumber.random(0, i[kItem].length - 1);
|
|
41
|
+
this.toggle(i[kItem][k].sk);
|
|
42
|
+
}
|
|
43
|
+
return this.calculate;
|
|
44
|
+
};
|
|
45
|
+
TSPool.prototype.clearLines = function () {
|
|
46
|
+
this.selected = {};
|
|
47
|
+
return this.calculate;
|
|
48
|
+
};
|
|
49
|
+
TSPool.prototype.key = function (key) {
|
|
50
|
+
return TSString_1.TSString.splitBy(key, '_', 'first')[0];
|
|
51
|
+
};
|
|
52
|
+
TSPool.prototype.toggle = function (k) {
|
|
53
|
+
var key = this.key(k);
|
|
54
|
+
if (!this.selected[key]) {
|
|
55
|
+
this.selected[key] = [k];
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
var iIndex = this.selected[key].findIndex(function (v) { return v === k; });
|
|
59
|
+
if (iIndex !== -1) {
|
|
60
|
+
this.selected[key].splice(iIndex, 1);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this.selected[key].push(k);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
Object.defineProperty(TSPool.prototype, "calculate", {
|
|
68
|
+
get: function () {
|
|
69
|
+
var lines = TSObject_1.TSObject.value(this.selected) ? 1 : 0, size = 0;
|
|
70
|
+
TSObject_1.TSObject.forOwn(this.selected, function (v) {
|
|
71
|
+
if (v.length) {
|
|
72
|
+
lines *= v.length;
|
|
73
|
+
size++;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
this.result = {
|
|
77
|
+
stake: this.options.stake, amount: this.options.stake * lines,
|
|
78
|
+
lines: lines,
|
|
79
|
+
selected: this.selected, completed: size === this.options.size
|
|
80
|
+
};
|
|
81
|
+
return this.result;
|
|
82
|
+
},
|
|
83
|
+
enumerable: false,
|
|
84
|
+
configurable: true
|
|
85
|
+
});
|
|
86
|
+
return TSPool;
|
|
87
|
+
}());
|
|
88
|
+
exports.TSPool = TSPool;
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ts-client-lib",
|
|
3
|
+
"version": "0.0.7",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"prepublishOnly": "npm run build",
|
|
6
|
+
"postpublish": "npm run clean:artifacts",
|
|
7
|
+
"build": "tsc --declaration -p .",
|
|
8
|
+
"watch": "tsc -w --declaration -p .",
|
|
9
|
+
"clean:artifacts": "node -e \"const fs=require('fs'),path=require('path');const root=process.cwd();for(const rel of ['auth','devices','entities','finance','games','utils']){const dir=path.join(root,rel);let n;try{n=fs.readdirSync(dir)}catch{continue}for(const name of n){if(!name.endsWith('.d.ts')&&path.extname(name)!=='.js')continue;const fp=path.join(dir,name);try{if(fs.statSync(fp).isFile())fs.unlinkSync(fp)}catch{}}}\"",
|
|
10
|
+
"clean:deps": "node -e \"for(const p of ['coverage','node_modules','package-lock.json'])try{require('fs').rmSync(p,{recursive:true,force:true})}catch{}\"",
|
|
11
|
+
"clean": "npm run clean:artifacts && npm run clean:deps",
|
|
12
|
+
"lint": "eslint . --fix --ignore-pattern \"**/*.d.ts\"",
|
|
13
|
+
"test": "npm run build && vitest run",
|
|
14
|
+
"test:watch": "vitest",
|
|
15
|
+
"test:coverage": "vitest run --coverage"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/onalbi/ts-client-lib"
|
|
20
|
+
},
|
|
21
|
+
"author": {
|
|
22
|
+
"name": "Albion Liçi",
|
|
23
|
+
"email": "lici.albion@gmail.com"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"typescript",
|
|
27
|
+
"cordova",
|
|
28
|
+
"cache",
|
|
29
|
+
"heuristic"
|
|
30
|
+
],
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/onalbi/ts-client-lib/issues"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"auth/**/*.{js,d.ts}",
|
|
37
|
+
"devices/**/*.{js,d.ts}",
|
|
38
|
+
"entities/**/*.{js,d.ts}",
|
|
39
|
+
"finance/**/*.{js,d.ts}",
|
|
40
|
+
"games/**/*.{js,d.ts}",
|
|
41
|
+
"utils/**/*.{js,d.ts}"
|
|
42
|
+
],
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"reflect-metadata": "^0.2.2"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"ts-common-lib": "latest"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"reflect-metadata": "^0.2.2"
|
|
51
|
+
},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=20.12.1"
|
|
54
|
+
},
|
|
55
|
+
"vitest": {
|
|
56
|
+
"globals": true,
|
|
57
|
+
"environment": "node",
|
|
58
|
+
"include": [
|
|
59
|
+
"test/**/*.spec.ts"
|
|
60
|
+
],
|
|
61
|
+
"exclude": [
|
|
62
|
+
"**/*.spec.js",
|
|
63
|
+
"**/node_modules/**"
|
|
64
|
+
],
|
|
65
|
+
"resolve": {
|
|
66
|
+
"extensions": [
|
|
67
|
+
".ts",
|
|
68
|
+
".tsx",
|
|
69
|
+
".mts",
|
|
70
|
+
".cts",
|
|
71
|
+
".js",
|
|
72
|
+
".mjs",
|
|
73
|
+
".jsx",
|
|
74
|
+
".json"
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
"coverage": {
|
|
78
|
+
"provider": "v8",
|
|
79
|
+
"include": [
|
|
80
|
+
"auth/**/*.ts",
|
|
81
|
+
"devices/**/*.ts",
|
|
82
|
+
"entities/**/*.ts",
|
|
83
|
+
"finance/**/*.ts",
|
|
84
|
+
"games/**/*.ts",
|
|
85
|
+
"utils/**/*.ts"
|
|
86
|
+
],
|
|
87
|
+
"reporter": [
|
|
88
|
+
"text",
|
|
89
|
+
"lcov"
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class TSArray {
|
|
2
|
+
static indexOfPartial(items: Array<string> | undefined, needle: string): number;
|
|
3
|
+
static shuffle(array: any[]): any[];
|
|
4
|
+
static fn(compare: (value: any) => any, order?: 'asc' | 'desc'): (a: any, b: any) => 1 | -1 | 0;
|
|
5
|
+
static sort(reverse?: boolean, path?: string): (a: any, b: any) => 1 | -1 | 0;
|
|
6
|
+
static toPair(array: Array<any>): Record<string, unknown>;
|
|
7
|
+
private static compare;
|
|
8
|
+
private static g;
|
|
9
|
+
}
|
package/utils/TSArray.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TSArray = void 0;
|
|
4
|
+
var TSArray = /** @class */ (function () {
|
|
5
|
+
function TSArray() {
|
|
6
|
+
}
|
|
7
|
+
TSArray.indexOfPartial = function (items, needle) {
|
|
8
|
+
if (items === void 0) { items = []; }
|
|
9
|
+
for (var i in items) {
|
|
10
|
+
if (Object.hasOwn(items, i) && needle.indexOf(items[i]) !== -1) {
|
|
11
|
+
return parseInt(i, 10);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return -1;
|
|
15
|
+
};
|
|
16
|
+
TSArray.shuffle = function (array) {
|
|
17
|
+
var _a;
|
|
18
|
+
for (var i = array.length - 1; i > 0; i--) {
|
|
19
|
+
var j = Math.floor(Math.random() * (i + 1));
|
|
20
|
+
_a = [array[j], array[i]], array[i] = _a[0], array[j] = _a[1];
|
|
21
|
+
}
|
|
22
|
+
return array;
|
|
23
|
+
};
|
|
24
|
+
TSArray.fn = function (compare, order) {
|
|
25
|
+
if (order === void 0) { order = 'desc'; }
|
|
26
|
+
if (order === 'asc') {
|
|
27
|
+
return function (a, b) {
|
|
28
|
+
var va = compare(a), vb = compare(b);
|
|
29
|
+
if (vb > va)
|
|
30
|
+
return -1;
|
|
31
|
+
if (va > vb)
|
|
32
|
+
return 1;
|
|
33
|
+
return 0;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return function (a, b) {
|
|
37
|
+
var va = compare(a), vb = compare(b);
|
|
38
|
+
if (va > vb)
|
|
39
|
+
return -1;
|
|
40
|
+
if (vb > va)
|
|
41
|
+
return 1;
|
|
42
|
+
return 0;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
TSArray.sort = function (reverse, path) {
|
|
46
|
+
var p = path !== null && path !== void 0 ? path : '';
|
|
47
|
+
return function (a, b) { return reverse ? TSArray.compare(a, b, p) : TSArray.compare(b, a, p); };
|
|
48
|
+
};
|
|
49
|
+
TSArray.toPair = function (array) {
|
|
50
|
+
var r = {};
|
|
51
|
+
for (var i = 0; i < array.length; i += 2) {
|
|
52
|
+
r[array[i]] = array[i + 1];
|
|
53
|
+
}
|
|
54
|
+
return r;
|
|
55
|
+
};
|
|
56
|
+
TSArray.compare = function (a, b, p) {
|
|
57
|
+
if (p) {
|
|
58
|
+
var gb = TSArray.g(b, p), ga = TSArray.g(a, p);
|
|
59
|
+
if (gb < ga)
|
|
60
|
+
return -1;
|
|
61
|
+
if (gb > ga)
|
|
62
|
+
return 1;
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
if (b < a)
|
|
66
|
+
return -1;
|
|
67
|
+
if (b > a)
|
|
68
|
+
return 1;
|
|
69
|
+
return 0;
|
|
70
|
+
};
|
|
71
|
+
TSArray.g = function (object, path) {
|
|
72
|
+
var a = path.split('.');
|
|
73
|
+
while (a.length) {
|
|
74
|
+
var key = a.shift();
|
|
75
|
+
if (key === undefined) {
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
object = object[key];
|
|
79
|
+
if (!object) {
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return object;
|
|
84
|
+
};
|
|
85
|
+
return TSArray;
|
|
86
|
+
}());
|
|
87
|
+
exports.TSArray = TSArray;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TSBoolean = void 0;
|
|
4
|
+
var TSBoolean = /** @class */ (function () {
|
|
5
|
+
function TSBoolean() {
|
|
6
|
+
}
|
|
7
|
+
TSBoolean.parse = function (v) {
|
|
8
|
+
if (typeof v === 'boolean') {
|
|
9
|
+
return v;
|
|
10
|
+
}
|
|
11
|
+
else if (/^\s*(true|1|on|yes|y)\s*$/i.test(v)) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
else if (/^\s*(false|0|off|no|n)\s*$/i.test(v)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return v;
|
|
18
|
+
};
|
|
19
|
+
TSBoolean.isEmpty = function (v) {
|
|
20
|
+
return v == null || /^\s*(null|undefined)\s*$/i.test(v);
|
|
21
|
+
};
|
|
22
|
+
return TSBoolean;
|
|
23
|
+
}());
|
|
24
|
+
exports.TSBoolean = TSBoolean;
|