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/TSDate.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TSDate = void 0;
|
|
4
|
+
var TSString_1 = require("./TSString");
|
|
5
|
+
var TSDate = /** @class */ (function () {
|
|
6
|
+
function TSDate() {
|
|
7
|
+
}
|
|
8
|
+
TSDate.utc = function (type, data, set) {
|
|
9
|
+
if (['Milliseconds', 'Seconds', 'Minutes', 'Hours', 'Date', 'Month', 'FullYear'].indexOf(type) === -1) {
|
|
10
|
+
throw Error("[TSDate::utc] Type (".concat(type, ") not supported."));
|
|
11
|
+
}
|
|
12
|
+
var date = new Date();
|
|
13
|
+
var anyDate = date;
|
|
14
|
+
if (set) {
|
|
15
|
+
anyDate['setUTC' + type].apply(anyDate, set);
|
|
16
|
+
}
|
|
17
|
+
anyDate['setUTC' + type](anyDate['getUTC' + type]() + data);
|
|
18
|
+
return date;
|
|
19
|
+
};
|
|
20
|
+
TSDate.key = function (max, date) {
|
|
21
|
+
if (max === void 0) { max = 12; }
|
|
22
|
+
if (date === void 0) { date = new Date(); }
|
|
23
|
+
return date.toISOString().replace(/[^0-9]/g, '').substring(0, max);
|
|
24
|
+
};
|
|
25
|
+
TSDate.parse = function (date, data, set) {
|
|
26
|
+
if (data === void 0) { data = 0; }
|
|
27
|
+
if (set === void 0) { set = [24, 0, 0, 0]; }
|
|
28
|
+
var dts = Date.parse(date);
|
|
29
|
+
if (isNaN(dts)) {
|
|
30
|
+
return TSDate.utc('Hours', data, set).toISOString();
|
|
31
|
+
}
|
|
32
|
+
return new Date(date).toISOString();
|
|
33
|
+
};
|
|
34
|
+
TSDate.yyyymmddhhss = function (date) {
|
|
35
|
+
var parts = date.toString().match(/\d{2}/g);
|
|
36
|
+
if (!parts || parts.length < 6) {
|
|
37
|
+
return new Date(NaN);
|
|
38
|
+
}
|
|
39
|
+
var y1 = parts[0], y2 = parts[1], m = parts[2], d = parts[3], h = parts[4], mm = parts[5];
|
|
40
|
+
return new Date("".concat(y1).concat(y2, "-").concat(m, "-").concat(d, "T").concat(h, ":").concat(mm, ":00.000Z"));
|
|
41
|
+
};
|
|
42
|
+
TSDate.format = function (timestamp, format, cb) {
|
|
43
|
+
if (timestamp === void 0) { timestamp = Date.now(); }
|
|
44
|
+
var d = new Date(timestamp), _a = d.toUTCString().split(/[\s+,:]+/), day = _a[0], date = _a[1], month = _a[2], year = _a[3], hours = _a[4], minutes = _a[5], seconds = _a[6], timezone = _a[7], data = { day: day, date: date, month: month, year: year, hours: hours, minutes: minutes, seconds: seconds, timezone: timezone };
|
|
45
|
+
data['_'] = d;
|
|
46
|
+
return TSString_1.TSString.parseAndReplace(format, cb ? cb(data) : data);
|
|
47
|
+
};
|
|
48
|
+
TSDate.timer = function (milliseconds, format, cb) {
|
|
49
|
+
var data = {
|
|
50
|
+
days: function (t) { return t / (1000 * 60 * 60 * 24); },
|
|
51
|
+
hours: function (t) { return (t / (1000 * 60 * 60)) % 24; },
|
|
52
|
+
minutes: function (t) { return (t / 1000 / 60) % 60; },
|
|
53
|
+
seconds: function (t) { return (t / 1000) % 60; }
|
|
54
|
+
};
|
|
55
|
+
for (var p in data) {
|
|
56
|
+
if (Object.hasOwn(data, p)) {
|
|
57
|
+
var fn = data[p];
|
|
58
|
+
if (typeof fn === 'function') {
|
|
59
|
+
data[p] = TSString_1.TSString.pad(Math.floor(fn(milliseconds)), 2, '0');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return TSString_1.TSString.parseAndReplace(format, cb ? cb(data) : data);
|
|
64
|
+
};
|
|
65
|
+
return TSDate;
|
|
66
|
+
}());
|
|
67
|
+
exports.TSDate = TSDate;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class TSHeuristic - Holds static functions to deal with Heuristic
|
|
3
|
+
*/
|
|
4
|
+
export declare class TSHeuristic {
|
|
5
|
+
static levenshtein(str1: string, str2: string): number;
|
|
6
|
+
private static levenshteinStepRow;
|
|
7
|
+
static sift4(s1: string, s2: string, maxOffset: number, maxDistance?: number): number;
|
|
8
|
+
private static sift4OnMatch;
|
|
9
|
+
private static sift4OnMismatch;
|
|
10
|
+
/** Increment cursors, optional early exit when distance exceeds maxDistance, normalize at string end. */
|
|
11
|
+
private static sift4StepCursors;
|
|
12
|
+
/** Updates transposition bookkeeping when characters match. */
|
|
13
|
+
private static sift4ProcessOffsets;
|
|
14
|
+
/** Try nearby columns when current chars differ (Sift4 local search). */
|
|
15
|
+
private static sift4ShiftCursorsForNearMatch;
|
|
16
|
+
static getHeuristicDistance(s1?: string, s2?: string): number;
|
|
17
|
+
static distance(s1?: string, s2?: string): number;
|
|
18
|
+
static similarity(s1: string, s2: string): number;
|
|
19
|
+
static removeDiacritics(str: string): string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Class TSHeuristic - Holds static functions to deal with Heuristic
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TSHeuristic = void 0;
|
|
7
|
+
var diacritics_removal_map_1 = require("./diacritics-removal-map");
|
|
8
|
+
var TSHeuristic = /** @class */ (function () {
|
|
9
|
+
function TSHeuristic() {
|
|
10
|
+
}
|
|
11
|
+
TSHeuristic.levenshtein = function (str1, str2) {
|
|
12
|
+
// base cases
|
|
13
|
+
if (str1 === str2) {
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
if (str1.length === 0) {
|
|
17
|
+
return str2.length;
|
|
18
|
+
}
|
|
19
|
+
if (str2.length === 0) {
|
|
20
|
+
return str1.length;
|
|
21
|
+
}
|
|
22
|
+
// two rows
|
|
23
|
+
var prevRow = new Array(str2.length + 1);
|
|
24
|
+
var nextCol = 0, i, j;
|
|
25
|
+
// initialise previous row
|
|
26
|
+
for (i = 0; i < prevRow.length; ++i) {
|
|
27
|
+
prevRow[i] = i;
|
|
28
|
+
}
|
|
29
|
+
// calculate current row distance from previous row
|
|
30
|
+
for (i = 0; i < str1.length; ++i) {
|
|
31
|
+
nextCol = i + 1;
|
|
32
|
+
for (j = 0; j < str2.length; ++j) {
|
|
33
|
+
nextCol = TSHeuristic.levenshteinStepRow(str1, str2, i, j, prevRow, nextCol);
|
|
34
|
+
}
|
|
35
|
+
prevRow[j] = nextCol;
|
|
36
|
+
}
|
|
37
|
+
return nextCol;
|
|
38
|
+
};
|
|
39
|
+
TSHeuristic.levenshteinStepRow = function (str1, str2, i, j, prevRow, nextCol) {
|
|
40
|
+
var curCol = nextCol;
|
|
41
|
+
var next = prevRow[j] + ((str1.charAt(i) === str2.charAt(j)) ? 0 : 1);
|
|
42
|
+
var tmp = curCol + 1;
|
|
43
|
+
if (next > tmp)
|
|
44
|
+
next = tmp;
|
|
45
|
+
tmp = prevRow[j + 1] + 1;
|
|
46
|
+
if (next > tmp)
|
|
47
|
+
next = tmp;
|
|
48
|
+
prevRow[j] = curCol;
|
|
49
|
+
return next;
|
|
50
|
+
};
|
|
51
|
+
TSHeuristic.sift4 = function (s1, s2, maxOffset, maxDistance) {
|
|
52
|
+
if (!s1 || !s1.length) {
|
|
53
|
+
if (!s2) {
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
return s2.length;
|
|
57
|
+
}
|
|
58
|
+
if (!s2 || !s2.length) {
|
|
59
|
+
return s1.length;
|
|
60
|
+
}
|
|
61
|
+
var l1 = s1.length, l2 = s2.length;
|
|
62
|
+
var c1 = 0, c2 = 0;
|
|
63
|
+
var lcss = 0;
|
|
64
|
+
var local_cs = 0;
|
|
65
|
+
var trans = 0;
|
|
66
|
+
var offset_arr = [];
|
|
67
|
+
while ((c1 < l1) && (c2 < l2)) {
|
|
68
|
+
if (s1.charAt(c1) === s2.charAt(c2)) {
|
|
69
|
+
var m = TSHeuristic.sift4OnMatch(offset_arr, c1, c2, local_cs, trans);
|
|
70
|
+
local_cs = m.local_cs;
|
|
71
|
+
trans = m.trans;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
var mm = TSHeuristic.sift4OnMismatch(s1, s2, c1, c2, maxOffset, l1, l2, lcss, local_cs);
|
|
75
|
+
c1 = mm.c1;
|
|
76
|
+
c2 = mm.c2;
|
|
77
|
+
lcss = mm.lcss;
|
|
78
|
+
local_cs = mm.local_cs;
|
|
79
|
+
}
|
|
80
|
+
var stepped = TSHeuristic.sift4StepCursors(c1, c2, l1, l2, maxDistance, lcss, trans, local_cs);
|
|
81
|
+
c1 = stepped.c1;
|
|
82
|
+
c2 = stepped.c2;
|
|
83
|
+
lcss = stepped.lcss;
|
|
84
|
+
local_cs = stepped.local_cs;
|
|
85
|
+
if (stepped.earlyExit !== undefined)
|
|
86
|
+
return stepped.earlyExit;
|
|
87
|
+
}
|
|
88
|
+
lcss += local_cs;
|
|
89
|
+
return Math.round(Math.max(l1, l2) - lcss + trans);
|
|
90
|
+
};
|
|
91
|
+
TSHeuristic.sift4OnMatch = function (offset_arr, c1, c2, local_cs, trans) {
|
|
92
|
+
local_cs++;
|
|
93
|
+
var _a = TSHeuristic.sift4ProcessOffsets(offset_arr, c1, c2), nextTrans = _a.nextTrans, isTrans = _a.isTrans;
|
|
94
|
+
trans += nextTrans;
|
|
95
|
+
offset_arr.push({ c1: c1, c2: c2, trans: isTrans });
|
|
96
|
+
return { local_cs: local_cs, trans: trans };
|
|
97
|
+
};
|
|
98
|
+
TSHeuristic.sift4OnMismatch = function (s1, s2, c1, c2, maxOffset, l1, l2, lcss, local_cs) {
|
|
99
|
+
lcss += local_cs;
|
|
100
|
+
local_cs = 0;
|
|
101
|
+
if (c1 !== c2) {
|
|
102
|
+
c1 = c2 = Math.min(c1, c2);
|
|
103
|
+
}
|
|
104
|
+
var shifted = TSHeuristic.sift4ShiftCursorsForNearMatch(s1, s2, c1, c2, maxOffset, l1, l2);
|
|
105
|
+
c1 = shifted.c1;
|
|
106
|
+
c2 = shifted.c2;
|
|
107
|
+
return { c1: c1, c2: c2, lcss: lcss, local_cs: local_cs };
|
|
108
|
+
};
|
|
109
|
+
/** Increment cursors, optional early exit when distance exceeds maxDistance, normalize at string end. */
|
|
110
|
+
TSHeuristic.sift4StepCursors = function (c1, c2, l1, l2, maxDistance, lcss, trans, local_cs) {
|
|
111
|
+
c1++;
|
|
112
|
+
c2++;
|
|
113
|
+
if (maxDistance) {
|
|
114
|
+
var temporaryDistance = Math.max(c1, c2) - lcss + trans;
|
|
115
|
+
if (temporaryDistance >= maxDistance) {
|
|
116
|
+
return { c1: c1, c2: c2, lcss: lcss, local_cs: local_cs, earlyExit: Math.round(temporaryDistance) };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if ((c1 >= l1) || (c2 >= l2)) {
|
|
120
|
+
lcss += local_cs;
|
|
121
|
+
local_cs = 0;
|
|
122
|
+
c1 = c2 = Math.min(c1, c2);
|
|
123
|
+
}
|
|
124
|
+
return { c1: c1, c2: c2, lcss: lcss, local_cs: local_cs };
|
|
125
|
+
};
|
|
126
|
+
/** Updates transposition bookkeeping when characters match. */
|
|
127
|
+
TSHeuristic.sift4ProcessOffsets = function (offset_arr, c1, c2) {
|
|
128
|
+
var nextTrans = 0;
|
|
129
|
+
var isTrans = false;
|
|
130
|
+
var i = 0;
|
|
131
|
+
while (i < offset_arr.length) {
|
|
132
|
+
var ofs = offset_arr[i];
|
|
133
|
+
if (c1 <= ofs.c1 || c2 <= ofs.c2) {
|
|
134
|
+
isTrans = Math.abs(c2 - c1) >= Math.abs(ofs.c2 - ofs.c1);
|
|
135
|
+
if (isTrans) {
|
|
136
|
+
nextTrans++;
|
|
137
|
+
}
|
|
138
|
+
else if (!ofs.trans) {
|
|
139
|
+
ofs.trans = true;
|
|
140
|
+
nextTrans++;
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
if (c1 > ofs.c2 && c2 > ofs.c1) {
|
|
145
|
+
offset_arr.splice(i, 1);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
i++;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return { nextTrans: nextTrans, isTrans: isTrans };
|
|
152
|
+
};
|
|
153
|
+
/** Try nearby columns when current chars differ (Sift4 local search). */
|
|
154
|
+
TSHeuristic.sift4ShiftCursorsForNearMatch = function (s1, s2, c1, c2, maxOffset, l1, l2) {
|
|
155
|
+
var nc1 = c1, nc2 = c2;
|
|
156
|
+
for (var i = 0; i < maxOffset && (c1 + i < l1 || c2 + i < l2); i++) {
|
|
157
|
+
if ((c1 + i < l1) && (s1.charAt(c1 + i) === s2.charAt(c2))) {
|
|
158
|
+
nc1 = c1 + i - 1;
|
|
159
|
+
nc2 = c2 - 1;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
if ((c2 + i < l2) && (s1.charAt(c1) === s2.charAt(c2 + i))) {
|
|
163
|
+
nc1 = c1 - 1;
|
|
164
|
+
nc2 = c2 + i - 1;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return { c1: nc1, c2: nc2 };
|
|
169
|
+
};
|
|
170
|
+
TSHeuristic.getHeuristicDistance = function (s1, s2) {
|
|
171
|
+
if (s1 === void 0) { s1 = ''; }
|
|
172
|
+
if (s2 === void 0) { s2 = ''; }
|
|
173
|
+
var maxDistance = Math.floor(Math.max(s1.length, s2.length) / 2), approximateDistance = this.sift4(s1, s2, 5);
|
|
174
|
+
// if the distance is close, perform an exact computation
|
|
175
|
+
if (approximateDistance <= maxDistance) {
|
|
176
|
+
return this.levenshtein(s1, s2);
|
|
177
|
+
}
|
|
178
|
+
return approximateDistance;
|
|
179
|
+
};
|
|
180
|
+
TSHeuristic.distance = function (s1, s2) {
|
|
181
|
+
if (s1 === void 0) { s1 = ''; }
|
|
182
|
+
if (s2 === void 0) { s2 = ''; }
|
|
183
|
+
return (this.getHeuristicDistance(s1, s2) / Math.max(s1.length, s2.length)) * 100;
|
|
184
|
+
};
|
|
185
|
+
TSHeuristic.similarity = function (s1, s2) {
|
|
186
|
+
return 100 - this.distance(s1, s2);
|
|
187
|
+
};
|
|
188
|
+
TSHeuristic.removeDiacritics = function (str) {
|
|
189
|
+
for (var _i = 0, DIACRITICS_REMOVAL_MAP_1 = diacritics_removal_map_1.DIACRITICS_REMOVAL_MAP; _i < DIACRITICS_REMOVAL_MAP_1.length; _i++) {
|
|
190
|
+
var rule = DIACRITICS_REMOVAL_MAP_1[_i];
|
|
191
|
+
str = str.replace(rule.letters, rule.base);
|
|
192
|
+
}
|
|
193
|
+
return str;
|
|
194
|
+
};
|
|
195
|
+
return TSHeuristic;
|
|
196
|
+
}());
|
|
197
|
+
exports.TSHeuristic = TSHeuristic;
|
package/utils/TSLZS.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare class TSLZS {
|
|
2
|
+
private f;
|
|
3
|
+
private keyStrBase64;
|
|
4
|
+
private keyStrUriSafe;
|
|
5
|
+
private baseReverseDic;
|
|
6
|
+
/** Read one packed bit field from the input stream (shared LZ pattern). */
|
|
7
|
+
/** When enlarge counter is zero, widen the code bit width (LZ decompress bookkeeping). */
|
|
8
|
+
private decompressExpandCodebookIfNeeded;
|
|
9
|
+
private decompressAppendLiteralToDictionary;
|
|
10
|
+
private decompressResolveEntry;
|
|
11
|
+
private decompressReadBits;
|
|
12
|
+
private compressAppendBit;
|
|
13
|
+
private compressWriteBitsFromValue;
|
|
14
|
+
private compressWritePlainBits;
|
|
15
|
+
/** First emitted bit is 1, remaining bits are 0 (LZ literal header). */
|
|
16
|
+
private compressWriteBitsFirstOne;
|
|
17
|
+
private compressWriteDictIndexBits;
|
|
18
|
+
/** Emit bits for a phrase still being added to the dictionary (literal path). */
|
|
19
|
+
private compressEmitPendingLiteral;
|
|
20
|
+
/** LZ "enlarge" step: decrement counter and widen bit width when it hits zero. */
|
|
21
|
+
private compressDecrementEnlargeIn;
|
|
22
|
+
/**
|
|
23
|
+
* Emit bits for the current phrase: pending literal (still being created) or dictionary index.
|
|
24
|
+
* @returns whether the phrase was a pending literal (caller may delete from dictionaryToCreate).
|
|
25
|
+
*/
|
|
26
|
+
private compressEmitPendingOrDict;
|
|
27
|
+
/** Final LZ stream padding: emit control bits then align to character boundary. */
|
|
28
|
+
private compressPadStreamTerminator;
|
|
29
|
+
private getBaseValue;
|
|
30
|
+
compressToBase64(input: string | null): string;
|
|
31
|
+
decompressFromBase64(input: string | null): string | null;
|
|
32
|
+
compressToUTF16(input: string | null): string;
|
|
33
|
+
decompressFromUTF16(compressed: string | null): string | null;
|
|
34
|
+
compressToUint8Array(uncompressed: string): Uint8Array;
|
|
35
|
+
decompressFromUint8Array(compressed: Uint8Array | null | undefined): string | null;
|
|
36
|
+
compressToEncodedURIComponent(input: string | null): string;
|
|
37
|
+
decompressFromEncodedURIComponent(input: string | null): string | null;
|
|
38
|
+
compress(uncompressed: string | null): string;
|
|
39
|
+
_compress(uncompressed: string | null, bitsPerChar: number, getCharFromInt: (a: number) => string): string;
|
|
40
|
+
decompress(compressed: string | null): string | null;
|
|
41
|
+
_decompress(length: number, resetValue: number, getNextValue: (index: number) => number): string | null;
|
|
42
|
+
}
|
package/utils/TSLZS.js
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TSLZS = void 0;
|
|
4
|
+
var TSLZS = /** @class */ (function () {
|
|
5
|
+
function TSLZS() {
|
|
6
|
+
this.f = String.fromCharCode;
|
|
7
|
+
this.keyStrBase64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
8
|
+
this.keyStrUriSafe = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$';
|
|
9
|
+
this.baseReverseDic = {};
|
|
10
|
+
}
|
|
11
|
+
/** Read one packed bit field from the input stream (shared LZ pattern). */
|
|
12
|
+
/** When enlarge counter is zero, widen the code bit width (LZ decompress bookkeeping). */
|
|
13
|
+
TSLZS.prototype.decompressExpandCodebookIfNeeded = function (enlargeIn, numBits) {
|
|
14
|
+
if (enlargeIn !== 0)
|
|
15
|
+
return [enlargeIn, numBits];
|
|
16
|
+
return [Math.pow(2, numBits), numBits + 1];
|
|
17
|
+
};
|
|
18
|
+
TSLZS.prototype.decompressAppendLiteralToDictionary = function (data, resetValue, getNextValue, dictionary, dictSize, bitWidth) {
|
|
19
|
+
var bits = this.decompressReadBits(data, resetValue, getNextValue, Math.pow(2, bitWidth));
|
|
20
|
+
dictionary[dictSize++] = this.f(bits);
|
|
21
|
+
return { code: dictSize - 1, dictSize: dictSize };
|
|
22
|
+
};
|
|
23
|
+
TSLZS.prototype.decompressResolveEntry = function (dictionary, c, dictSize, w) {
|
|
24
|
+
if (dictionary[c] != null) {
|
|
25
|
+
return String(dictionary[c]);
|
|
26
|
+
}
|
|
27
|
+
if (c === dictSize) {
|
|
28
|
+
return w + w.charAt(0);
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
};
|
|
32
|
+
TSLZS.prototype.decompressReadBits = function (data, resetValue, getNextValue, maxPower) {
|
|
33
|
+
var bits = 0;
|
|
34
|
+
var power = 1;
|
|
35
|
+
while (power !== maxPower) {
|
|
36
|
+
var resb = data.val & data.position;
|
|
37
|
+
data.position >>= 1;
|
|
38
|
+
if (data.position === 0) {
|
|
39
|
+
data.position = resetValue;
|
|
40
|
+
data.val = getNextValue(data.index++);
|
|
41
|
+
}
|
|
42
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
43
|
+
power <<= 1;
|
|
44
|
+
}
|
|
45
|
+
return bits;
|
|
46
|
+
};
|
|
47
|
+
TSLZS.prototype.compressAppendBit = function (s, bitsPerChar, getCharFromInt, bit) {
|
|
48
|
+
s.context_data_val = bit === undefined
|
|
49
|
+
? (s.context_data_val << 1)
|
|
50
|
+
: (s.context_data_val << 1) | bit;
|
|
51
|
+
if (s.context_data_position === bitsPerChar - 1) {
|
|
52
|
+
s.context_data_position = 0;
|
|
53
|
+
s.context_data.push(getCharFromInt(s.context_data_val));
|
|
54
|
+
s.context_data_val = 0;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
s.context_data_position++;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
TSLZS.prototype.compressWriteBitsFromValue = function (s, bitsPerChar, getCharFromInt, value, width) {
|
|
61
|
+
var v = value;
|
|
62
|
+
for (var i = 0; i < width; i++) {
|
|
63
|
+
this.compressAppendBit(s, bitsPerChar, getCharFromInt, v & 1);
|
|
64
|
+
v >>= 1;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
TSLZS.prototype.compressWritePlainBits = function (s, bitsPerChar, getCharFromInt, count) {
|
|
68
|
+
for (var i = 0; i < count; i++) {
|
|
69
|
+
this.compressAppendBit(s, bitsPerChar, getCharFromInt);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
/** First emitted bit is 1, remaining bits are 0 (LZ literal header). */
|
|
73
|
+
TSLZS.prototype.compressWriteBitsFirstOne = function (s, bitsPerChar, getCharFromInt, n) {
|
|
74
|
+
for (var i = 0; i < n; i++) {
|
|
75
|
+
this.compressAppendBit(s, bitsPerChar, getCharFromInt, i === 0 ? 1 : 0);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
TSLZS.prototype.compressWriteDictIndexBits = function (s, bitsPerChar, getCharFromInt, context_numBits, value) {
|
|
79
|
+
for (var i = 0; i < context_numBits; i++) {
|
|
80
|
+
this.compressAppendBit(s, bitsPerChar, getCharFromInt, value & 1);
|
|
81
|
+
value >>= 1;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
/** Emit bits for a phrase still being added to the dictionary (literal path). */
|
|
85
|
+
TSLZS.prototype.compressEmitPendingLiteral = function (context_w, context_dictionaryToCreate, bitState, bitsPerChar, getCharFromInt, context_numBits) {
|
|
86
|
+
if (!Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w))
|
|
87
|
+
return;
|
|
88
|
+
if (context_w.charCodeAt(0) < 256) {
|
|
89
|
+
this.compressWritePlainBits(bitState, bitsPerChar, getCharFromInt, context_numBits);
|
|
90
|
+
this.compressWriteBitsFromValue(bitState, bitsPerChar, getCharFromInt, context_w.charCodeAt(0), 8);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
this.compressWriteBitsFirstOne(bitState, bitsPerChar, getCharFromInt, context_numBits);
|
|
94
|
+
this.compressWriteBitsFromValue(bitState, bitsPerChar, getCharFromInt, context_w.charCodeAt(0), 16);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
/** LZ "enlarge" step: decrement counter and widen bit width when it hits zero. */
|
|
98
|
+
TSLZS.prototype.compressDecrementEnlargeIn = function (enlargeIn, numBits) {
|
|
99
|
+
var ei = enlargeIn - 1;
|
|
100
|
+
var nb = numBits;
|
|
101
|
+
if (ei === 0) {
|
|
102
|
+
ei = Math.pow(2, nb);
|
|
103
|
+
nb++;
|
|
104
|
+
}
|
|
105
|
+
return [ei, nb];
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Emit bits for the current phrase: pending literal (still being created) or dictionary index.
|
|
109
|
+
* @returns whether the phrase was a pending literal (caller may delete from dictionaryToCreate).
|
|
110
|
+
*/
|
|
111
|
+
TSLZS.prototype.compressEmitPendingOrDict = function (context_w, context_dictionary, context_dictionaryToCreate, bitState, bitsPerChar, getCharFromInt, context_numBits) {
|
|
112
|
+
var pending = Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w);
|
|
113
|
+
if (pending) {
|
|
114
|
+
this.compressEmitPendingLiteral(context_w, context_dictionaryToCreate, bitState, bitsPerChar, getCharFromInt, context_numBits);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
var value = context_dictionary[context_w];
|
|
118
|
+
this.compressWriteDictIndexBits(bitState, bitsPerChar, getCharFromInt, context_numBits, value);
|
|
119
|
+
}
|
|
120
|
+
return pending;
|
|
121
|
+
};
|
|
122
|
+
/** Final LZ stream padding: emit control bits then align to character boundary. */
|
|
123
|
+
TSLZS.prototype.compressPadStreamTerminator = function (bitState, bitsPerChar, getCharFromInt, context_numBits) {
|
|
124
|
+
var value = 2;
|
|
125
|
+
for (var i = 0; i < context_numBits; i++) {
|
|
126
|
+
this.compressAppendBit(bitState, bitsPerChar, getCharFromInt, value & 1);
|
|
127
|
+
value >>= 1;
|
|
128
|
+
}
|
|
129
|
+
while (true) {
|
|
130
|
+
bitState.context_data_val = (bitState.context_data_val << 1);
|
|
131
|
+
if (bitState.context_data_position === bitsPerChar - 1) {
|
|
132
|
+
bitState.context_data.push(getCharFromInt(bitState.context_data_val));
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
bitState.context_data_position++;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
TSLZS.prototype.getBaseValue = function (alphabet, character) {
|
|
139
|
+
if (!this.baseReverseDic[alphabet]) {
|
|
140
|
+
this.baseReverseDic[alphabet] = {};
|
|
141
|
+
for (var i = 0; i < alphabet.length; i++) {
|
|
142
|
+
this.baseReverseDic[alphabet][alphabet.charAt(i)] = i;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return this.baseReverseDic[alphabet][character];
|
|
146
|
+
};
|
|
147
|
+
TSLZS.prototype.compressToBase64 = function (input) {
|
|
148
|
+
var _this = this;
|
|
149
|
+
if (input == null)
|
|
150
|
+
return '';
|
|
151
|
+
var res = this._compress(input, 6, function (a) { return _this.keyStrBase64.charAt(a); });
|
|
152
|
+
switch (res.length % 4) { // To produce valid Base64
|
|
153
|
+
default: // When could this happen ?
|
|
154
|
+
case 0: return res;
|
|
155
|
+
case 1: return res + '===';
|
|
156
|
+
case 2: return res + '==';
|
|
157
|
+
case 3: return res + '=';
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
TSLZS.prototype.decompressFromBase64 = function (input) {
|
|
161
|
+
var _this = this;
|
|
162
|
+
if (input == null)
|
|
163
|
+
return '';
|
|
164
|
+
if (input == '')
|
|
165
|
+
return null;
|
|
166
|
+
return this._decompress(input.length, 32, function (index) { return _this.getBaseValue(_this.keyStrBase64, input.charAt(index)); });
|
|
167
|
+
};
|
|
168
|
+
TSLZS.prototype.compressToUTF16 = function (input) {
|
|
169
|
+
var _this = this;
|
|
170
|
+
if (input == null)
|
|
171
|
+
return '';
|
|
172
|
+
return this._compress(input, 15, function (a) { return _this.f(a + 32); }) + ' ';
|
|
173
|
+
};
|
|
174
|
+
TSLZS.prototype.decompressFromUTF16 = function (compressed) {
|
|
175
|
+
if (compressed == null)
|
|
176
|
+
return '';
|
|
177
|
+
if (compressed == '')
|
|
178
|
+
return null;
|
|
179
|
+
return this._decompress(compressed.length, 16384, function (index) { return compressed.charCodeAt(index) - 32; });
|
|
180
|
+
};
|
|
181
|
+
TSLZS.prototype.compressToUint8Array = function (uncompressed) {
|
|
182
|
+
var compressed = this.compress(uncompressed);
|
|
183
|
+
var buf = new Uint8Array(compressed.length * 2); // 2 bytes per character
|
|
184
|
+
for (var i = 0, TotalLen = compressed.length; i < TotalLen; i++) {
|
|
185
|
+
var current_value = compressed.charCodeAt(i);
|
|
186
|
+
buf[i * 2] = current_value >>> 8;
|
|
187
|
+
buf[i * 2 + 1] = current_value % 256;
|
|
188
|
+
}
|
|
189
|
+
return buf;
|
|
190
|
+
};
|
|
191
|
+
TSLZS.prototype.decompressFromUint8Array = function (compressed) {
|
|
192
|
+
var _this = this;
|
|
193
|
+
if (compressed === null || compressed === undefined) {
|
|
194
|
+
return this.decompress(null);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
var buf = new Array(compressed.length / 2); // 2 bytes per character
|
|
198
|
+
for (var i = 0, TotalLen = buf.length; i < TotalLen; i++) {
|
|
199
|
+
buf[i] = compressed[i * 2] * 256 + compressed[i * 2 + 1];
|
|
200
|
+
}
|
|
201
|
+
var result_1 = [];
|
|
202
|
+
buf.forEach(function (c) { return result_1.push(_this.f(c)); });
|
|
203
|
+
return this.decompress(result_1.join(''));
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
TSLZS.prototype.compressToEncodedURIComponent = function (input) {
|
|
207
|
+
var _this = this;
|
|
208
|
+
if (input == null)
|
|
209
|
+
return '';
|
|
210
|
+
return this._compress(input, 6, function (a) { return _this.keyStrUriSafe.charAt(a); });
|
|
211
|
+
};
|
|
212
|
+
TSLZS.prototype.decompressFromEncodedURIComponent = function (input) {
|
|
213
|
+
var _this = this;
|
|
214
|
+
if (input == null)
|
|
215
|
+
return '';
|
|
216
|
+
if (input == '')
|
|
217
|
+
return null;
|
|
218
|
+
input = input.replace(/ /g, '+');
|
|
219
|
+
return this._decompress(input.length, 32, function (index) { return _this.getBaseValue(_this.keyStrUriSafe, input.charAt(index)); });
|
|
220
|
+
};
|
|
221
|
+
TSLZS.prototype.compress = function (uncompressed) {
|
|
222
|
+
var _this = this;
|
|
223
|
+
return this._compress(uncompressed, 16, function (a) { return _this.f(a); });
|
|
224
|
+
};
|
|
225
|
+
TSLZS.prototype._compress = function (uncompressed, bitsPerChar, getCharFromInt) {
|
|
226
|
+
var _a, _b, _c;
|
|
227
|
+
if (uncompressed == null)
|
|
228
|
+
return '';
|
|
229
|
+
var context_dictionary = {}, context_dictionaryToCreate = {}, context_data = [];
|
|
230
|
+
var context_c, context_wc, context_w = '', context_enlargeIn = 2, // Compensate for the first entry which should not count
|
|
231
|
+
context_dictSize = 3, context_numBits = 2, ii;
|
|
232
|
+
var bitState = {
|
|
233
|
+
context_data_val: 0,
|
|
234
|
+
context_data_position: 0,
|
|
235
|
+
context_data: context_data
|
|
236
|
+
};
|
|
237
|
+
for (ii = 0; ii < uncompressed.length; ii += 1) {
|
|
238
|
+
context_c = uncompressed.charAt(ii);
|
|
239
|
+
if (!Object.prototype.hasOwnProperty.call(context_dictionary, context_c)) {
|
|
240
|
+
context_dictionary[context_c] = context_dictSize++;
|
|
241
|
+
context_dictionaryToCreate[context_c] = true;
|
|
242
|
+
}
|
|
243
|
+
context_wc = context_w + context_c;
|
|
244
|
+
if (Object.prototype.hasOwnProperty.call(context_dictionary, context_wc)) {
|
|
245
|
+
context_w = context_wc;
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
var pendingPhrase = this.compressEmitPendingOrDict(context_w, context_dictionary, context_dictionaryToCreate, bitState, bitsPerChar, getCharFromInt, context_numBits);
|
|
249
|
+
if (pendingPhrase) {
|
|
250
|
+
_a = this.compressDecrementEnlargeIn(context_enlargeIn, context_numBits), context_enlargeIn = _a[0], context_numBits = _a[1];
|
|
251
|
+
delete context_dictionaryToCreate[context_w];
|
|
252
|
+
}
|
|
253
|
+
_b = this.compressDecrementEnlargeIn(context_enlargeIn, context_numBits), context_enlargeIn = _b[0], context_numBits = _b[1];
|
|
254
|
+
context_dictionary[context_wc] = context_dictSize++;
|
|
255
|
+
context_w = String(context_c);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (context_w !== '') {
|
|
259
|
+
var pendingTail = this.compressEmitPendingOrDict(context_w, context_dictionary, context_dictionaryToCreate, bitState, bitsPerChar, getCharFromInt, context_numBits);
|
|
260
|
+
if (pendingTail) {
|
|
261
|
+
_c = this.compressDecrementEnlargeIn(context_enlargeIn, context_numBits), context_enlargeIn = _c[0], context_numBits = _c[1];
|
|
262
|
+
delete context_dictionaryToCreate[context_w];
|
|
263
|
+
}
|
|
264
|
+
context_numBits = this.compressDecrementEnlargeIn(context_enlargeIn, context_numBits)[1];
|
|
265
|
+
}
|
|
266
|
+
this.compressPadStreamTerminator(bitState, bitsPerChar, getCharFromInt, context_numBits);
|
|
267
|
+
return bitState.context_data.join('');
|
|
268
|
+
};
|
|
269
|
+
TSLZS.prototype.decompress = function (compressed) {
|
|
270
|
+
if (compressed == null)
|
|
271
|
+
return '';
|
|
272
|
+
if (compressed == '')
|
|
273
|
+
return null;
|
|
274
|
+
return this._decompress(compressed.length, 32768, function (index) { return compressed.charCodeAt(index); });
|
|
275
|
+
};
|
|
276
|
+
TSLZS.prototype._decompress = function (length, resetValue, getNextValue) {
|
|
277
|
+
var _a, _b;
|
|
278
|
+
var dictionary = [], result = [], data = { val: getNextValue(0), position: resetValue, index: 1 };
|
|
279
|
+
var enlargeIn = 4, dictSize = 4, numBits = 3, entry, i, w, bits, c = '';
|
|
280
|
+
for (i = 0; i < 3; i += 1) {
|
|
281
|
+
dictionary[i] = i;
|
|
282
|
+
}
|
|
283
|
+
bits = this.decompressReadBits(data, resetValue, getNextValue, Math.pow(2, 2));
|
|
284
|
+
switch (bits) {
|
|
285
|
+
case 0: {
|
|
286
|
+
var lit = this.decompressReadBits(data, resetValue, getNextValue, Math.pow(2, 8));
|
|
287
|
+
c = this.f(lit);
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
case 1: {
|
|
291
|
+
var lit = this.decompressReadBits(data, resetValue, getNextValue, Math.pow(2, 16));
|
|
292
|
+
c = this.f(lit);
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
case 2:
|
|
296
|
+
return '';
|
|
297
|
+
default:
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
dictionary[3] = c;
|
|
301
|
+
w = c;
|
|
302
|
+
result.push(c);
|
|
303
|
+
while (true) {
|
|
304
|
+
if (data.index > length) {
|
|
305
|
+
return '';
|
|
306
|
+
}
|
|
307
|
+
bits = this.decompressReadBits(data, resetValue, getNextValue, Math.pow(2, numBits));
|
|
308
|
+
switch (bits) {
|
|
309
|
+
case 0: {
|
|
310
|
+
var appended = this.decompressAppendLiteralToDictionary(data, resetValue, getNextValue, dictionary, dictSize, 8);
|
|
311
|
+
c = appended.code;
|
|
312
|
+
dictSize = appended.dictSize;
|
|
313
|
+
enlargeIn--;
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
case 1: {
|
|
317
|
+
var appended = this.decompressAppendLiteralToDictionary(data, resetValue, getNextValue, dictionary, dictSize, 16);
|
|
318
|
+
c = appended.code;
|
|
319
|
+
dictSize = appended.dictSize;
|
|
320
|
+
enlargeIn--;
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
case 2:
|
|
324
|
+
return result.join('');
|
|
325
|
+
default:
|
|
326
|
+
c = bits;
|
|
327
|
+
}
|
|
328
|
+
_a = this.decompressExpandCodebookIfNeeded(enlargeIn, numBits), enlargeIn = _a[0], numBits = _a[1];
|
|
329
|
+
var resolvedEntry = this.decompressResolveEntry(dictionary, c, dictSize, w);
|
|
330
|
+
if (resolvedEntry === null) {
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
entry = resolvedEntry;
|
|
334
|
+
result.push(entry);
|
|
335
|
+
dictionary[dictSize++] = w + entry.charAt(0);
|
|
336
|
+
enlargeIn--;
|
|
337
|
+
w = entry;
|
|
338
|
+
_b = this.decompressExpandCodebookIfNeeded(enlargeIn, numBits), enlargeIn = _b[0], numBits = _b[1];
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
return TSLZS;
|
|
342
|
+
}());
|
|
343
|
+
exports.TSLZS = TSLZS;
|