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/utils/TSLog.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
/**
|
|
3
|
+
* Log instance of a class
|
|
4
|
+
*
|
|
5
|
+
* @example @TSLogClass
|
|
6
|
+
*
|
|
7
|
+
* @param target
|
|
8
|
+
* @constructor
|
|
9
|
+
*/
|
|
10
|
+
export declare function TSLogClass<T extends new (...args: any[]) => any>(target: T): T;
|
|
11
|
+
/**
|
|
12
|
+
* Log and measure performance of a function
|
|
13
|
+
*
|
|
14
|
+
* @example @TSLogMethod
|
|
15
|
+
*
|
|
16
|
+
* @param target
|
|
17
|
+
* @param key
|
|
18
|
+
* @param descriptor
|
|
19
|
+
* @constructor
|
|
20
|
+
*/
|
|
21
|
+
export declare function TSLogMethod(target: any, key: string, descriptor: PropertyDescriptor): PropertyDescriptor | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Log property state
|
|
24
|
+
*
|
|
25
|
+
* @example @TSLogProperty
|
|
26
|
+
*
|
|
27
|
+
* @param target
|
|
28
|
+
* @param key
|
|
29
|
+
* @constructor
|
|
30
|
+
*/
|
|
31
|
+
export declare function TSLogProperty(target: any, key: string): void;
|
|
32
|
+
/**
|
|
33
|
+
* Log factory that automatically detect kind signature
|
|
34
|
+
*
|
|
35
|
+
* @example @TSLog
|
|
36
|
+
*
|
|
37
|
+
* @param args
|
|
38
|
+
* @constructor
|
|
39
|
+
*/
|
|
40
|
+
export declare function TSLog(...args: Array<any>): void;
|
package/utils/TSLog.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TSLogClass = TSLogClass;
|
|
4
|
+
exports.TSLogMethod = TSLogMethod;
|
|
5
|
+
exports.TSLogProperty = TSLogProperty;
|
|
6
|
+
exports.TSLog = TSLog;
|
|
7
|
+
require("reflect-metadata");
|
|
8
|
+
/**
|
|
9
|
+
* Log instance of a class
|
|
10
|
+
*
|
|
11
|
+
* @example @TSLogClass
|
|
12
|
+
*
|
|
13
|
+
* @param target
|
|
14
|
+
* @constructor
|
|
15
|
+
*/
|
|
16
|
+
function TSLogClass(target) {
|
|
17
|
+
return function _a() {
|
|
18
|
+
var _newTarget = this && this instanceof _a ? this.constructor : void 0;
|
|
19
|
+
var args = [];
|
|
20
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
21
|
+
args[_i] = arguments[_i];
|
|
22
|
+
}
|
|
23
|
+
console.log("[TSLogClass::".concat(target.name, "] is created"));
|
|
24
|
+
return Reflect.construct(target, args, _newTarget);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Log and measure performance of a function
|
|
29
|
+
*
|
|
30
|
+
* @example @TSLogMethod
|
|
31
|
+
*
|
|
32
|
+
* @param target
|
|
33
|
+
* @param key
|
|
34
|
+
* @param descriptor
|
|
35
|
+
* @constructor
|
|
36
|
+
*/
|
|
37
|
+
function TSLogMethod(target, key, descriptor) {
|
|
38
|
+
if (descriptor) {
|
|
39
|
+
var method_1 = descriptor.value;
|
|
40
|
+
descriptor.value = function () {
|
|
41
|
+
var args = [];
|
|
42
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
43
|
+
args[_i] = arguments[_i];
|
|
44
|
+
}
|
|
45
|
+
var measure = function () { return (typeof performance !== 'undefined' ? performance.now() : Number(new Date())); }, start = measure(), params = args.map(function (a) { return JSON.stringify(a); }).join(), result = method_1.apply(this, args);
|
|
46
|
+
console.log("[TSLogMethod::".concat(key, "] (").concat(params, ") => ").concat(JSON.stringify(result, null, 2)));
|
|
47
|
+
console.log("[TSLogMethod::".concat(key, "] stats: ").concat((measure() - start).toFixed(2), " ms"));
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
50
|
+
return descriptor;
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Log property state
|
|
56
|
+
*
|
|
57
|
+
* @example @TSLogProperty
|
|
58
|
+
*
|
|
59
|
+
* @param target
|
|
60
|
+
* @param key
|
|
61
|
+
* @constructor
|
|
62
|
+
*/
|
|
63
|
+
function TSLogProperty(target, key) {
|
|
64
|
+
var v = target[key];
|
|
65
|
+
var t = Reflect.getMetadata('design:type', target, key);
|
|
66
|
+
var getter = function () {
|
|
67
|
+
console.log("[TSLogProperty::Get:".concat(t.name, "] ").concat(key, " => ").concat(JSON.stringify(v, null, 2)));
|
|
68
|
+
return v;
|
|
69
|
+
};
|
|
70
|
+
var setter = function (nv) {
|
|
71
|
+
console.log("[TSLogProperty::Set:".concat(t.name, "] ").concat(key, " => ").concat(JSON.stringify(nv, null, 2)));
|
|
72
|
+
v = nv;
|
|
73
|
+
};
|
|
74
|
+
if (delete target[key]) {
|
|
75
|
+
Object.defineProperty(target, key, {
|
|
76
|
+
get: getter, set: setter, enumerable: true, configurable: true
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Log factory that automatically detect kind signature
|
|
82
|
+
*
|
|
83
|
+
* @example @TSLog
|
|
84
|
+
*
|
|
85
|
+
* @param args
|
|
86
|
+
* @constructor
|
|
87
|
+
*/
|
|
88
|
+
function TSLog() {
|
|
89
|
+
var args = [];
|
|
90
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
91
|
+
args[_i] = arguments[_i];
|
|
92
|
+
}
|
|
93
|
+
switch (args.length) {
|
|
94
|
+
case 3:
|
|
95
|
+
if (typeof args[2] === 'undefined') {
|
|
96
|
+
TSLogProperty.apply(void 0, args);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
TSLogMethod.apply(void 0, args);
|
|
100
|
+
return;
|
|
101
|
+
case 2:
|
|
102
|
+
TSLogProperty.apply(void 0, args);
|
|
103
|
+
return;
|
|
104
|
+
case 1:
|
|
105
|
+
TSLogClass.apply(void 0, args);
|
|
106
|
+
return;
|
|
107
|
+
default:
|
|
108
|
+
throw new Error('Not a valid decorator');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TSNumber = void 0;
|
|
4
|
+
var TSNumber = /** @class */ (function () {
|
|
5
|
+
function TSNumber() {
|
|
6
|
+
}
|
|
7
|
+
TSNumber.roundBy = function (n, d, type) {
|
|
8
|
+
if (d === void 0) { d = 5; }
|
|
9
|
+
if (type === void 0) { type = 'round'; }
|
|
10
|
+
return Math[type](n / d) * d;
|
|
11
|
+
};
|
|
12
|
+
TSNumber.random = function (from, to) {
|
|
13
|
+
return Math.floor(from + (Math.random() * (to - from + 1)));
|
|
14
|
+
};
|
|
15
|
+
TSNumber.humanize = function (number, options) {
|
|
16
|
+
if (options === void 0) { options = {}; }
|
|
17
|
+
options = options || {};
|
|
18
|
+
var result;
|
|
19
|
+
if (Object.hasOwn(options, 'unit')) {
|
|
20
|
+
return TSNumber.humanizeWithUnit(number, options);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
var d = options.delimiter || ',';
|
|
24
|
+
var s = options.separator || '.';
|
|
25
|
+
var f = options.fixed || 3;
|
|
26
|
+
result = number.toString().split('.');
|
|
27
|
+
result[0] = result[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1' + d);
|
|
28
|
+
if (result[1]) {
|
|
29
|
+
result[1] = result[1].substring(0, f);
|
|
30
|
+
}
|
|
31
|
+
if (d === s) {
|
|
32
|
+
return result[0];
|
|
33
|
+
}
|
|
34
|
+
return result.join(s);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
TSNumber.humanizeWithUnit = function (number, options) {
|
|
38
|
+
var s = options.separator || '';
|
|
39
|
+
var result = parseInt(number.toString(), 10);
|
|
40
|
+
var cultureTable = {
|
|
41
|
+
en: {
|
|
42
|
+
'': ['', 0], 'Thousand': ['K', 3], 'Million': ['M', 6], 'Billion': ['B', 9],
|
|
43
|
+
'Trillion': ['T', 12], 'Quadrillion': ['q', 15], 'Quintillion': ['Q', 18]
|
|
44
|
+
},
|
|
45
|
+
fr: {
|
|
46
|
+
'': ['', 0], 'Mille': ['K', 3], 'Million': ['M', 6], 'Milliard': ['Md', 9],
|
|
47
|
+
'Mille Milliards': ['T', 12], 'Quadrillion': ['q', 15], 'Quintillion': ['Q', 18]
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var cultures = cultureTable[options.culture || 'en'] || cultureTable.en;
|
|
51
|
+
var zeroes = 0;
|
|
52
|
+
var sM = {};
|
|
53
|
+
var lM = {};
|
|
54
|
+
for (var c in cultures) {
|
|
55
|
+
if (Object.hasOwn(cultures, c)) {
|
|
56
|
+
sM[c] = cultures[c][0];
|
|
57
|
+
lM[cultures[c][1]] = c;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
while (parseInt((result / 1000).toString(), 10) !== 0) {
|
|
61
|
+
result /= 1000;
|
|
62
|
+
zeroes += 3;
|
|
63
|
+
}
|
|
64
|
+
return [!options.fixed ? Math.floor(result) : result.toFixed(options.fixed), options.unit !== 'long' ? sM[lM[zeroes]] : lM[zeroes]].join(s);
|
|
65
|
+
};
|
|
66
|
+
return TSNumber;
|
|
67
|
+
}());
|
|
68
|
+
exports.TSNumber = TSNumber;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare class TSObject {
|
|
2
|
+
static empty(object?: any): boolean;
|
|
3
|
+
static value(object?: any): any;
|
|
4
|
+
static fcAsKey(key: string): Record<string, string>;
|
|
5
|
+
static paths(text: string): RegExpMatchArray | null;
|
|
6
|
+
static property(text: string): string;
|
|
7
|
+
static propertyEscape(text: string): string;
|
|
8
|
+
static getBy(object: any, path: string, value?: null): any;
|
|
9
|
+
static setBy(o: any, s: any, path?: string): any;
|
|
10
|
+
static mergeBy(o: any, s: any, path?: string): any;
|
|
11
|
+
static updateBy(o: any, s: any, path?: string): any;
|
|
12
|
+
static deleteBy(object: any, pathToDelete: string, pathToReturn?: string): any;
|
|
13
|
+
static copyProperties(target: any, source: any, force?: boolean): void;
|
|
14
|
+
static cleanProperties(source: any, properties?: any): any;
|
|
15
|
+
static propertySet(o: any, k: string, v?: unknown): string;
|
|
16
|
+
static forOwn(object: any, callback: (v: any, k: string | number) => void): void;
|
|
17
|
+
static operateBy(o: any, s: any, type?: string, p0?: any, p1?: any, p2?: any, p3?: any): any;
|
|
18
|
+
private static operateByWorkDeep;
|
|
19
|
+
static workBy(o: any, s: any, type?: string): any;
|
|
20
|
+
static merge(target: any, source: any, full?: boolean): any;
|
|
21
|
+
static clone(object: any): any;
|
|
22
|
+
static flat(current: any, property?: string, paths?: string[], cb?: (id: unknown, data: Record<string, unknown>) => void): Record<string, unknown>;
|
|
23
|
+
static enumValues(entity: any, type?: 'string'): string[];
|
|
24
|
+
static enumValues(entity: any, type?: 'number'): number[];
|
|
25
|
+
static toDictionary(array: Array<any>, kName: string | number, vName: string | number, ...args: unknown[]): any;
|
|
26
|
+
static reduceObject(object: any, ...args: unknown[]): any;
|
|
27
|
+
static normalizeObject(object: any): any;
|
|
28
|
+
static valueOrArrayValue(object: any, key: string | number): any;
|
|
29
|
+
}
|
|
@@ -0,0 +1,312 @@
|
|
|
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 __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
+
var t = {};
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
+
t[p[i]] = s[p[i]];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
23
|
+
};
|
|
24
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
25
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
26
|
+
if (ar || !(i in from)) {
|
|
27
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
28
|
+
ar[i] = from[i];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.TSObject = void 0;
|
|
35
|
+
var TSObject = /** @class */ (function () {
|
|
36
|
+
function TSObject() {
|
|
37
|
+
}
|
|
38
|
+
TSObject.empty = function (object) {
|
|
39
|
+
if (object === void 0) { object = {}; }
|
|
40
|
+
for (var p in object) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
};
|
|
45
|
+
TSObject.value = function (object) {
|
|
46
|
+
if (object === void 0) { object = {}; }
|
|
47
|
+
for (var p in object) {
|
|
48
|
+
return object[p];
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
};
|
|
52
|
+
TSObject.fcAsKey = function (key) {
|
|
53
|
+
return key.split('|').reduce(function (a, c) { return (a[c.charAt(0)] = c.substring(1), a); }, {});
|
|
54
|
+
};
|
|
55
|
+
TSObject.paths = function (text) {
|
|
56
|
+
return text.match(/(?:\\.|[^.])+/g);
|
|
57
|
+
};
|
|
58
|
+
TSObject.property = function (text) {
|
|
59
|
+
return text.replace(/\\./g, '.');
|
|
60
|
+
};
|
|
61
|
+
TSObject.propertyEscape = function (text) {
|
|
62
|
+
return text.replace(/\./g, '\\.');
|
|
63
|
+
};
|
|
64
|
+
TSObject.getBy = function (object, path, value) {
|
|
65
|
+
if (value === void 0) { value = null; }
|
|
66
|
+
var a = TSObject.paths(path);
|
|
67
|
+
if (!a)
|
|
68
|
+
return value;
|
|
69
|
+
while (a.length && (object = object[TSObject.property(a.shift())])) { /** Walk on object */ }
|
|
70
|
+
return ['null', 'undefined'].indexOf(typeof object) === -1 ? object : value;
|
|
71
|
+
};
|
|
72
|
+
TSObject.setBy = function (o, s, path) {
|
|
73
|
+
return TSObject.operateBy.apply(TSObject, __spreadArray([o, s, 'set'], (path ? path.split('.') : []), false));
|
|
74
|
+
};
|
|
75
|
+
TSObject.mergeBy = function (o, s, path) {
|
|
76
|
+
return TSObject.operateBy.apply(TSObject, __spreadArray([o, s, 'merge'], (path ? path.split('.') : []), false));
|
|
77
|
+
};
|
|
78
|
+
TSObject.updateBy = function (o, s, path) {
|
|
79
|
+
return TSObject.operateBy.apply(TSObject, __spreadArray([o, s, 'update'], (path ? path.split('.') : []), false));
|
|
80
|
+
};
|
|
81
|
+
TSObject.deleteBy = function (object, pathToDelete, pathToReturn) {
|
|
82
|
+
if (pathToReturn === void 0) { pathToReturn = ''; }
|
|
83
|
+
var path = function (p) { var _a; return ((_a = TSObject.paths(p)) !== null && _a !== void 0 ? _a : []).map(function (p) { return "?.['".concat(TSObject.property(p), "']"); }).join(''); };
|
|
84
|
+
if (!pathToReturn.length && pathToDelete.indexOf(pathToReturn) !== 0) {
|
|
85
|
+
pathToReturn = '';
|
|
86
|
+
}
|
|
87
|
+
else if (pathToReturn.length) {
|
|
88
|
+
pathToReturn = path(pathToReturn);
|
|
89
|
+
}
|
|
90
|
+
return new Function('_', "delete _".concat(path(pathToDelete), ";return _").concat(pathToReturn, ";"))(object);
|
|
91
|
+
};
|
|
92
|
+
TSObject.copyProperties = function (target, source, force) {
|
|
93
|
+
TSObject.forOwn(source, function (v, k) {
|
|
94
|
+
if (Object.hasOwn(target, k) || force) {
|
|
95
|
+
target[k] = source[k];
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
TSObject.cleanProperties = function (source, properties) {
|
|
100
|
+
if (properties === void 0) { properties = []; }
|
|
101
|
+
TSObject.forOwn(source, function (v, k) {
|
|
102
|
+
if ([null, '', undefined, NaN].indexOf(source[k]) > -1 ||
|
|
103
|
+
Array.isArray(source[k]) && !source[k].length ||
|
|
104
|
+
typeof source[k] === 'object' && TSObject.empty(source[k])) {
|
|
105
|
+
delete source[k];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
TSObject.forOwn(properties, function (v) {
|
|
109
|
+
if (Object.hasOwn(source, v)) {
|
|
110
|
+
delete source[v];
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
return source;
|
|
114
|
+
};
|
|
115
|
+
TSObject.propertySet = function (o, k, v) {
|
|
116
|
+
var keys = k.split(',');
|
|
117
|
+
for (var i = 0; i < keys.length; i++) {
|
|
118
|
+
if (typeof v !== 'undefined' && o && Object.hasOwn(o, keys[i]) && o[keys[i]] === v) {
|
|
119
|
+
return v;
|
|
120
|
+
}
|
|
121
|
+
else if (o && o[keys[i]]) {
|
|
122
|
+
return keys[i];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return keys[keys.length - 1];
|
|
126
|
+
};
|
|
127
|
+
TSObject.forOwn = function (object, callback) {
|
|
128
|
+
for (var k in object) {
|
|
129
|
+
if (Object.hasOwn(object, k)) {
|
|
130
|
+
callback(object[k], k);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
TSObject.operateBy = function (o, s, type, p0, p1, p2, p3) {
|
|
135
|
+
if (type === void 0) { type = 'merge'; }
|
|
136
|
+
if (!p0) {
|
|
137
|
+
return TSObject.workBy(o, s, type);
|
|
138
|
+
}
|
|
139
|
+
if (!o[p0]) {
|
|
140
|
+
o[p0] = s;
|
|
141
|
+
return o;
|
|
142
|
+
}
|
|
143
|
+
if (p1 && !o[p0][p1]) {
|
|
144
|
+
o[p0][p1] = s;
|
|
145
|
+
return o;
|
|
146
|
+
}
|
|
147
|
+
if (p2 && !o[p0][p1][p2]) {
|
|
148
|
+
o[p0][p1][p2] = s;
|
|
149
|
+
return o;
|
|
150
|
+
}
|
|
151
|
+
if (p3 && !o[p0][p1][p2][p3]) {
|
|
152
|
+
o[p0][p1][p2][p3] = s;
|
|
153
|
+
return o;
|
|
154
|
+
}
|
|
155
|
+
return TSObject.operateByWorkDeep(o, s, type, p0, p1, p2, p3);
|
|
156
|
+
};
|
|
157
|
+
TSObject.operateByWorkDeep = function (o, s, type, p0, p1, p2, p3) {
|
|
158
|
+
if (o[p0] && o[p0][p1] && o[p0][p1][p2] && o[p0][p1][p2][p3]) {
|
|
159
|
+
o[p0][p1][p2][p3] = TSObject.workBy(o[p0][p1][p2][p3], s, type);
|
|
160
|
+
return o;
|
|
161
|
+
}
|
|
162
|
+
if (o[p0] && o[p0][p1] && o[p0][p1][p2]) {
|
|
163
|
+
o[p0][p1][p2] = TSObject.workBy(o[p0][p1][p2], s, type);
|
|
164
|
+
return o;
|
|
165
|
+
}
|
|
166
|
+
if (o[p0] && o[p0][p1]) {
|
|
167
|
+
o[p0][p1] = TSObject.workBy(o[p0][p1], s, type);
|
|
168
|
+
return o;
|
|
169
|
+
}
|
|
170
|
+
if (o[p0]) {
|
|
171
|
+
o[p0] = TSObject.workBy(o[p0], s, type);
|
|
172
|
+
}
|
|
173
|
+
return o;
|
|
174
|
+
};
|
|
175
|
+
TSObject.workBy = function (o, s, type) {
|
|
176
|
+
if (type === void 0) { type = 'merge'; }
|
|
177
|
+
if (type === 'merge') {
|
|
178
|
+
return TSObject.merge(o, s);
|
|
179
|
+
}
|
|
180
|
+
else if (type === 'update') {
|
|
181
|
+
return __assign(__assign({}, o), s);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
return s;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
TSObject.merge = function (target, source, full) {
|
|
188
|
+
if (full === void 0) { full = true; }
|
|
189
|
+
if (!source) {
|
|
190
|
+
return target;
|
|
191
|
+
}
|
|
192
|
+
for (var _i = 0, _a = Object.keys(source); _i < _a.length; _i++) {
|
|
193
|
+
var key = _a[_i];
|
|
194
|
+
if (target[key] instanceof Object && source[key] instanceof Object && key in target) {
|
|
195
|
+
if (full) {
|
|
196
|
+
Object.assign(source[key], TSObject.merge(target[key], source[key], full));
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
TSObject.merge(target[key], source[key], full);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
else if (source[key] instanceof Object && key in target) {
|
|
203
|
+
target[key] = source[key];
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
Object.assign(target || {}, source);
|
|
207
|
+
return target;
|
|
208
|
+
};
|
|
209
|
+
TSObject.clone = function (object) {
|
|
210
|
+
var cloned = (object && object.constructor) ? new object.constructor() : {};
|
|
211
|
+
for (var attribute in object) {
|
|
212
|
+
if (Array.isArray(object[attribute])) {
|
|
213
|
+
cloned[attribute] = object[attribute].slice(0);
|
|
214
|
+
}
|
|
215
|
+
else if (typeof object[attribute] === 'object') {
|
|
216
|
+
cloned[attribute] = TSObject.clone(object[attribute]);
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
cloned[attribute] = object[attribute];
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return cloned;
|
|
223
|
+
};
|
|
224
|
+
TSObject.flat = function (current, property, paths, cb) {
|
|
225
|
+
if (property === void 0) { property = 'k'; }
|
|
226
|
+
if (paths === void 0) { paths = ['s', 'c', 't', 'e']; }
|
|
227
|
+
var result = {}, stack = [{ current: current, path: {} }];
|
|
228
|
+
var _loop_1 = function () {
|
|
229
|
+
var item = stack.pop();
|
|
230
|
+
if (!item)
|
|
231
|
+
return "continue";
|
|
232
|
+
var current_1 = item.current, path = item.path;
|
|
233
|
+
if (typeof current_1 !== 'object' || current_1 === null)
|
|
234
|
+
return "continue";
|
|
235
|
+
var keys = Object.keys(current_1);
|
|
236
|
+
if (keys.length === 0)
|
|
237
|
+
return "continue";
|
|
238
|
+
if (property in current_1) {
|
|
239
|
+
var _a = path, _b = paths[paths.length - 1], id = _a[_b], rest = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
240
|
+
if (cb) {
|
|
241
|
+
cb(id, __assign(__assign({}, rest), current_1));
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
result[String(id)] = __assign(__assign({}, rest), current_1);
|
|
245
|
+
}
|
|
246
|
+
return "continue";
|
|
247
|
+
}
|
|
248
|
+
keys.forEach(function (k) {
|
|
249
|
+
var p = __assign({}, path);
|
|
250
|
+
for (var i = 0; i < paths.length; i++) {
|
|
251
|
+
if (!path[paths[i]]) {
|
|
252
|
+
p[paths[i]] = k;
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
stack.push({ current: current_1[k], path: p });
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
while (stack.length > 0) {
|
|
260
|
+
_loop_1();
|
|
261
|
+
}
|
|
262
|
+
return result;
|
|
263
|
+
};
|
|
264
|
+
TSObject.enumValues = function (entity, type) {
|
|
265
|
+
if (type === void 0) { type = 'string'; }
|
|
266
|
+
var values = [];
|
|
267
|
+
for (var i in entity) {
|
|
268
|
+
if (type === 'number' && !isNaN(Number([entity[i]])) || type === 'string' && typeof entity[i] === 'string') {
|
|
269
|
+
values.push(entity[i]);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return values;
|
|
273
|
+
};
|
|
274
|
+
/* --------- [XML] --------- */
|
|
275
|
+
TSObject.toDictionary = function (array, kName, vName) {
|
|
276
|
+
var args = [];
|
|
277
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
|
278
|
+
args[_i - 3] = arguments[_i];
|
|
279
|
+
}
|
|
280
|
+
var result = {};
|
|
281
|
+
var value;
|
|
282
|
+
for (var i in array) {
|
|
283
|
+
if (array[i] != null) {
|
|
284
|
+
value = this.valueOrArrayValue(array[i], vName);
|
|
285
|
+
result[this.valueOrArrayValue(array[i], kName)] = !args ? value : TSObject.reduceObject.apply(TSObject, __spreadArray([value], args, false));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return result;
|
|
289
|
+
};
|
|
290
|
+
TSObject.reduceObject = function (object) {
|
|
291
|
+
var args = [];
|
|
292
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
293
|
+
args[_i - 1] = arguments[_i];
|
|
294
|
+
}
|
|
295
|
+
for (var i = 0; i < args.length; i++) {
|
|
296
|
+
var key = args[i];
|
|
297
|
+
if (Object.hasOwn(object, key)) {
|
|
298
|
+
object = TSObject.valueOrArrayValue(object, key);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return object;
|
|
302
|
+
};
|
|
303
|
+
TSObject.normalizeObject = function (object) {
|
|
304
|
+
TSObject.forOwn(object, function (v, k) { return object[k] = TSObject.valueOrArrayValue(object, k); });
|
|
305
|
+
return object;
|
|
306
|
+
};
|
|
307
|
+
TSObject.valueOrArrayValue = function (object, key) {
|
|
308
|
+
return Array.isArray(object[key]) ? object[key][0] : object[key];
|
|
309
|
+
};
|
|
310
|
+
return TSObject;
|
|
311
|
+
}());
|
|
312
|
+
exports.TSObject = TSObject;
|