@pioneer-platform/helpers 4.0.3 → 4.0.5

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.
@@ -11,222 +11,440 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.BigIntArithmetics = exports.formatBigIntToSafeValue = void 0;
13
13
  var types_1 = require("@coinmasters/types");
14
+ var TAG = " | BigIntArithmetics | ";
14
15
  var DEFAULT_DECIMAL = 8;
15
16
  var bigintPow = function (base, exponent) {
16
- var result = BigInt(1);
17
- while (exponent > 0) {
18
- if (exponent % 2 === 1) {
19
- result *= base;
17
+ var tag = TAG + " | bigintPow | ";
18
+ try {
19
+ var result = BigInt(1);
20
+ while (exponent > 0) {
21
+ if (exponent % 2 === 1) {
22
+ result *= base;
23
+ }
24
+ base *= base;
25
+ exponent = Math.floor(exponent / 2);
20
26
  }
21
- base *= base;
22
- exponent = Math.floor(exponent / 2);
27
+ return result;
28
+ }
29
+ catch (error) {
30
+ console.error(tag + 'Error in bigintPow:', error);
31
+ return BigInt(1);
23
32
  }
24
- return result;
25
33
  };
26
34
  var toMultiplier = function (decimal) {
27
- console.log('toMultiplier input decimal:', decimal);
35
+ var tag = TAG + " | toMultiplier | ";
36
+ console.log(tag + 'input decimal:', decimal);
28
37
  try {
29
38
  var result = bigintPow(BigInt(10), decimal);
30
- console.log('toMultiplier result:', result);
39
+ console.log(tag + 'result:', result);
31
40
  return result;
32
41
  }
33
42
  catch (error) {
34
- console.error('Error in toMultiplier:', error);
43
+ console.error(tag + 'Error in toMultiplier:', error);
35
44
  return BigInt(10);
36
45
  }
37
46
  };
38
- var decimalFromMultiplier = function (multiplier) { return Math.log10(Number(multiplier)); };
47
+ var decimalFromMultiplier = function (multiplier) {
48
+ var tag = TAG + " | decimalFromMultiplier | ";
49
+ try {
50
+ return Math.log10(Number(multiplier));
51
+ }
52
+ catch (error) {
53
+ console.error(tag + 'Error in decimalFromMultiplier:', error);
54
+ return 0;
55
+ }
56
+ };
39
57
  function formatBigIntToSafeValue(_a) {
40
58
  var value = _a.value, _b = _a.bigIntDecimal, bigIntDecimal = _b === void 0 ? DEFAULT_DECIMAL : _b, _c = _a.decimal, decimal = _c === void 0 ? DEFAULT_DECIMAL : _c;
41
- var isNegative = value < BigInt(0);
42
- var valueString = value.toString().substring(isNegative ? 1 : 0);
43
- var padLength = decimal - (valueString.length - 1);
44
- if (padLength > 0) {
45
- valueString = '0'.repeat(padLength) + valueString;
46
- }
47
- var decimalIndex = valueString.length - decimal;
48
- var decimalString = valueString.slice(-decimal);
49
- if (parseInt(decimalString[bigIntDecimal]) >= 5) {
50
- decimalString = "".concat(decimalString.substring(0, bigIntDecimal - 1)).concat((parseInt(decimalString[bigIntDecimal - 1]) + 1).toString());
59
+ var tag = TAG + " | formatBigIntToSafeValue | ";
60
+ try {
61
+ console.log(tag, 'value:', value, 'bigIntDecimal:', bigIntDecimal, 'decimal:', decimal);
62
+ // Check if the value is negative and throw an error if true
63
+ if (value < BigInt(0)) {
64
+ throw new Error(tag + 'Negative value is not allowed');
65
+ }
66
+ // Convert bigint to string and handle potential negative sign
67
+ var valueString = value.toString();
68
+ // Calculate padding length required to match the specified decimal places
69
+ var padLength = decimal - (valueString.length - 1);
70
+ // Pad the value string with leading zeros if necessary
71
+ if (padLength > 0) {
72
+ valueString = '0'.repeat(padLength) + valueString;
73
+ }
74
+ // Determine the position of the decimal point
75
+ var decimalIndex = valueString.length - decimal;
76
+ // Extract the decimal part of the value
77
+ var decimalString = valueString.slice(-decimal);
78
+ // Trim the decimal string to match the specified bigIntDecimal length
79
+ if (decimalString.length > bigIntDecimal) {
80
+ decimalString = decimalString.substring(0, bigIntDecimal);
81
+ }
82
+ // Construct the final string with the integer and decimal parts
83
+ var formattedValue = "".concat(valueString.slice(0, decimalIndex), ".").concat(decimalString).replace(/\.?0*$/, '');
84
+ // Log the formatted value for debugging
85
+ console.log(tag + 'Formatted Value:', formattedValue);
86
+ return formattedValue;
51
87
  }
52
- else {
53
- decimalString = decimalString.substring(0, bigIntDecimal);
88
+ catch (error) {
89
+ // Log any errors encountered during the process
90
+ console.error(tag + 'Error in formatBigIntToSafeValue:', error);
91
+ return '';
54
92
  }
55
- return "".concat(isNegative ? '-' : '').concat(valueString.slice(0, decimalIndex), ".").concat(decimalString).replace(/\.?0*$/, '');
56
93
  }
57
94
  exports.formatBigIntToSafeValue = formatBigIntToSafeValue;
95
+ // export function formatBigIntToSafeValue({
96
+ // value,
97
+ // bigIntDecimal = DEFAULT_DECIMAL,
98
+ // decimal = DEFAULT_DECIMAL,
99
+ // }: {
100
+ // value: bigint;
101
+ // bigIntDecimal?: number;
102
+ // decimal?: number;
103
+ // }): string {
104
+ // let tag = TAG + " | formatBigIntToSafeValue | ";
105
+ // try {
106
+ // const isNegative = value < BigInt(0);
107
+ // let valueString = value.toString().substring(isNegative ? 1 : 0);
108
+ //
109
+ // const padLength = decimal - (valueString.length - 1);
110
+ //
111
+ // if (padLength > 0) {
112
+ // valueString = '0'.repeat(padLength) + valueString;
113
+ // }
114
+ //
115
+ // const decimalIndex = valueString.length - decimal;
116
+ // let decimalString = valueString.slice(-decimal);
117
+ //
118
+ // if (decimalString.length > bigIntDecimal) {
119
+ // decimalString = decimalString.substring(0, bigIntDecimal);
120
+ // }
121
+ //
122
+ // return `${isNegative ? '-' : ''}${valueString.slice(0, decimalIndex)}.${decimalString}`.replace(
123
+ // /\.?0*$/,
124
+ // '',
125
+ // );
126
+ // } catch (error) {
127
+ // console.error(tag + 'Error in formatBigIntToSafeValue:', error);
128
+ // return '';
129
+ // }
130
+ // }
58
131
  var BigIntArithmetics = /** @class */ (function () {
59
132
  function BigIntArithmetics(params) {
60
- this.decimalMultiplier = bigintPow(BigInt(10), 8);
61
- this.bigIntValue = BigInt(0);
62
- console.log('Constructor Params:', params);
63
- var value = getStringValue(params);
64
- console.log('String Value:', value);
65
- var isComplex = typeof params === 'object' && params !== null;
66
- this.decimal = isComplex ? params.decimal : undefined;
67
- console.log('Decimal:', this.decimal);
68
- if (isComplex && 'decimalMultiplier' in params) {
69
- this.decimalMultiplier = params.decimalMultiplier;
70
- }
71
- else {
72
- var maxDecimals = Math.max(getFloatDecimals(toSafeValue(value)), this.decimal || 0);
73
- this.decimalMultiplier = toMultiplier(maxDecimals);
74
- }
75
- console.log('Decimal Multiplier:', this.decimalMultiplier);
76
- this.setValue(value);
77
- console.log('BigInt Value:', this.bigIntValue);
133
+ var tag = TAG + " | constructor | ";
134
+ try {
135
+ console.log(tag + 'Constructor Params:', params);
136
+ var value = getStringValue(params);
137
+ console.log(tag + 'String Value:', value);
138
+ var isComplex = typeof params === 'object' && params !== null;
139
+ this.decimal = isComplex ? params.decimal : undefined;
140
+ console.log(tag, 'Decimal:', this.decimal);
141
+ console.log(tag, 'isComplex:', isComplex);
142
+ if (isComplex) {
143
+ this.decimalMultiplier = this.decimal;
144
+ }
145
+ else {
146
+ var maxDecimals = Math.max(getFloatDecimals(toSafeValue(value)), this.decimal || 0);
147
+ this.decimalMultiplier = toMultiplier(maxDecimals);
148
+ }
149
+ console.log(tag + 'Decimal Multiplier:', this.decimalMultiplier);
150
+ this.setValue(value);
151
+ //@ts-ignore
152
+ console.log(tag + 'BigInt Value:', this.bigIntValue);
153
+ }
154
+ catch (error) {
155
+ console.error(tag + 'Error in constructor:', error);
156
+ this.decimalMultiplier = BigInt(1);
157
+ this.bigIntValue = BigInt(0);
158
+ }
78
159
  }
79
160
  BigIntArithmetics.fromBigInt = function (value, decimal) {
80
- return new BigIntArithmetics({
81
- decimal: decimal,
82
- value: formatBigIntToSafeValue({ value: value, bigIntDecimal: decimal, decimal: decimal }),
83
- });
161
+ var tag = TAG + " | fromBigInt | ";
162
+ try {
163
+ return new BigIntArithmetics({
164
+ decimal: decimal,
165
+ value: formatBigIntToSafeValue({ value: value, bigIntDecimal: decimal, decimal: decimal }),
166
+ });
167
+ }
168
+ catch (error) {
169
+ console.error(tag + 'Error in fromBigInt:', error);
170
+ return new BigIntArithmetics(0);
171
+ }
84
172
  };
85
173
  BigIntArithmetics.shiftDecimals = function (_a) {
86
174
  var value = _a.value, from = _a.from, to = _a.to;
87
- return this.fromBigInt((value.getBaseValue('bigint') * toMultiplier(to)) / toMultiplier(from), to);
175
+ var tag = TAG + " | shiftDecimals | ";
176
+ try {
177
+ return this.fromBigInt((value.getBaseValue('bigint') * toMultiplier(to)) / toMultiplier(from), to);
178
+ }
179
+ catch (error) {
180
+ console.error(tag + 'Error in shiftDecimals:', error);
181
+ return new BigIntArithmetics(0);
182
+ }
88
183
  };
89
184
  BigIntArithmetics.prototype.set = function (value) {
90
- // @ts-ignore
91
- return new BigIntArithmetics({ decimal: this.decimal, value: value });
185
+ var tag = TAG + " | set | ";
186
+ try {
187
+ // @ts-ignore
188
+ return new BigIntArithmetics({ decimal: this.decimal, value: value });
189
+ }
190
+ catch (error) {
191
+ console.error(tag + 'Error in set:', error);
192
+ return this;
193
+ }
92
194
  };
93
195
  BigIntArithmetics.prototype.add = function () {
94
196
  var args = [];
95
197
  for (var _i = 0; _i < arguments.length; _i++) {
96
198
  args[_i] = arguments[_i];
97
199
  }
98
- return this.arithmetics.apply(this, __spreadArray(['add'], args, false));
200
+ var tag = TAG + " | add | ";
201
+ try {
202
+ return this.arithmetics.apply(this, __spreadArray(['add'], args, false));
203
+ }
204
+ catch (error) {
205
+ console.error(tag + 'Error in add:', error);
206
+ return this;
207
+ }
99
208
  };
100
209
  BigIntArithmetics.prototype.sub = function () {
101
210
  var args = [];
102
211
  for (var _i = 0; _i < arguments.length; _i++) {
103
212
  args[_i] = arguments[_i];
104
213
  }
105
- return this.arithmetics.apply(this, __spreadArray(['sub'], args, false));
214
+ var tag = TAG + " | sub | ";
215
+ try {
216
+ return this.arithmetics.apply(this, __spreadArray(['sub'], args, false));
217
+ }
218
+ catch (error) {
219
+ console.error(tag + 'Error in sub:', error);
220
+ return this;
221
+ }
106
222
  };
107
223
  BigIntArithmetics.prototype.mul = function () {
108
224
  var args = [];
109
225
  for (var _i = 0; _i < arguments.length; _i++) {
110
226
  args[_i] = arguments[_i];
111
227
  }
112
- return this.arithmetics.apply(this, __spreadArray(['mul'], args, false));
228
+ var tag = TAG + " | mul | ";
229
+ try {
230
+ return this.arithmetics.apply(this, __spreadArray(['mul'], args, false));
231
+ }
232
+ catch (error) {
233
+ console.error(tag + 'Error in mul:', error);
234
+ return this;
235
+ }
113
236
  };
114
237
  BigIntArithmetics.prototype.div = function () {
115
238
  var args = [];
116
239
  for (var _i = 0; _i < arguments.length; _i++) {
117
240
  args[_i] = arguments[_i];
118
241
  }
119
- return this.arithmetics.apply(this, __spreadArray(['div'], args, false));
242
+ var tag = TAG + " | div | ";
243
+ try {
244
+ return this.arithmetics.apply(this, __spreadArray(['div'], args, false));
245
+ }
246
+ catch (error) {
247
+ console.error(tag + 'Error in div:', error);
248
+ return this;
249
+ }
120
250
  };
121
251
  BigIntArithmetics.prototype.gt = function (value) {
122
- return this.comparison('gt', value);
252
+ var tag = TAG + " | gt | ";
253
+ try {
254
+ return this.comparison('gt', value);
255
+ }
256
+ catch (error) {
257
+ console.error(tag + 'Error in gt:', error);
258
+ return false;
259
+ }
123
260
  };
124
261
  BigIntArithmetics.prototype.gte = function (value) {
125
- return this.comparison('gte', value);
262
+ var tag = TAG + " | gte | ";
263
+ try {
264
+ return this.comparison('gte', value);
265
+ }
266
+ catch (error) {
267
+ console.error(tag + 'Error in gte:', error);
268
+ return false;
269
+ }
126
270
  };
127
271
  BigIntArithmetics.prototype.lt = function (value) {
128
- return this.comparison('lt', value);
272
+ var tag = TAG + " | lt | ";
273
+ try {
274
+ return this.comparison('lt', value);
275
+ }
276
+ catch (error) {
277
+ console.error(tag + 'Error in lt:', error);
278
+ return false;
279
+ }
129
280
  };
130
281
  BigIntArithmetics.prototype.lte = function (value) {
131
- return this.comparison('lte', value);
282
+ var tag = TAG + " | lte | ";
283
+ try {
284
+ return this.comparison('lte', value);
285
+ }
286
+ catch (error) {
287
+ console.error(tag + 'Error in lte:', error);
288
+ return false;
289
+ }
132
290
  };
133
291
  BigIntArithmetics.prototype.eqValue = function (value) {
134
- return this.comparison('eqValue', value);
292
+ var tag = TAG + " | eqValue | ";
293
+ try {
294
+ return this.comparison('eqValue', value);
295
+ }
296
+ catch (error) {
297
+ console.error(tag + 'Error in eqValue:', error);
298
+ return false;
299
+ }
135
300
  };
136
- // @ts-ignore
301
+ //@ts-ignore
137
302
  BigIntArithmetics.prototype.getValue = function (type) {
138
- var value = formatBigIntToSafeValue({
139
- value: this.bigIntValue,
140
- bigIntDecimal: this.decimal || decimalFromMultiplier(this.decimalMultiplier),
141
- });
142
- switch (type) {
143
- case 'number':
144
- return Number(value);
145
- case 'string':
146
- return value;
147
- case 'bigint':
148
- return ((this.bigIntValue * bigintPow(BigInt(10), this.decimal || 8)) /
149
- this.decimalMultiplier);
303
+ var tag = TAG + " | getValue | ";
304
+ try {
305
+ console.log(tag, 'getValue type:', type);
306
+ console.log(tag, 'decimalMultiplier: ', this.decimalMultiplier);
307
+ var value = formatBigIntToSafeValue({
308
+ value: this.bigIntValue,
309
+ bigIntDecimal: this.decimal || decimalFromMultiplier(this.decimalMultiplier),
310
+ decimal: this.decimalMultiplier,
311
+ });
312
+ console.log(tag, 'value:', value);
313
+ switch (type) {
314
+ case 'number':
315
+ return Number(value);
316
+ case 'string':
317
+ return value;
318
+ case 'bigint':
319
+ return ((this.bigIntValue * bigintPow(BigInt(10), this.decimal || 8)) /
320
+ this.decimalMultiplier);
321
+ }
322
+ }
323
+ catch (error) {
324
+ console.error(tag + 'Error in getValue:', error);
325
+ return null;
150
326
  }
151
327
  };
152
328
  // @ts-ignore
153
329
  BigIntArithmetics.prototype.getBaseValue = function (type) {
154
- var divisor = this.decimalMultiplier / toMultiplier(this.decimal || types_1.BaseDecimal.THOR);
155
- var baseValue = this.bigIntValue / divisor;
156
- switch (type) {
157
- case 'number':
158
- return Number(baseValue);
159
- case 'string':
160
- return baseValue.toString();
161
- case 'bigint':
162
- return baseValue;
330
+ var tag = TAG + " | getBaseValue | ";
331
+ try {
332
+ var divisor = this.decimalMultiplier / toMultiplier(this.decimal || types_1.BaseDecimal.THOR);
333
+ var baseValue = this.bigIntValue / divisor;
334
+ switch (type) {
335
+ case 'number':
336
+ return Number(baseValue);
337
+ case 'string':
338
+ return baseValue.toString();
339
+ case 'bigint':
340
+ return baseValue;
341
+ }
342
+ }
343
+ catch (error) {
344
+ console.error(tag + 'Error in getBaseValue:', error);
345
+ return null;
163
346
  }
164
347
  };
165
348
  BigIntArithmetics.prototype.getBigIntValue = function (value, decimal) {
166
- if (!decimal && typeof value === 'object' && value !== null) {
167
- return value.bigIntValue;
349
+ var tag = TAG + " | getBigIntValue | ";
350
+ try {
351
+ if (!decimal && typeof value === 'object' && value !== null) {
352
+ return value.bigIntValue;
353
+ }
354
+ var stringValue = getStringValue(value);
355
+ var safeValue = toSafeValue(stringValue);
356
+ if (safeValue === '0' || safeValue === 'undefined')
357
+ return BigInt(0);
358
+ return this.toBigInt(safeValue, decimal);
168
359
  }
169
- var stringValue = getStringValue(value);
170
- var safeValue = toSafeValue(stringValue);
171
- if (safeValue === '0' || safeValue === 'undefined')
360
+ catch (error) {
361
+ console.error(tag + 'Error in getBigIntValue:', error);
172
362
  return BigInt(0);
173
- return this.toBigInt(safeValue, decimal);
363
+ }
174
364
  };
175
365
  BigIntArithmetics.prototype.toSignificant = function (significantDigits) {
176
366
  if (significantDigits === void 0) { significantDigits = 6; }
177
- var _a = this.getValue('string').split('.'), int = _a[0], dec = _a[1];
178
- var integer = int || '';
179
- var decimal = dec || '';
180
- var valueLength = parseInt(integer) ? integer.length + decimal.length : decimal.length;
181
- if (valueLength <= significantDigits) {
182
- return this.getValue('string');
183
- }
184
- if (integer.length >= significantDigits) {
185
- return integer.slice(0, significantDigits).padEnd(integer.length, '0');
186
- }
187
- if (parseInt(integer)) {
188
- return "".concat(integer, ".").concat(decimal.slice(0, significantDigits - integer.length)).padEnd(significantDigits - integer.length, '0');
189
- }
190
- var trimmedDecimal = parseInt(decimal);
191
- var slicedDecimal = "".concat(trimmedDecimal).slice(0, significantDigits);
192
- return "0.".concat(slicedDecimal.padStart(decimal.length - "".concat(trimmedDecimal).length + slicedDecimal.length, '0'));
367
+ var tag = TAG + " | toSignificant | ";
368
+ try {
369
+ var _a = this.getValue('string').split('.'), int = _a[0], dec = _a[1];
370
+ var integer = int || '';
371
+ var decimal = dec || '';
372
+ var valueLength = parseInt(integer) ? integer.length + decimal.length : decimal.length;
373
+ if (valueLength <= significantDigits) {
374
+ return this.getValue('string');
375
+ }
376
+ if (integer.length >= significantDigits) {
377
+ return integer.slice(0, significantDigits).padEnd(integer.length, '0');
378
+ }
379
+ if (parseInt(integer)) {
380
+ return "".concat(integer, ".").concat(decimal.slice(0, significantDigits - integer.length)).padEnd(significantDigits - integer.length, '0');
381
+ }
382
+ var trimmedDecimal = parseInt(decimal);
383
+ var slicedDecimal = "".concat(trimmedDecimal).slice(0, significantDigits);
384
+ return "0.".concat(slicedDecimal.padStart(decimal.length - "".concat(trimmedDecimal).length + slicedDecimal.length, '0'));
385
+ }
386
+ catch (error) {
387
+ console.error(tag + 'Error in toSignificant:', error);
388
+ return '';
389
+ }
193
390
  };
194
391
  BigIntArithmetics.prototype.toFixed = function (fixedDigits) {
195
392
  if (fixedDigits === void 0) { fixedDigits = 6; }
196
- var _a = this.getValue('string').split('.'), int = _a[0], dec = _a[1];
197
- var integer = int || '';
198
- var decimal = dec || '';
199
- if (parseInt(integer)) {
200
- return "".concat(integer, ".").concat(decimal.slice(0, fixedDigits)).padEnd(fixedDigits, '0');
201
- }
202
- var trimmedDecimal = parseInt(decimal);
203
- var slicedDecimal = "".concat(trimmedDecimal).slice(0, fixedDigits);
204
- return "0.".concat(slicedDecimal.padStart(decimal.length - "".concat(trimmedDecimal).length + slicedDecimal.length, '0'));
393
+ var tag = TAG + " | toFixed | ";
394
+ try {
395
+ var _a = this.getValue('string').split('.'), int = _a[0], dec = _a[1];
396
+ var integer = int || '';
397
+ var decimal = dec || '';
398
+ if (parseInt(integer)) {
399
+ return "".concat(integer, ".").concat(decimal.slice(0, fixedDigits)).padEnd(fixedDigits, '0');
400
+ }
401
+ var trimmedDecimal = parseInt(decimal);
402
+ var slicedDecimal = "".concat(trimmedDecimal).slice(0, fixedDigits);
403
+ return "0.".concat(slicedDecimal.padStart(decimal.length - "".concat(trimmedDecimal).length + slicedDecimal.length, '0'));
404
+ }
405
+ catch (error) {
406
+ console.error(tag + 'Error in toFixed:', error);
407
+ return '';
408
+ }
205
409
  };
206
410
  BigIntArithmetics.prototype.toAbbreviation = function (digits) {
207
411
  if (digits === void 0) { digits = 2; }
208
- var value = this.getValue('number');
209
- var abbreviations = ['', 'K', 'M', 'B', 'T', 'Q', 'Qi', 'S'];
210
- var tier = Math.floor(Math.log10(Math.abs(value)) / 3);
211
- var suffix = abbreviations[tier];
212
- if (!suffix)
213
- return this.getValue('string');
214
- var scale = Math.pow(10, (tier * 3));
215
- var scaled = value / scale;
216
- return "".concat(scaled.toFixed(digits)).concat(suffix);
412
+ var tag = TAG + " | toAbbreviation | ";
413
+ try {
414
+ var value = this.getValue('number');
415
+ var abbreviations = ['', 'K', 'M', 'B', 'T', 'Q', 'Qi', 'S'];
416
+ var tier = Math.floor(Math.log10(Math.abs(value)) / 3);
417
+ var suffix = abbreviations[tier];
418
+ if (!suffix)
419
+ return this.getValue('string');
420
+ var scale = Math.pow(10, (tier * 3));
421
+ var scaled = value / scale;
422
+ return "".concat(scaled.toFixed(digits)).concat(suffix);
423
+ }
424
+ catch (error) {
425
+ console.error(tag + 'Error in toAbbreviation:', error);
426
+ return '';
427
+ }
217
428
  };
218
429
  BigIntArithmetics.prototype.toCurrency = function (currency, _a) {
219
430
  if (currency === void 0) { currency = '$'; }
220
431
  var _b = _a === void 0 ? {} : _a, _c = _b.currencyPosition, currencyPosition = _c === void 0 ? 'start' : _c, _d = _b.decimal, decimal = _d === void 0 ? 2 : _d, _e = _b.decimalSeparator, decimalSeparator = _e === void 0 ? '.' : _e, _f = _b.thousandSeparator, thousandSeparator = _f === void 0 ? ',' : _f;
221
- var value = this.getValue('number');
222
- var _g = value.toFixed(6).split('.'), int = _g[0], _h = _g[1], dec = _h === void 0 ? '' : _h;
223
- var integer = int.replace(/\B(?=(\d{3})+(?!\d))/g, thousandSeparator);
224
- var parsedValue = !int && !dec
225
- ? '0.00'
226
- : int === '0'
227
- ? "".concat(parseFloat("0.".concat(dec))).replace('.', decimalSeparator)
228
- : "".concat(integer).concat(parseInt(dec) ? "".concat(decimalSeparator).concat(dec.slice(0, decimal)) : '');
229
- return "".concat(currencyPosition === 'start' ? currency : '').concat(parsedValue).concat(currencyPosition === 'end' ? currency : '');
432
+ var tag = TAG + " | toCurrency | ";
433
+ try {
434
+ var value = this.getValue('number');
435
+ var _g = value.toFixed(6).split('.'), int = _g[0], _h = _g[1], dec = _h === void 0 ? '' : _h;
436
+ var integer = int.replace(/\B(?=(\d{3})+(?!\d))/g, thousandSeparator);
437
+ var parsedValue = !int && !dec
438
+ ? '0.00'
439
+ : int === '0'
440
+ ? "".concat(parseFloat("0.".concat(dec))).replace('.', decimalSeparator)
441
+ : "".concat(integer).concat(parseInt(dec) ? "".concat(decimalSeparator).concat(dec.slice(0, decimal)) : '');
442
+ return "".concat(currencyPosition === 'start' ? currency : '').concat(parsedValue).concat(currencyPosition === 'end' ? currency : '');
443
+ }
444
+ catch (error) {
445
+ console.error(tag + 'Error in toCurrency:', error);
446
+ return '';
447
+ }
230
448
  };
231
449
  BigIntArithmetics.prototype.arithmetics = function (method) {
232
450
  var _this = this;
@@ -234,84 +452,118 @@ var BigIntArithmetics = /** @class */ (function () {
234
452
  for (var _i = 1; _i < arguments.length; _i++) {
235
453
  args[_i - 1] = arguments[_i];
236
454
  }
237
- var precisionDecimal = this.retrievePrecisionDecimal.apply(this, __spreadArray([this], args, false));
238
- var decimal = Math.max(precisionDecimal, decimalFromMultiplier(this.decimalMultiplier));
239
- var precisionDecimalMultiplier = toMultiplier(decimal);
240
- var result = args.reduce(function (acc, arg) {
241
- var value = _this.getBigIntValue(arg, decimal);
242
- switch (method) {
243
- case 'add':
244
- return acc + value;
245
- case 'sub':
246
- return acc - value;
247
- case 'mul':
248
- return (acc * value) / precisionDecimalMultiplier;
249
- case 'div': {
250
- if (value === BigInt(0))
251
- throw new RangeError('Division by zero');
252
- return (acc * precisionDecimalMultiplier) / value;
455
+ var tag = TAG + " | arithmetics | ";
456
+ try {
457
+ var precisionDecimal = this.retrievePrecisionDecimal.apply(this, __spreadArray([this], args, false));
458
+ var decimal_1 = Math.max(precisionDecimal, decimalFromMultiplier(this.decimalMultiplier));
459
+ var precisionDecimalMultiplier_1 = toMultiplier(decimal_1);
460
+ var result = args.reduce(function (acc, arg) {
461
+ var value = _this.getBigIntValue(arg, decimal_1);
462
+ switch (method) {
463
+ case 'add':
464
+ return acc + value;
465
+ case 'sub':
466
+ return acc - value;
467
+ case 'mul':
468
+ return (acc * value) / precisionDecimalMultiplier_1;
469
+ case 'div': {
470
+ if (value === BigInt(0))
471
+ throw new RangeError('Division by zero');
472
+ return (acc * precisionDecimalMultiplier_1) / value;
473
+ }
474
+ default:
475
+ return acc;
253
476
  }
254
- default:
255
- return acc;
256
- }
257
- }, (this.bigIntValue * precisionDecimalMultiplier) / this.decimalMultiplier);
258
- var formattedValue = formatBigIntToSafeValue({
259
- bigIntDecimal: decimal,
260
- decimal: decimal,
261
- value: result,
262
- });
263
- return new BigIntArithmetics({
264
- decimalMultiplier: toMultiplier(decimal),
265
- decimal: this.decimal,
266
- value: formattedValue,
267
- });
477
+ }, (this.bigIntValue * precisionDecimalMultiplier_1) / this.decimalMultiplier);
478
+ var formattedValue = formatBigIntToSafeValue({
479
+ bigIntDecimal: decimal_1,
480
+ decimal: decimal_1,
481
+ value: result,
482
+ });
483
+ return new BigIntArithmetics({
484
+ decimalMultiplier: toMultiplier(decimal_1),
485
+ decimal: this.decimal,
486
+ value: formattedValue,
487
+ });
488
+ }
489
+ catch (error) {
490
+ console.error(tag + 'Error in arithmetics:', error);
491
+ return this;
492
+ }
268
493
  };
269
494
  BigIntArithmetics.prototype.comparison = function (method) {
270
495
  var args = [];
271
496
  for (var _i = 1; _i < arguments.length; _i++) {
272
497
  args[_i - 1] = arguments[_i];
273
498
  }
274
- var decimal = this.retrievePrecisionDecimal.apply(this, __spreadArray([this], args, false));
275
- var value = this.getBigIntValue(args[0], decimal);
276
- var compareToValue = this.getBigIntValue(this, decimal);
277
- switch (method) {
278
- case 'gt':
279
- return compareToValue > value;
280
- case 'gte':
281
- return compareToValue >= value;
282
- case 'lt':
283
- return compareToValue < value;
284
- case 'lte':
285
- return compareToValue <= value;
286
- case 'eqValue':
287
- return compareToValue === value;
499
+ var tag = TAG + " | comparison | ";
500
+ try {
501
+ var decimal = this.retrievePrecisionDecimal.apply(this, __spreadArray([this], args, false));
502
+ var value = this.getBigIntValue(args[0], decimal);
503
+ var compareToValue = this.getBigIntValue(this, decimal);
504
+ switch (method) {
505
+ case 'gt':
506
+ return compareToValue > value;
507
+ case 'gte':
508
+ return compareToValue >= value;
509
+ case 'lt':
510
+ return compareToValue < value;
511
+ case 'lte':
512
+ return compareToValue <= value;
513
+ case 'eqValue':
514
+ return compareToValue === value;
515
+ }
516
+ }
517
+ catch (error) {
518
+ console.error(tag + 'Error in comparison:', error);
519
+ return false;
288
520
  }
289
521
  };
290
522
  BigIntArithmetics.prototype.setValue = function (value) {
291
- var safeValue = toSafeValue(value) || '0';
292
- this.bigIntValue = this.toBigInt(safeValue);
523
+ var tag = TAG + " | setValue | ";
524
+ try {
525
+ var safeValue = toSafeValue(value) || '0';
526
+ this.bigIntValue = this.toBigInt(safeValue);
527
+ }
528
+ catch (error) {
529
+ console.error(tag + 'Error in setValue:', error);
530
+ }
293
531
  };
294
532
  BigIntArithmetics.prototype.retrievePrecisionDecimal = function () {
295
533
  var args = [];
296
534
  for (var _i = 0; _i < arguments.length; _i++) {
297
535
  args[_i] = arguments[_i];
298
536
  }
299
- var decimals = args
300
- .map(function (arg) {
301
- var isObject = typeof arg === 'object' && arg !== null;
302
- var value = isObject
303
- ? arg.decimal || decimalFromMultiplier(arg.decimalMultiplier)
304
- : getFloatDecimals(toSafeValue(arg));
305
- return value;
306
- })
307
- .filter(Boolean);
308
- return Math.max.apply(Math, __spreadArray(__spreadArray([], decimals, false), [DEFAULT_DECIMAL], false));
537
+ var tag = TAG + " | retrievePrecisionDecimal | ";
538
+ try {
539
+ var decimals = args
540
+ .map(function (arg) {
541
+ var isObject = typeof arg === 'object' && arg !== null;
542
+ var value = isObject
543
+ ? arg.decimal || decimalFromMultiplier(arg.decimalMultiplier)
544
+ : getFloatDecimals(toSafeValue(arg));
545
+ return value;
546
+ })
547
+ .filter(Boolean);
548
+ return Math.max.apply(Math, __spreadArray(__spreadArray([], decimals, false), [DEFAULT_DECIMAL], false));
549
+ }
550
+ catch (error) {
551
+ console.error(tag + 'Error in retrievePrecisionDecimal:', error);
552
+ return DEFAULT_DECIMAL;
553
+ }
309
554
  };
310
555
  BigIntArithmetics.prototype.toBigInt = function (value, decimal) {
311
- var multiplier = decimal ? toMultiplier(decimal) : this.decimalMultiplier;
312
- var padDecimal = decimalFromMultiplier(multiplier);
313
- var _a = value.split('.'), _b = _a[0], integerPart = _b === void 0 ? '' : _b, _c = _a[1], decimalPart = _c === void 0 ? '' : _c;
314
- return BigInt("".concat(integerPart).concat(decimalPart.padEnd(padDecimal, '0')));
556
+ var tag = TAG + " | toBigInt | ";
557
+ try {
558
+ var multiplier = decimal ? toMultiplier(decimal) : this.decimalMultiplier;
559
+ var padDecimal = decimalFromMultiplier(multiplier);
560
+ var _a = value.split('.'), _b = _a[0], integerPart = _b === void 0 ? '' : _b, _c = _a[1], decimalPart = _c === void 0 ? '' : _c;
561
+ return BigInt("".concat(integerPart).concat(decimalPart.padEnd(padDecimal, '0')));
562
+ }
563
+ catch (error) {
564
+ console.error(tag + 'Error in toBigInt:', error);
565
+ return BigInt(0);
566
+ }
315
567
  };
316
568
  return BigIntArithmetics;
317
569
  }());
@@ -321,24 +573,45 @@ var numberFormatter = Intl.NumberFormat('fullwide', {
321
573
  maximumFractionDigits: 20,
322
574
  });
323
575
  function toSafeValue(value) {
324
- var parsedValue = typeof value === 'number' ? numberFormatter.format(value) : getStringValue(value);
325
- var splitValue = "".concat(parsedValue).replace(/,/g, '.').split('.');
326
- return splitValue.length > 1
327
- ? "".concat(splitValue.slice(0, -1).join(''), ".").concat(splitValue.at(-1))
328
- : splitValue[0];
576
+ var tag = TAG + " | toSafeValue | ";
577
+ try {
578
+ var parsedValue = typeof value === 'number' ? numberFormatter.format(value) : getStringValue(value);
579
+ var splitValue = "".concat(parsedValue).replace(/,/g, '.').split('.');
580
+ return splitValue.length > 1
581
+ ? "".concat(splitValue.slice(0, -1).join(''), ".").concat(splitValue.at(-1))
582
+ : splitValue[0];
583
+ }
584
+ catch (error) {
585
+ console.error(tag + 'Error in toSafeValue:', error);
586
+ return '0';
587
+ }
329
588
  }
330
589
  function getFloatDecimals(value) {
331
- var decimals = 0;
332
- var parts = value.split('.');
333
- if (parts.length > 1 && parts[1].length > 0) {
334
- decimals = parts[1].length;
590
+ var tag = TAG + " | getFloatDecimals | ";
591
+ try {
592
+ var decimals = 0;
593
+ var parts = value.split('.');
594
+ if (parts.length > 1 && parts[1].length > 0) {
595
+ decimals = parts[1].length;
596
+ }
597
+ return Math.max(decimals, DEFAULT_DECIMAL);
598
+ }
599
+ catch (error) {
600
+ console.error(tag + 'Error in getFloatDecimals:', error);
601
+ return DEFAULT_DECIMAL;
335
602
  }
336
- return Math.max(decimals, DEFAULT_DECIMAL);
337
603
  }
338
604
  function getStringValue(param) {
339
- return typeof param === 'object' && param !== null
340
- ? 'getValue' in param
341
- ? param.getValue('string')
342
- : param.value
343
- : param;
605
+ var tag = TAG + " | getStringValue | ";
606
+ try {
607
+ return typeof param === 'object' && param !== null
608
+ ? 'getValue' in param
609
+ ? param.getValue('string')
610
+ : param.value
611
+ : param;
612
+ }
613
+ catch (error) {
614
+ console.error(tag + 'Error in getStringValue:', error);
615
+ return '';
616
+ }
344
617
  }