Skip to content

Commit 49893eb

Browse files
committed
Updating types files
1 parent 7102c48 commit 49893eb

File tree

2 files changed

+154
-1
lines changed

2 files changed

+154
-1
lines changed

types/constants.d.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const EXPONENT: "exponent";
2626
export const ROUND: "round";
2727

2828
// Special Characters and Values
29+
export const E: "e";
2930
export const EMPTY: "";
3031
export const PERIOD: ".";
3132
export const S: "s";
@@ -48,4 +49,33 @@ export const STRINGS: {
4849
iec: ["", "kibi", "mebi", "gibi", "tebi", "pebi", "exbi", "zebi", "yobi"];
4950
jedec: ["", "kilo", "mega", "giga", "tera", "peta", "exa", "zetta", "yotta"];
5051
};
51-
};
52+
};
53+
54+
// Pre-computed lookup tables for performance optimization
55+
export const BINARY_POWERS: readonly [
56+
1, // 2^0
57+
1024, // 2^10
58+
1048576, // 2^20
59+
1073741824, // 2^30
60+
1099511627776, // 2^40
61+
1125899906842624, // 2^50
62+
1152921504606846976, // 2^60
63+
1180591620717411303424, // 2^70
64+
1208925819614629174706176 // 2^80
65+
];
66+
67+
export const DECIMAL_POWERS: readonly [
68+
1, // 10^0
69+
1000, // 10^3
70+
1000000, // 10^6
71+
1000000000, // 10^9
72+
1000000000000, // 10^12
73+
1000000000000000, // 10^15
74+
1000000000000000000, // 10^18
75+
1000000000000000000000, // 10^21
76+
1000000000000000000000000 // 10^24
77+
];
78+
79+
// Pre-computed log values for faster exponent calculation
80+
export const LOG_2_1024: number;
81+
export const LOG_10_1000: number;

types/helpers.d.ts

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/**
2+
* Configuration object returned by getBaseConfiguration
3+
*/
4+
export interface BaseConfiguration {
5+
/** Whether to use decimal (base 10) calculations */
6+
isDecimal: boolean;
7+
/** Ceiling value for auto-increment calculations */
8+
ceil: number;
9+
/** The actual standard to use for formatting */
10+
actualStandard: string;
11+
}
12+
13+
/**
14+
* Value calculation result
15+
*/
16+
export interface OptimizedValueResult {
17+
/** The calculated result value */
18+
result: number;
19+
/** The adjusted exponent */
20+
e: number;
21+
}
22+
23+
/**
24+
* Precision handling result
25+
*/
26+
export interface PrecisionHandlingResult {
27+
/** The formatted value */
28+
value: string | number;
29+
/** The adjusted exponent */
30+
e: number;
31+
}
32+
33+
/**
34+
* Optimized base configuration lookup
35+
* @param standard - Standard type
36+
* @param base - Base number
37+
* @returns Configuration object
38+
*/
39+
export function getBaseConfiguration(standard: string, base: number): BaseConfiguration;
40+
41+
/**
42+
* Optimized zero value handling
43+
* @param precision - Precision value
44+
* @param actualStandard - Standard to use
45+
* @param bits - Whether to use bits
46+
* @param symbols - Custom symbols
47+
* @param full - Whether to use full form
48+
* @param fullforms - Custom full forms
49+
* @param output - Output format
50+
* @param spacer - Spacer character
51+
* @returns Formatted result
52+
*/
53+
export function handleZeroValue(
54+
precision: number,
55+
actualStandard: string,
56+
bits: boolean,
57+
symbols: Record<string, string>,
58+
full: boolean,
59+
fullforms: string[],
60+
output: string,
61+
spacer: string
62+
): string | [number | string, string] | { value: number | string; symbol: string; exponent: number; unit: string } | number;
63+
64+
/**
65+
* Optimized value calculation with bits handling
66+
* @param num - Input number
67+
* @param e - Exponent
68+
* @param isDecimal - Whether to use decimal powers
69+
* @param bits - Whether to calculate bits
70+
* @param ceil - Ceiling value for auto-increment
71+
* @returns Object with result and e properties
72+
*/
73+
export function calculateOptimizedValue(
74+
num: number,
75+
e: number,
76+
isDecimal: boolean,
77+
bits: boolean,
78+
ceil: number
79+
): OptimizedValueResult;
80+
81+
/**
82+
* Optimized precision handling with scientific notation correction
83+
* @param value - Current value
84+
* @param precision - Precision to apply
85+
* @param e - Current exponent
86+
* @param num - Original number
87+
* @param isDecimal - Whether using decimal base
88+
* @param bits - Whether calculating bits
89+
* @param ceil - Ceiling value
90+
* @param roundingFunc - Rounding function
91+
* @param round - Round value
92+
* @returns Object with value and e properties
93+
*/
94+
export function applyPrecisionHandling(
95+
value: number,
96+
precision: number,
97+
e: number,
98+
num: number,
99+
isDecimal: boolean,
100+
bits: boolean,
101+
ceil: number,
102+
roundingFunc: (x: number) => number,
103+
round: number
104+
): PrecisionHandlingResult;
105+
106+
/**
107+
* Optimized number formatting with locale, separator, and padding
108+
* @param value - Value to format
109+
* @param locale - Locale setting
110+
* @param localeOptions - Locale options
111+
* @param separator - Custom separator
112+
* @param pad - Whether to pad
113+
* @param round - Round value
114+
* @returns Formatted value
115+
*/
116+
export function applyNumberFormatting(
117+
value: number | string,
118+
locale: string | boolean,
119+
localeOptions: Intl.NumberFormatOptions,
120+
separator: string,
121+
pad: boolean,
122+
round: number
123+
): string | number;

0 commit comments

Comments
 (0)