@rabex-kit/rabex-ui 0.2.46 → 0.2.49

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.
@@ -398,6 +398,34 @@ var charachter = ['.', ','];
398
398
  // ============================================================================
399
399
  // CORE UTILITY FUNCTIONS - SCIENTIFIC NOTATION SAFE
400
400
  // ============================================================================
401
+ /**
402
+ * Detect the number of meaningful decimal places in a number
403
+ * @param num - The number to analyze
404
+ * @returns Number of decimal places that contain meaningful data
405
+ */
406
+ var detectPrecision = function detectPrecision(num) {
407
+ if (num === 0) return 0;
408
+ // Convert to string to analyze the original input precision
409
+ var str = num.toString();
410
+ // Handle scientific notation
411
+ if (str.includes('e')) {
412
+ var _str$split = str.split('e'),
413
+ base = _str$split[0],
414
+ exp = _str$split[1];
415
+ var exponent = parseInt(exp);
416
+ var baseDecimals = base.includes('.') ? base.split('.')[1].length : 0;
417
+ if (exponent < 0) {
418
+ return Math.abs(exponent) + baseDecimals;
419
+ } else {
420
+ return Math.max(0, baseDecimals - exponent);
421
+ }
422
+ }
423
+ // Handle regular decimal notation
424
+ if (str.includes('.')) {
425
+ return str.split('.')[1].length;
426
+ }
427
+ return 0;
428
+ };
401
429
  /**
402
430
  * CONVERT SCIENTIFIC NOTATION TO DECIMAL STRING
403
431
  *
@@ -419,30 +447,27 @@ var charachter = ['.', ','];
419
447
  * convertScientific("abc") → undefined
420
448
  */
421
449
  var convertScientific = function convertScientific(num) {
422
- // Handle null, undefined, or empty string inputs
423
450
  if (num === null || num === undefined || num === '') {
424
451
  return undefined;
425
452
  }
426
- // Convert input to number for validation and processing
427
453
  var numValue = Number(num);
428
- // Validate that the result is a finite number
429
454
  if (isNaN(numValue) || !isFinite(numValue)) {
430
455
  return undefined;
431
456
  }
432
- // Handle exact zero case
433
457
  if (numValue === 0) return '0';
434
- // Handle very large integers using BigInt to avoid precision loss
435
- // Numbers >= 1e15 may lose precision in JavaScript's Number type
458
+ // Handle very large integers
436
459
  if (Math.abs(numValue) >= 1e15 && Number.isInteger(numValue)) {
437
460
  return BigInt(Math.round(numValue)).toString();
438
461
  }
439
- // Handle very small numbers that would round to zero
462
+ // Handle very small numbers
440
463
  if (Math.abs(numValue) < 1e-15) {
441
464
  return '0';
442
465
  }
443
- // Convert to fixed decimal notation with high precision
444
- // Then remove trailing zeros for clean output
445
- return numValue.toFixed(20).replace(/\.?0+$/, '');
466
+ // SOLUTION 1: Intelligent precision detection
467
+ var detectedPrecision = detectPrecision(numValue);
468
+ var safePrecision = Math.min(detectedPrecision + 2, 15); // Add buffer but cap at 15
469
+ var result = numValue.toFixed(safePrecision).replace(/\.?0+$/, '');
470
+ return result;
446
471
  };
447
472
  /**
448
473
  * SAFE NUMBER CONVERSION
@@ -756,22 +781,32 @@ var enhancedRoundDown = function enhancedRoundDown(val, dec) {
756
781
  var formatted = parseFloat(result).toFixed(dec);
757
782
  return formatted.replace(/^([\d,]+)$|^([\d,]+)\.0*$|^([\d,]+\.[0-9]*?)0*$/, '$1$2$3');
758
783
  };
784
+ var _roundUp = function roundUp(val, dec) {
785
+ var decimal = dec === 0 ? 0 : +("1" + new Array(dec + 1).join('0'));
786
+ var result = decimal === 0 ? Math.ceil(val) : Math.ceil(+bigDecimal.multiply(val, decimal)) / decimal;
787
+ return result ? result.toFixed(dec).replace(/^([\d,]+)$|^([\d,]+)\.0*$|^([\d,]+\.[0-9]*?)0*$/, '$1$2$3') : '0';
788
+ };
789
+ var _roundDown = function roundDown(val, dec) {
790
+ var decimal = dec === 0 ? 0 : +("1" + new Array(dec + 1).join('0'));
791
+ var result = decimal === 0 ? Math.floor(val) : Math.floor(+bigDecimal.multiply(val, decimal)) / decimal;
792
+ return result ? result.toFixed(dec).replace(/^([\d,]+)$|^([\d,]+)\.0*$|^([\d,]+\.[0-9]*?)0*$/, '$1$2$3') : '0';
793
+ };
759
794
  /**
760
795
  * BACKWARD COMPATIBLE ROUND UP
761
796
  *
762
797
  * Purpose: Wrapper function maintaining original API while using enhanced implementation
763
798
  */
764
- var _roundUp = function roundUp(val, dec) {
765
- return enhancedRoundUp(val, dec);
766
- };
799
+ // const roundUp = (val: number, dec: number): string => {
800
+ // return enhancedRoundUp(val, dec);
801
+ // };
767
802
  /**
768
803
  * BACKWARD COMPATIBLE ROUND DOWN
769
804
  *
770
805
  * Purpose: Wrapper function maintaining original API while using enhanced implementation
771
806
  */
772
- var _roundDown = function roundDown(val, dec) {
773
- return enhancedRoundDown(val, dec);
774
- };
807
+ // const roundDown = (val: number, dec: number): string => {
808
+ // return enhancedRoundDown(val, dec);
809
+ // };
775
810
  // ============================================================================
776
811
  // VALIDATION & CONVERSION FUNCTIONS
777
812
  // ============================================================================