numora 2.0.4 → 3.0.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.
Files changed (32) hide show
  1. package/dist/NumoraInput.d.ts +67 -0
  2. package/dist/config.d.ts +11 -0
  3. package/dist/features/compact-notation.d.ts +17 -0
  4. package/dist/features/decimals.d.ts +21 -0
  5. package/dist/features/formatting/caret-position-utils.d.ts +54 -0
  6. package/dist/features/formatting/change-detection.d.ts +40 -0
  7. package/dist/features/formatting/character-equivalence.d.ts +9 -0
  8. package/dist/features/formatting/constants.d.ts +29 -0
  9. package/dist/features/formatting/cursor-boundary.d.ts +39 -0
  10. package/dist/features/formatting/cursor-position.d.ts +50 -0
  11. package/dist/features/formatting/digit-counting.d.ts +61 -0
  12. package/dist/features/formatting/index.d.ts +20 -0
  13. package/dist/features/formatting/large-number.d.ts +39 -0
  14. package/dist/features/formatting/numeric-formatting-utils.d.ts +24 -0
  15. package/dist/features/formatting/percent.d.ts +45 -0
  16. package/dist/features/formatting/subscript-notation.d.ts +20 -0
  17. package/dist/features/formatting/thousand-grouping.d.ts +34 -0
  18. package/dist/features/leading-zeros.d.ts +18 -0
  19. package/dist/features/mobile-keyboard-filtering.d.ts +18 -0
  20. package/dist/features/non-numeric-characters.d.ts +9 -0
  21. package/dist/features/sanitization.d.ts +44 -0
  22. package/dist/features/scientific-notation.d.ts +9 -0
  23. package/dist/index.d.ts +5 -0
  24. package/dist/index.js +1 -1
  25. package/dist/index.mjs +386 -388
  26. package/dist/types.d.ts +34 -0
  27. package/dist/utils/escape-reg-exp.d.ts +16 -0
  28. package/dist/utils/event-handlers.d.ts +31 -0
  29. package/dist/utils/format-utils.d.ts +28 -0
  30. package/dist/utils/input-pattern.d.ts +5 -0
  31. package/dist/validation.d.ts +20 -0
  32. package/package.json +2 -2
