numora 3.0.2 → 3.2.0
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/README.md +33 -244
- package/dist/NumoraInput.d.ts +0 -1
- package/dist/features/compact-notation.d.ts +6 -2
- package/dist/features/formatting/cursor-position.d.ts +44 -1
- package/dist/features/formatting/digit-counting.d.ts +35 -12
- package/dist/features/formatting/index.d.ts +0 -4
- package/dist/features/non-numeric-characters.d.ts +1 -0
- package/dist/features/sanitization.d.ts +1 -1
- package/dist/features/scientific-notation.d.ts +4 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/index.mjs +595 -901
- package/dist/types.d.ts +2 -1
- package/dist/utils/locale.d.ts +14 -0
- package/dist/utils/regex-cache.d.ts +40 -0
- package/dist/validation.d.ts +1 -2
- package/package.json +5 -3
- package/dist/features/formatting/character-equivalence.d.ts +0 -9
- package/dist/features/formatting/large-number.d.ts +0 -39
- package/dist/features/formatting/numeric-formatting-utils.d.ts +0 -24
- package/dist/features/formatting/percent.d.ts +0 -45
- package/dist/features/formatting/subscript-notation.d.ts +0 -20
package/dist/types.d.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ThousandStyle } from '../types';
|
|
2
|
+
export declare function getSeparatorsFromLocale(locale?: string): {
|
|
3
|
+
thousandSeparator: string;
|
|
4
|
+
decimalSeparator: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function resolveLocaleOptions(options: {
|
|
7
|
+
thousandSeparator?: string;
|
|
8
|
+
thousandStyle?: ThousandStyle;
|
|
9
|
+
decimalSeparator?: string;
|
|
10
|
+
}): {
|
|
11
|
+
thousandSeparator: string;
|
|
12
|
+
thousandStyle: ThousandStyle;
|
|
13
|
+
decimalSeparator: string;
|
|
14
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regex caching utility for performance optimization.
|
|
3
|
+
* Caches compiled RegExp objects to avoid recompilation on every function call.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Gets a cached RegExp or creates and caches a new one.
|
|
7
|
+
* Use this for dynamic patterns that depend on user input (e.g., separators).
|
|
8
|
+
*
|
|
9
|
+
* @param pattern - The regex pattern string
|
|
10
|
+
* @param flags - Optional regex flags (default: 'g')
|
|
11
|
+
* @returns A cached RegExp object
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Instead of: new RegExp(escapeRegExp(separator), 'g')
|
|
15
|
+
* getCachedRegex(escapeRegExp(separator), 'g')
|
|
16
|
+
*/
|
|
17
|
+
export declare function getCachedRegex(pattern: string, flags?: string): RegExp;
|
|
18
|
+
/**
|
|
19
|
+
* Gets a cached RegExp for a separator character.
|
|
20
|
+
* Handles escaping of special regex characters automatically.
|
|
21
|
+
*
|
|
22
|
+
* @param separator - The separator character to match
|
|
23
|
+
* @param flags - Optional regex flags (default: 'g')
|
|
24
|
+
* @returns A cached RegExp object that matches the separator
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* getCachedSeparatorRegex(',') // Returns cached /,/g
|
|
28
|
+
* getCachedSeparatorRegex('.') // Returns cached /\./g (escaped)
|
|
29
|
+
*/
|
|
30
|
+
export declare function getCachedSeparatorRegex(separator: string, flags?: string): RegExp;
|
|
31
|
+
/**
|
|
32
|
+
* Clears the regex cache.
|
|
33
|
+
* Useful for testing or when separator configuration changes significantly.
|
|
34
|
+
*/
|
|
35
|
+
export declare function clearRegexCache(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Gets the current size of the regex cache.
|
|
38
|
+
* Useful for debugging and monitoring.
|
|
39
|
+
*/
|
|
40
|
+
export declare function getRegexCacheSize(): number;
|
package/dist/validation.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "numora",
|
|
3
|
-
"version": "3.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.2.0",
|
|
4
|
+
"description": "Framework-agnostic numeric input library for DeFi and financial apps",
|
|
5
5
|
"homepage": "https://numora.xyz/",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -52,16 +52,18 @@
|
|
|
52
52
|
"license": "MIT",
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@types/node": "^22.13.11",
|
|
55
|
+
"fast-check": "^3.15.0",
|
|
55
56
|
"jsdom": "^26.0.0",
|
|
56
57
|
"typescript": "^5.8.2",
|
|
57
58
|
"vite": "^6.2.2",
|
|
58
59
|
"vitest": "^3.0.9"
|
|
59
60
|
},
|
|
61
|
+
"sideEffects": false,
|
|
60
62
|
"publishConfig": {
|
|
61
63
|
"access": "public"
|
|
62
64
|
},
|
|
63
65
|
"scripts": {
|
|
64
|
-
"build": "vite build
|
|
66
|
+
"build": "vite build && tsc --emitDeclarationOnly",
|
|
65
67
|
"test": "vitest run",
|
|
66
68
|
"dev": "vite build --watch"
|
|
67
69
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Character equivalence utilities for cursor position calculation.
|
|
3
|
-
*/
|
|
4
|
-
import type { IsCharacterEquivalent } from './cursor-position';
|
|
5
|
-
/**
|
|
6
|
-
* Default character equivalence function.
|
|
7
|
-
* Only considers identical characters as equivalent.
|
|
8
|
-
*/
|
|
9
|
-
export declare const defaultIsCharacterEquivalent: IsCharacterEquivalent;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Large number formatting utilities for displaying numbers with scale notation (k, M, T, etc.).
|
|
3
|
-
* These are display-only utilities, not for input formatting.
|
|
4
|
-
*/
|
|
5
|
-
import { ThousandStyle } from '@/types';
|
|
6
|
-
export interface FormatLargeNumberOptions {
|
|
7
|
-
/** Minimum scale threshold - only apply scale notation above this (default: 0, meaning always apply if applicable) */
|
|
8
|
-
minScale?: number;
|
|
9
|
-
/** Under what value should decimals be shown (default: 1000) */
|
|
10
|
-
decimalsUnder?: number;
|
|
11
|
-
/** Maximum decimal places to show (default: 2) */
|
|
12
|
-
decimals?: number;
|
|
13
|
-
/** Minimum decimal places to show (default: 0) */
|
|
14
|
-
decimalsMin?: number;
|
|
15
|
-
/** Show minimum decimals even when value is 0 (default: false) */
|
|
16
|
-
decimalsMinAppliesToZero?: boolean;
|
|
17
|
-
/** Placeholder for very large numbers that exceed our scale notation (default: '🔥') */
|
|
18
|
-
veryLargePlaceholder?: string;
|
|
19
|
-
/** Decimal separator (default: '.') */
|
|
20
|
-
decimalSeparator?: string;
|
|
21
|
-
/** Thousand separator for formatting (optional) */
|
|
22
|
-
thousandSeparator?: string;
|
|
23
|
-
/** Thousand grouping style (default: None) */
|
|
24
|
-
thousandStyle?: ThousandStyle;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Formats a large number with scale notation (k, M, T, etc.) for display.
|
|
28
|
-
*
|
|
29
|
-
* @param value - The numeric string value to format
|
|
30
|
-
* @param options - Optional formatting options
|
|
31
|
-
* @returns The formatted string with scale suffix if applicable
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* formatLargeNumber("123") // "123"
|
|
35
|
-
* formatLargeNumber("1234") // "1.23k"
|
|
36
|
-
* formatLargeNumber("1234567") // "1.23M"
|
|
37
|
-
* formatLargeNumber("0") // "0"
|
|
38
|
-
*/
|
|
39
|
-
export declare function formatLargeNumber(value: string, options?: FormatLargeNumberOptions): string;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Common utilities for numeric formatting.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Checks if a numeric string represents a very large number.
|
|
6
|
-
*/
|
|
7
|
-
export declare function isVeryLarge(value: string): boolean;
|
|
8
|
-
/**
|
|
9
|
-
* Compares two numeric strings using string comparison.
|
|
10
|
-
* Returns negative if a < b, positive if a > b, 0 if equal.
|
|
11
|
-
* Uses string-based comparison to avoid precision issues.
|
|
12
|
-
*/
|
|
13
|
-
export declare function compareStrings(a: string, b: string): number;
|
|
14
|
-
/**
|
|
15
|
-
* Applies scale notation to a numeric string.
|
|
16
|
-
*/
|
|
17
|
-
export declare function applyScaleNotation(value: string, decimalSeparator: string, minScale?: number): {
|
|
18
|
-
scaledValue: string;
|
|
19
|
-
scaleSuffix: string;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Helper for applying decimal precision and handling trailing zeros.
|
|
23
|
-
*/
|
|
24
|
-
export declare function applyDecimalPrecision(value: string, decimals: number, decimalsMin: number, decimalSeparator: string, decimalsMinAppliesToZero?: boolean, isZeroValue?: boolean): string;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Percent formatting utilities for displaying numeric values as percentages.
|
|
3
|
-
* All functions use string arithmetic to avoid precision loss.
|
|
4
|
-
*/
|
|
5
|
-
import { ThousandStyle } from '@/types';
|
|
6
|
-
/**
|
|
7
|
-
* Formats a decimal value as a percentage string.
|
|
8
|
-
* Input is expected as a decimal (e.g., 0.01 represents 1%).
|
|
9
|
-
*
|
|
10
|
-
* @param value - The numeric string value (as decimal, e.g., "0.01" for 1%)
|
|
11
|
-
* @param decimals - Number of decimal places to show (default: 2)
|
|
12
|
-
* @param decimalSeparator - The decimal separator character (default: '.')
|
|
13
|
-
* @param thousandSeparator - Optional thousand separator for large percentages
|
|
14
|
-
* @param thousandStyle - Optional thousand grouping style
|
|
15
|
-
* @returns The formatted percentage string (e.g., "1.00%")
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* formatPercent("0.01", 2) // "1.00%"
|
|
19
|
-
* formatPercent("0.1234", 2) // "12.34%"
|
|
20
|
-
* formatPercent("1", 0) // "100%"
|
|
21
|
-
* formatPercent("0", 2) // "0%"
|
|
22
|
-
*/
|
|
23
|
-
export declare function formatPercent(value: string, decimals?: number, decimalSeparator?: string, thousandSeparator?: string, thousandStyle?: ThousandStyle): string;
|
|
24
|
-
/**
|
|
25
|
-
* Formats a large percentage value with scale notation (k, M, T, etc.) for very large percentages.
|
|
26
|
-
* Input is expected as a decimal (e.g., 0.01 represents 1%).
|
|
27
|
-
*
|
|
28
|
-
* @param value - The numeric string value (as decimal, e.g., "0.01" for 1%)
|
|
29
|
-
* @param decimals - Number of decimal places to show for values under threshold (default: 2)
|
|
30
|
-
* @param options - Optional formatting options
|
|
31
|
-
* @returns The formatted percentage string with scale suffix if needed (e.g., "1.23M%")
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* formatLargePercent("0.01", 2) // "1.00%"
|
|
35
|
-
* formatLargePercent("1000", 2) // "100000%"
|
|
36
|
-
* formatLargePercent("1000000", 2) // "100M%"
|
|
37
|
-
*/
|
|
38
|
-
export declare function formatLargePercent(value: string | null | undefined, decimals?: number, options?: {
|
|
39
|
-
missingPlaceholder?: string;
|
|
40
|
-
veryLargePlaceholder?: string;
|
|
41
|
-
decimalsUnder?: number;
|
|
42
|
-
decimalSeparator?: string;
|
|
43
|
-
thousandSeparator?: string;
|
|
44
|
-
thousandStyle?: ThousandStyle;
|
|
45
|
-
}): string;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Subscript notation utilities for condensing leading decimal zeros.
|
|
3
|
-
* Converts very small numbers like 0.000001 to 0₆1 for better readability.
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Condenses leading decimal zeros in a numeric string to subscript notation.
|
|
7
|
-
* For example: 0.000001 → 0₆1 (meaning 6 leading zeros)
|
|
8
|
-
*
|
|
9
|
-
* @param value - The numeric string value to condense
|
|
10
|
-
* @param maxDecimalDigits - Maximum number of decimal digits to show after condensation
|
|
11
|
-
* @param decimalSeparator - The decimal separator character (default: '.')
|
|
12
|
-
* @returns The condensed string with subscript notation for leading zeros
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* condenseDecimalZeros("0.000001", 8) // "0₆1"
|
|
16
|
-
* condenseDecimalZeros("0.000123", 8) // "0₃123"
|
|
17
|
-
* condenseDecimalZeros("1.000001", 8) // "1.000001" (no leading zeros to condense)
|
|
18
|
-
* condenseDecimalZeros("0.123", 8) // "0.123" (not enough zeros to condense)
|
|
19
|
-
*/
|
|
20
|
-
export declare function condenseDecimalZeros(value: string, maxDecimalDigits?: number, decimalSeparator?: string): string;
|