@pioneer-platform/helpers 4.0.13 → 4.1.1

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