@@ -0,0 +1,34 @@
1
+ export declare enum FormatOn {
2
+ Blur = "blur",
3
+ Change = "change"
4
+ }
5
+ export declare enum ThousandStyle {
6
+ None = "none",
7
+ Thousand = "thousand",
8
+ Lakh = "lakh",
9
+ Wan = "wan"
10
+ }
11
+ export interface FormattingOptions {
12
+ formatOn?: FormatOn;
13
+ thousandSeparator?: string;
14
+ ThousandStyle?: ThousandStyle;
15
+ enableCompactNotation?: boolean;
16
+ enableNegative?: boolean;
17
+ enableLeadingZeros?: boolean;
18
+ decimalSeparator?: string;
19
+ decimalMinLength?: number;
20
+ rawValueMode?: boolean;
21
+ }
22
+ export interface CaretPositionInfo {
23
+ selectionStart?: number;
24
+ selectionEnd?: number;
25
+ endOffset?: number;
26
+ }
27
+ export interface SeparatorOptions {
28
+ decimalSeparator?: string;
29
+ thousandSeparator?: string;
30
+ }
31
+ export interface Separators {
32
+ decimalSeparator: string;
33
+ thousandSeparator?: string;
34
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Shared utility functions used across multiple features.
3
+ */
4
+ /**
5
+ * Escapes special regex characters in a string.
6
+ * This is used when building regex patterns from user-provided separator characters.
7
+ *
8
+ * @param str - The string to escape
9
+ * @returns The escaped string safe for use in regex patterns
10
+ *
11
+ * @example
12
+ * escapeRegExp(".") // Returns: "\\."
13
+ * escapeRegExp("$") // Returns: "\\$"
14
+ * escapeRegExp("1,234") // Returns: "1\\,234"
15
+ */
16
+ export declare function escapeRegExp(str: string): string;
@@ -0,0 +1,31 @@
1
+ import { type FormattingOptions, type CaretPositionInfo } from '@/types';
2
+ /**
3
+ * Handles the keydown event to prevent the user from entering a second decimal point.
4
+ * Also tracks selection info for Delete/Backspace keys to enable proper cursor positioning.
5
+ * In 'change' mode with formatting, skips cursor over thousand separators on delete/backspace.
6
+ *
7
+ * @param e - The keyboard event triggered by the input.
8
+ * @param formattingOptions - Optional formatting options for separator skipping
9
+ * @returns Caret position info if Delete/Backspace was pressed, undefined otherwise
10
+ */
11
+ export declare function handleOnKeyDownNumoraInput(e: KeyboardEvent, formattingOptions?: FormattingOptions): CaretPositionInfo | undefined;
12
+ /**
13
+ * Handles the input change event to ensure the value does not exceed the maximum number of decimal places,
14
+ * replaces commas with dots, and removes invalid non-numeric characters.
15
+ * Also handles cursor positioning for Delete/Backspace keys.
16
+ * Optionally formats with thousand separators in real-time if formatOn is 'change'.
17
+ *
18
+ * @param e - The event triggered by the input.
19
+ * @param decimalMaxLength - The maximum number of decimal places allowed.
20
+ * @param caretPositionBeforeChange - Optional caret position info from keydown handler
21
+ * @param formattingOptions - Optional formatting options for real-time formatting
22
+ * @returns Object with formatted value and raw value
23
+ */
24
+ export declare function handleOnChangeNumoraInput(e: Event, decimalMaxLength: number, caretPositionBeforeChange?: CaretPositionInfo, formattingOptions?: FormattingOptions): {
25
+ formatted: string;
26
+ raw: string;
27
+ };
28
+ export declare function handleOnPasteNumoraInput(e: ClipboardEvent, decimalMaxLength: number, formattingOptions?: FormattingOptions): {
29
+ formatted: string;
30
+ raw: string;
31
+ };
@@ -0,0 +1,28 @@
1
+ import { type FormattingOptions } from '@/types';
2
+ /**
3
+ * Formats a value from user input events (onChange, onBlur) by sanitizing, trimming decimals, and applying formatting.
4
+ * The behavior adapts based on formatOn mode - removes separators in 'change' mode since they'll be re-added.
5
+ *
6
+ * @param rawValue - The raw input value from the user event
7
+ * @param decimalMaxLength - Maximum number of decimal places allowed
8
+ * @param formattingOptions - Optional formatting options
9
+ * @param shouldRemoveThousandSeparators - Whether to remove thousand separators during sanitization (default: determined by formatOn)
10
+ * @returns Object with formatted value and raw value (raw value is the value before formatting)
11
+ */
12
+ export declare function formatInputValue(rawValue: string, decimalMaxLength: number, formattingOptions?: FormattingOptions, shouldRemoveThousandSeparators?: boolean): {
13
+ formatted: string;
14
+ raw: string;
15
+ };
16
+ /**
17
+ * Formats a value for display (e.g., initial values, controlled values).
18
+ * Assumes the value might already contain thousand separators, so removes them before processing.
19
+ *
20
+ * @param value - The value to format for display
21
+ * @param decimalMaxLength - Maximum number of decimal places allowed
22
+ * @param formattingOptions - Optional formatting options
23
+ * @returns Object with formatted value and raw value
24
+ */
25
+ export declare function formatValueForDisplay(value: string, decimalMaxLength: number, formattingOptions?: FormattingOptions): {
26
+ formatted: string;
27
+ raw: string;
28
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Builds an input pattern that allows optional negative sign and a single custom decimal separator.
3
+ * The separator is escaped so any character can be safely used.
4
+ */
5
+ export declare function getNumoraPattern(decimalSeparator: string, enableNegative: boolean): string;
@@ -0,0 +1,20 @@
1
+ import { FormatOn } from './types';
2
+ import { ThousandStyle } from './types';
3
+ export interface NumoraInputValidationOptions {
4
+ decimalMaxLength?: number;
5
+ decimalMinLength?: number;
6
+ formatOn?: FormatOn;
7
+ thousandSeparator?: string;
8
+ thousandStyle?: ThousandStyle;
9
+ decimalSeparator?: string;
10
+ enableCompactNotation?: boolean;
11
+ enableNegative?: boolean;
12
+ enableLeadingZeros?: boolean;
13
+ rawValueMode?: boolean;
14
+ onChange?: (value: string) => void;
15
+ }
16
+ /**
17
+ * Validates all NumoraInput constructor parameters.
18
+ * Throws descriptive errors for invalid values.
19
+ */
20
+ export declare function validateNumoraInputOptions(options: NumoraInputValidationOptions): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "numora",
3
- "version": "2.0.4",
3
+ "version": "3.0.0",
4
4
  "description": "Precision-first numeric input library for DeFi and financial applications",
5
5
  "homepage": "https://numora.xyz/",
6
6
  "main": "dist/index.js",
@@ -61,7 +61,7 @@
61
61
  "access": "public"
62
62
  },
63
63
  "scripts": {
64
- "build": "vite build && tsc --emitDeclarationOnly",
64
+ "build": "vite build & tsc --emitDeclarationOnly",
65
65
  "test": "vitest run",
66
66
  "dev": "vite build --watch"
67
67
  }