@rabex-kit/rabex-ui 0.2.45 → 0.2.46

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,30 +1,202 @@
1
1
  import bigDecimal from 'js-big-decimal';
2
- declare function suffix(num: number | string, options: {
2
+ /**
3
+ * Type definition for suffix function options
4
+ */
5
+ interface SuffixOptions {
3
6
  precision?: number;
4
7
  round?: 'roundDown' | 'roundUp';
5
8
  suffix?: Array<'K' | 'M' | 'B' | 'T'>;
6
- }): string;
9
+ }
10
+ /**
11
+ * NUMBER SUFFIX FORMATTER (K, M, B, T)
12
+ *
13
+ * Purpose: Converts large numbers to human-readable format with suffixes
14
+ *
15
+ * @param num - Input number to format
16
+ * @param options - Formatting options (precision, rounding method, allowed suffixes)
17
+ * @returns Formatted string with appropriate suffix
18
+ *
19
+ * Key Features:
20
+ * - Uses bigDecimal for all calculations to avoid scientific notation
21
+ * - Supports custom precision and rounding methods
22
+ * - Configurable suffix types (K=thousands, M=millions, B=billions, T=trillions)
23
+ * - Falls back to original number if no suffix applies
24
+ *
25
+ * Examples:
26
+ * suffix(1000, {precision: 1}) → "1K"
27
+ * suffix(1500000, {precision: 2, round: 'roundUp'}) → "1.5M"
28
+ * suffix(2.5e9) → "2.5B"
29
+ *
30
+ * Scientific Notation Prevention:
31
+ * - Uses string-based thresholds instead of numeric literals
32
+ * - BigDecimal comparison instead of JavaScript's Math.abs()
33
+ * - BigDecimal division instead of standard division operator
34
+ */
35
+ declare function suffix(num: number | string, options?: SuffixOptions): string;
7
36
  declare const _default: {
37
+ /**
38
+ * Add thousand separators to numbers
39
+ * Usage: delimiter(1234567) → "1,234,567"
40
+ */
8
41
  delimiter: (num: number | string, separator?: string | undefined, separateBy?: number | undefined) => string | number;
9
- removeDelimiter: (num: string, separator?: string) => number;
42
+ /**
43
+ * Remove thousand separators from formatted strings
44
+ * Usage: removeDelimiter("1,234,567") → "1234567"
45
+ */
46
+ removeDelimiter: (num: string, separator?: string) => string;
47
+ /**
48
+ * Format large numbers with K/M/B/T suffixes
49
+ * Usage: suffix(1000000) → "1M"
50
+ */
51
+ suffix: typeof suffix;
52
+ /**
53
+ * Round number down to specified decimal places
54
+ * Usage: roundDown(3.14159, 2) → "3.14"
55
+ */
10
56
  roundDown: (val: number, dec: number) => string;
57
+ /**
58
+ * Round number up to specified decimal places
59
+ * Usage: roundUp(3.14159, 2) → "3.15"
60
+ */
11
61
  roundUp: (val: number, dec: number) => string;
62
+ /**
63
+ * Validate if decimal places are within specified limit
64
+ * Usage: isDecimalValid("12.34", 2) → true
65
+ */
12
66
  isDecimalValid: (val: string, dec: number) => boolean;
67
+ /**
68
+ * Validate if input contains only valid numeric characters
69
+ * Usage: isValid("123.45") → true
70
+ */
13
71
  isValid: (val: number | string) => boolean;
14
- toEn: (val: string) => any;
15
- suffix: typeof suffix;
72
+ /**
73
+ * Convert Persian numerals to English numerals
74
+ * Usage: toEn("۱۲۳") → "123"
75
+ */
76
+ toEn: (val: string) => string;
77
+ /**
78
+ * Convert scientific notation to decimal string
79
+ * Usage: convertScientific(1e-8) → "0.00000001"
80
+ */
81
+ convertScientific: (num: string | number) => string | undefined;
82
+ /**
83
+ * Safe number conversion with fallback to "0"
84
+ * Usage: safeNumber(1e-8) → "0.00000001"
85
+ */
86
+ safeNumber: (num: string | number) => string;
87
+ /**
88
+ * Complete suite of safe mathematical operations
89
+ * All operations prevent scientific notation and maintain precision
90
+ */
91
+ safeMath: {
92
+ /**
93
+ * SAFE ADDITION
94
+ * @param num1 - First addend
95
+ * @param num2 - Second addend
96
+ * @returns Sum as decimal string
97
+ */
98
+ add: (num1: string | number, num2: string | number) => string;
99
+ /**
100
+ * SAFE SUBTRACTION
101
+ * @param num1 - Minuend (number to subtract from)
102
+ * @param num2 - Subtrahend (number to subtract)
103
+ * @returns Difference as decimal string
104
+ */
105
+ subtract: (num1: string | number, num2: string | number) => string;
106
+ /**
107
+ * SAFE MULTIPLICATION
108
+ * @param num1 - First factor
109
+ * @param num2 - Second factor
110
+ * @returns Product as decimal string
111
+ */
112
+ multiply: (num1: string | number, num2: string | number) => string;
113
+ /**
114
+ * SAFE DIVISION
115
+ * @param num1 - Dividend
116
+ * @param num2 - Divisor
117
+ * @param precision - Decimal places in result (default: 10)
118
+ * @returns Quotient as decimal string
119
+ */
120
+ divide: (num1: string | number, num2: string | number, precision?: number) => string;
121
+ };
122
+ /**
123
+ * Direct access to bigDecimal library for advanced operations
124
+ */
16
125
  bigDecimal: typeof bigDecimal;
17
- modulus: typeof bigDecimal.modulus;
18
- divide: (num1: string | number, num2: string | number, precision: any) => string;
19
- multiply: typeof bigDecimal.multiply;
20
- subtract: typeof bigDecimal.subtract;
21
- add: typeof bigDecimal.add;
22
- negate: typeof bigDecimal.negate;
23
- compareTo: typeof bigDecimal.compareTo;
24
- ceil: typeof bigDecimal.ceil;
25
- floor: typeof bigDecimal.floor;
26
- abs: typeof bigDecimal.abs;
27
- round: typeof bigDecimal.round;
28
- getPrettyValue: typeof bigDecimal.getPrettyValue;
126
+ /**
127
+ * Modulus operation with precision
128
+ * Usage: modulus(10, 3) → remainder as string
129
+ */
130
+ modulus: (num1: number | string, num2: number | string) => string;
131
+ /**
132
+ * Division with configurable precision
133
+ * Usage: divide(10, 3, 4) → "3.3333"
134
+ */
135
+ divide: (num1: string | number, num2: string | number, precision?: number) => string;
136
+ /**
137
+ * Multiplication with precision
138
+ * Usage: multiply(1.5, 2.3) → "3.45"
139
+ */
140
+ multiply: (num1: number | string, num2: number | string) => string;
141
+ /**
142
+ * Subtraction with precision
143
+ * Usage: subtract(10, 3.5) → "6.5"
144
+ */
145
+ subtract: (num1: number | string, num2: number | string) => string;
146
+ /**
147
+ * Addition with precision
148
+ * Usage: add(1.1, 2.2) → "3.3"
149
+ */
150
+ add: (num1: number | string, num2: number | string) => string;
151
+ /**
152
+ * Number negation
153
+ * Usage: negate(5) → "-5"
154
+ */
155
+ negate: (num: number | string) => string;
156
+ /**
157
+ * Number comparison (-1: less, 0: equal, 1: greater)
158
+ * Usage: compareTo(5, 3) → 1
159
+ */
160
+ compareTo: (num1: number | string, num2: number | string) => 0 | 1 | -1;
161
+ /**
162
+ * Ceiling function (round up to nearest integer)
163
+ * Usage: ceil(3.14) → "4"
164
+ */
165
+ ceil: (num: number | string) => any;
166
+ /**
167
+ * Floor function (round down to nearest integer)
168
+ * Usage: floor(3.14) → "3"
169
+ */
170
+ floor: (num: number | string) => any;
171
+ /**
172
+ * Absolute value
173
+ * Usage: abs(-5) → "5"
174
+ */
175
+ abs: (num: number | string) => string;
176
+ /**
177
+ * Round to specified precision
178
+ * Usage: round(3.14159, 2) → "3.14"
179
+ */
180
+ round: (num: number | string, precision: number) => string;
181
+ /**
182
+ * Format number with pretty printing (thousands separators)
183
+ * Usage: getPrettyValue(1234567, 2, ",") → "1,234,567.00"
184
+ */
185
+ getPrettyValue: (num: number | string, precision?: number | undefined, separator?: string | undefined) => string;
29
186
  };
187
+ /**
188
+ * COMPREHENSIVE NUMBER UTILITIES EXPORT
189
+ *
190
+ * This object provides the complete API for all number operations, formatting,
191
+ * validation, and mathematical calculations. All functions are designed to
192
+ * prevent scientific notation and maintain high precision.
193
+ *
194
+ * Categories:
195
+ * 1. Formatting: delimiter, removeDelimiter, suffix
196
+ * 2. Rounding: roundUp, roundDown
197
+ * 3. Validation: isValid, isDecimalValid
198
+ * 4. Conversion: toEn, convertScientific, safeNumber
199
+ * 5. Mathematics: All bigDecimal operations + safeMath suite
200
+ * 6. Utilities: Direct access to bigDecimal library
201
+ */
30
202
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabex-kit/rabex-ui",
3
- "version": "0.2.45",
3
+ "version": "0.2.46",
4
4
  "license": "MIT",
5
5
  "author": "Seyyed Mahdi Hosseini",
6
6
  "main": "dist/index.js",