numora 1.0.4 → 2.0.1

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 (34) hide show
  1. package/README.md +233 -23
  2. package/dist/NumoraInput.d.ts +72 -0
  3. package/dist/config.d.ts +11 -0
  4. package/dist/features/compact-notation.d.ts +17 -0
  5. package/dist/features/decimals.d.ts +52 -0
  6. package/dist/features/formatting/caret-position-utils.d.ts +54 -0
  7. package/dist/features/formatting/change-detection.d.ts +40 -0
  8. package/dist/features/formatting/character-equivalence.d.ts +9 -0
  9. package/dist/features/formatting/constants.d.ts +29 -0
  10. package/dist/features/formatting/cursor-boundary.d.ts +39 -0
  11. package/dist/features/formatting/cursor-position.d.ts +50 -0
  12. package/dist/features/formatting/digit-counting.d.ts +61 -0
  13. package/dist/features/formatting/index.d.ts +19 -0
  14. package/dist/features/formatting/large-number.d.ts +39 -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 +41 -0
  22. package/dist/features/scientific-notation.d.ts +9 -0
  23. package/dist/index.d.ts +4 -4
  24. package/dist/index.js +1 -1
  25. package/dist/index.mjs +1136 -59
  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 +15 -14
  29. package/dist/utils/input-pattern.d.ts +5 -0
  30. package/dist/validation.d.ts +20 -0
  31. package/package.json +9 -9
  32. package/dist/NumericInput.d.ts +0 -21
  33. package/dist/utils/decimals.d.ts +0 -13
  34. package/dist/utils/sanitization.d.ts +0 -1
@@ -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;
@@ -1,23 +1,24 @@
1
- /**
2
- * Handles the input change event to ensure the value does not exceed the maximum number of decimal places,
3
- * replaces commas with dots, and removes invalid non-numeric characters.
4
- *
5
- * @param e - The event triggered by the input.
6
- * @param maxDecimals - The maximum number of decimal places allowed.
7
- */
8
- export declare function handleOnChangeNumericInput(e: Event, maxDecimals: number): void;
1
+ import { type FormattingOptions, type CaretPositionInfo } from '@/types';
9
2
  /**
10
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.
11
6
  *
12
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
13
10
  */
14
- export declare function handleOnKeyDownNumericInput(e: KeyboardEvent): void;
11
+ export declare function handleOnKeyDownNumoraInput(e: KeyboardEvent, formattingOptions?: FormattingOptions): CaretPositionInfo | undefined;
15
12
  /**
16
- * Handles the paste event to ensure the value does not exceed the maximum number of decimal places,
13
+ * Handles the input change event to ensure the value does not exceed the maximum number of decimal places,
17
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'.
18
17
  *
19
- * @param e - The clipboard event triggered by the input.
20
- * @param maxDecimals - The maximum number of decimal places allowed.
21
- * @returns The sanitized value after the paste event.
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
22
  */
23
- export declare function handleOnPasteNumericInput(e: ClipboardEvent, maxDecimals: number): string;
23
+ export declare function handleOnChangeNumoraInput(e: Event, decimalMaxLength: number, caretPositionBeforeChange?: CaretPositionInfo, formattingOptions?: FormattingOptions): void;
24
+ export declare function handleOnPasteNumoraInput(e: ClipboardEvent, decimalMaxLength: number, formattingOptions?: FormattingOptions): string;
@@ -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,8 +1,8 @@
1
1
  {
2
2
  "name": "numora",
3
- "version": "1.0.4",
4
- "description": "Framework-agnostic headless finance input library",
5
- "homepage": "https://numora.netlify.app/",
3
+ "version": "2.0.1",
4
+ "description": "Precision-first numeric input library for DeFi and financial applications",
5
+ "homepage": "https://numora.xyz/",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "files": [
@@ -19,11 +19,6 @@
19
19
  "type": "git",
20
20
  "url": "https://github.com/Sharqiewicz/numora"
21
21
  },
22
- "scripts": {
23
- "build": "vite build && tsc --emitDeclarationOnly",
24
- "test": "vitest run",
25
- "dev": "vite build --watch"
26
- },
27
22
  "keywords": [
28
23
  "numeric input",
29
24
  "currency input",
@@ -61,5 +56,10 @@
61
56
  "typescript": "^5.8.2",
62
57
  "vite": "^6.2.2",
63
58
  "vitest": "^3.0.9"
59
+ },
60
+ "scripts": {
61
+ "build": "vite build && tsc --emitDeclarationOnly",
62
+ "test": "vitest run",
63
+ "dev": "vite build --watch"
64
64
  }
65
- }
65
+ }
@@ -1,21 +0,0 @@
1
- interface NumericInputOptions extends Partial<HTMLInputElement> {
2
- maxDecimals?: number;
3
- onChange?: (value: string) => void;
4
- }
5
- export declare class NumericInput {
6
- private element;
7
- private options;
8
- constructor(container: HTMLElement, { maxDecimals, onChange, ...rest }: NumericInputOptions);
9
- private createInputElement;
10
- private setupEventListeners;
11
- private handleChange;
12
- private handleKeyDown;
13
- private handlePaste;
14
- getValue(): string;
15
- setValue(value: string): void;
16
- disable(): void;
17
- enable(): void;
18
- addEventListener(event: string, callback: EventListenerOrEventListenerObject): void;
19
- removeEventListener(event: string, callback: EventListenerOrEventListenerObject): void;
20
- }
21
- export {};
@@ -1,13 +0,0 @@
1
- export declare const replaceCommasWithDots: (value: string) => string;
2
- /**
3
- * Checks if the input already has a decimal point and prevents the user from entering another one.
4
- */
5
- export declare const alreadyHasDecimal: (e: KeyboardEvent) => boolean;
6
- /**
7
- * Trims a string representation of a number to a maximum number of decimal places.
8
- *
9
- * @param value - The string to trim.
10
- * @param maxDecimals - The maximum number of decimal places to allow.
11
- * @returns The trimmed string.
12
- */
13
- export declare const trimToMaxDecimals: (value: string, maxDecimals: number) => string;
@@ -1 +0,0 @@
1
- export declare const sanitizeNumericInput: (value: string) => string;