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