raqam 0.3.1 → 0.4.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 +25 -9
- package/dist/chunk-4GNLVHAM.js +2 -0
- package/dist/chunk-4GNLVHAM.js.map +1 -0
- package/dist/chunk-5LYK54TH.js +2 -0
- package/dist/chunk-5LYK54TH.js.map +1 -0
- package/dist/chunk-C5MK5U3F.js +2 -0
- package/dist/chunk-C5MK5U3F.js.map +1 -0
- package/dist/chunk-CAHEQQ5J.cjs +2 -0
- package/dist/chunk-CAHEQQ5J.cjs.map +1 -0
- package/dist/chunk-G7ACJUKH.js +2 -0
- package/dist/chunk-G7ACJUKH.js.map +1 -0
- package/dist/chunk-GAKIDRGS.cjs +2 -0
- package/dist/chunk-GAKIDRGS.cjs.map +1 -0
- package/dist/chunk-I3H3UMZD.cjs +2 -0
- package/dist/chunk-I3H3UMZD.cjs.map +1 -0
- package/dist/chunk-LD6OTXXT.js +2 -0
- package/dist/chunk-LD6OTXXT.js.map +1 -0
- package/dist/chunk-MNYIBO2M.cjs +2 -0
- package/dist/chunk-MNYIBO2M.cjs.map +1 -0
- package/dist/chunk-MOES3T6R.js +2 -0
- package/dist/chunk-MOES3T6R.js.map +1 -0
- package/dist/chunk-MUO4XNLX.cjs +2 -0
- package/dist/chunk-MUO4XNLX.cjs.map +1 -0
- package/dist/chunk-P6AWGQPY.js +2 -0
- package/dist/chunk-P6AWGQPY.js.map +1 -0
- package/dist/chunk-TFY7JMI6.js +2 -0
- package/dist/chunk-TFY7JMI6.js.map +1 -0
- package/dist/chunk-UYZYSVT5.cjs +2 -0
- package/dist/chunk-UYZYSVT5.cjs.map +1 -0
- package/dist/chunk-XJZHLJ2C.cjs +2 -0
- package/dist/chunk-XJZHLJ2C.cjs.map +1 -0
- package/dist/chunk-YUKLLK4G.cjs +2 -0
- package/dist/chunk-YUKLLK4G.cjs.map +1 -0
- package/dist/chunk-ZKLZ7UKZ.cjs +2 -0
- package/dist/chunk-ZKLZ7UKZ.cjs.map +1 -0
- package/dist/chunk-ZWDI6EPF.js +2 -0
- package/dist/chunk-ZWDI6EPF.js.map +1 -0
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +68 -295
- package/dist/core.d.ts +68 -295
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -133
- package/dist/index.d.ts +12 -133
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/locales/ar.cjs +1 -35
- package/dist/locales/ar.cjs.map +1 -1
- package/dist/locales/ar.js +1 -3
- package/dist/locales/bn.cjs +1 -35
- package/dist/locales/bn.cjs.map +1 -1
- package/dist/locales/bn.js +1 -3
- package/dist/locales/fa.cjs +1 -37
- package/dist/locales/fa.cjs.map +1 -1
- package/dist/locales/fa.js +1 -3
- package/dist/locales/hi.cjs +1 -35
- package/dist/locales/hi.cjs.map +1 -1
- package/dist/locales/hi.js +1 -3
- package/dist/locales/index.cjs +1 -77
- package/dist/locales/index.cjs.map +1 -1
- package/dist/locales/index.js +1 -7
- package/dist/locales/th.cjs +1 -35
- package/dist/locales/th.cjs.map +1 -1
- package/dist/locales/th.js +1 -3
- package/dist/react.cjs +1 -1
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +117 -3
- package/dist/react.d.ts +117 -3
- package/dist/react.js +1 -1
- package/dist/react.js.map +1 -1
- package/dist/{index-BMFJwudG.d.cts → types-B2ZqkJI-.d.cts} +34 -107
- package/dist/{index-BMFJwudG.d.ts → types-B2ZqkJI-.d.ts} +34 -107
- package/package.json +28 -6
- package/dist/chunk-4AMLNJEK.js +0 -14
- package/dist/chunk-4AMLNJEK.js.map +0 -1
- package/dist/chunk-7IEJOMYT.js +0 -14
- package/dist/chunk-7IEJOMYT.js.map +0 -1
- package/dist/chunk-HPUEM7JB.js +0 -14
- package/dist/chunk-HPUEM7JB.js.map +0 -1
- package/dist/chunk-OLLREWX6.js +0 -16
- package/dist/chunk-OLLREWX6.js.map +0 -1
- package/dist/chunk-RP3DVBGJ.js +0 -14
- package/dist/chunk-RP3DVBGJ.js.map +0 -1
- package/dist/chunk-TISOJTKH.js +0 -25
- package/dist/chunk-TISOJTKH.js.map +0 -1
package/dist/core.d.cts
CHANGED
|
@@ -1,297 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
decimalSeparator: string;
|
|
4
|
-
/** Grouping (thousands) separator (e.g. "," en-US, "." de-DE, "٬" fa-IR) */
|
|
5
|
-
groupingSeparator: string;
|
|
6
|
-
/** Minus sign character (usually "-" but can differ) */
|
|
7
|
-
minusSign: string;
|
|
8
|
-
/** Locale's representation of "0" (e.g. "0" for Latin, "۰" for Persian) */
|
|
9
|
-
zero: string;
|
|
10
|
-
/** Whether this is an RTL locale */
|
|
11
|
-
isRTL: boolean;
|
|
12
|
-
}
|
|
13
|
-
interface FormatResult {
|
|
14
|
-
formatted: string;
|
|
15
|
-
parts: Intl.NumberFormatPart[];
|
|
16
|
-
}
|
|
17
|
-
interface ParseResult {
|
|
18
|
-
/** The parsed number, or null if empty / un-parseable */
|
|
19
|
-
value: number | null;
|
|
20
|
-
/** True for valid numbers */
|
|
21
|
-
isValid: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* True for valid-but-incomplete input that must not be reformatted yet:
|
|
24
|
-
* "-", "1.", "1.0", "1.00", etc.
|
|
25
|
-
*/
|
|
26
|
-
isIntermediate: boolean;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* boolean[] of length formattedValue.length + 1.
|
|
30
|
-
* true → cursor may rest at this index
|
|
31
|
-
* false → cursor must not rest here (e.g. inside a thousands separator)
|
|
32
|
-
*/
|
|
33
|
-
type CaretBoundary = boolean[];
|
|
34
|
-
/** Unicode codepoint range [start, end] inclusive representing a digit block */
|
|
35
|
-
type DigitBlock = readonly [number, number];
|
|
36
|
-
interface UseNumberFieldStateOptions {
|
|
37
|
-
/** Controlled numeric value */
|
|
38
|
-
value?: number | null;
|
|
39
|
-
/** Uncontrolled default value */
|
|
40
|
-
defaultValue?: number | null;
|
|
41
|
-
/** Fires on every meaningful value change */
|
|
42
|
-
onChange?: (value: number | null) => void;
|
|
43
|
-
/** BCP 47 locale tag (default: browser locale) */
|
|
44
|
-
locale?: string;
|
|
45
|
-
/** Full Intl.NumberFormatOptions — currency, percent, decimal, etc. */
|
|
46
|
-
formatOptions?: Intl.NumberFormatOptions;
|
|
47
|
-
/** Minimum allowed value */
|
|
48
|
-
minValue?: number;
|
|
49
|
-
/** Maximum allowed value */
|
|
50
|
-
maxValue?: number;
|
|
51
|
-
/** Step amount for increment/decrement (default: 1) */
|
|
52
|
-
step?: number;
|
|
53
|
-
/** Large step — Shift+Arrow / PageUp/Down (default: step * 10) */
|
|
54
|
-
largeStep?: number;
|
|
55
|
-
/** Small step — Meta/Ctrl+Arrow (default: step * 0.1) */
|
|
56
|
-
smallStep?: number;
|
|
57
|
-
/** Allow negative values (default: true) */
|
|
58
|
-
allowNegative?: boolean;
|
|
59
|
-
/** Allow decimal values (default: true) */
|
|
60
|
-
allowDecimal?: boolean;
|
|
61
|
-
/** Override maximumFractionDigits from formatOptions */
|
|
62
|
-
maximumFractionDigits?: number;
|
|
63
|
-
/** Override minimumFractionDigits from formatOptions */
|
|
64
|
-
minimumFractionDigits?: number;
|
|
65
|
-
/** Always show exactly maximumFractionDigits decimal places */
|
|
66
|
-
fixedDecimalScale?: boolean;
|
|
67
|
-
/** When clamping happens (default: "blur") */
|
|
68
|
-
clampBehavior?: "blur" | "strict" | "none";
|
|
69
|
-
/** Apply live formatting while typing (default: true) */
|
|
70
|
-
liveFormat?: boolean;
|
|
71
|
-
/** Arbitrary prefix string (e.g. "$") */
|
|
72
|
-
prefix?: string;
|
|
73
|
-
/** Arbitrary suffix string (e.g. " تومان") */
|
|
74
|
-
suffix?: string;
|
|
75
|
-
/** Disable the field */
|
|
76
|
-
disabled?: boolean;
|
|
77
|
-
/** Make the field read-only */
|
|
78
|
-
readOnly?: boolean;
|
|
79
|
-
/** Mark the field as required */
|
|
80
|
-
required?: boolean;
|
|
81
|
-
/**
|
|
82
|
-
* Allow values outside min/max to be typed and committed without clamping.
|
|
83
|
-
* Useful when server-side validation handles clamping.
|
|
84
|
-
* When true, aria-invalid is set when value is out of range.
|
|
85
|
-
* default: false
|
|
86
|
-
*/
|
|
87
|
-
allowOutOfRange?: boolean;
|
|
88
|
-
/**
|
|
89
|
-
* Custom validation function. Called on every value change.
|
|
90
|
-
* - Return `true` or `null`/`undefined` → valid
|
|
91
|
-
* - Return `false` → invalid (aria-invalid set, no error message)
|
|
92
|
-
* - Return a `string` → invalid with that string as the error message
|
|
93
|
-
*/
|
|
94
|
-
validate?: (value: number | null) => boolean | string | null | undefined;
|
|
95
|
-
/**
|
|
96
|
-
* Fires with the raw unformatted string the user typed, preserving full
|
|
97
|
-
* decimal precision before JS float conversion. Useful for financial apps
|
|
98
|
-
* that need arbitrary-precision string arithmetic.
|
|
99
|
-
* Fires alongside `onChange`.
|
|
100
|
-
*/
|
|
101
|
-
onRawChange?: (rawValue: string | null) => void;
|
|
102
|
-
/**
|
|
103
|
-
* Custom format function. When provided, replaces the built-in Intl.NumberFormat
|
|
104
|
-
* formatter for display purposes. Also used for initial display value.
|
|
105
|
-
*/
|
|
106
|
-
formatValue?: (value: number) => string;
|
|
107
|
-
/**
|
|
108
|
-
* Custom parse function. When provided, replaces the built-in locale-aware parser.
|
|
109
|
-
* Must return `{ value: number | null, isIntermediate: boolean }`.
|
|
110
|
-
*/
|
|
111
|
-
parseValue?: (input: string) => {
|
|
112
|
-
value: number | null;
|
|
113
|
-
isIntermediate: boolean;
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
interface NumberFieldState {
|
|
117
|
-
/** The display string shown in the input */
|
|
118
|
-
inputValue: string;
|
|
119
|
-
/** The parsed numeric value (null for empty/invalid) */
|
|
120
|
-
numberValue: number | null;
|
|
121
|
-
/**
|
|
122
|
-
* The raw string value exactly as the user typed it (before formatting).
|
|
123
|
-
* Preserves full decimal precision — useful for financial arbitrary-precision math.
|
|
124
|
-
*/
|
|
125
|
-
rawValue: string | null;
|
|
126
|
-
/** Whether increment is currently possible */
|
|
127
|
-
canIncrement: boolean;
|
|
128
|
-
/** Whether decrement is currently possible */
|
|
129
|
-
canDecrement: boolean;
|
|
130
|
-
/** Whether the ScrubArea is currently being dragged */
|
|
131
|
-
isScrubbing: boolean;
|
|
132
|
-
/** Update the isScrubbing state (called by useScrubArea) */
|
|
133
|
-
setIsScrubbing: (val: boolean) => void;
|
|
134
|
-
/** Whether the input is currently focused */
|
|
135
|
-
isFocused: boolean;
|
|
136
|
-
/** Update the isFocused state (called by useNumberField) */
|
|
137
|
-
setIsFocused: (val: boolean) => void;
|
|
138
|
-
/** Current validation state — 'valid' if no validate prop, or based on validate result */
|
|
139
|
-
validationState: "valid" | "invalid";
|
|
140
|
-
/** Error message from validate() if it returned a string, otherwise null */
|
|
141
|
-
validationError: string | null;
|
|
142
|
-
/** Internal: set the reason for the next onChange call (used by useNumberField) */
|
|
143
|
-
_setLastChangeReason: (reason: ChangeReason) => void;
|
|
144
|
-
/** Internal: read the current change reason (used by NumberField.Root) */
|
|
145
|
-
_getLastChangeReason: () => ChangeReason;
|
|
146
|
-
/**
|
|
147
|
-
* Update display string (triggers parse + onChange). `knownValue` overrides
|
|
148
|
-
* the parsed value when `val` is a formatted string that cannot be reversed
|
|
149
|
-
* (compact "2.5K", scientific, unit notation).
|
|
150
|
-
*/
|
|
151
|
-
setInputValue: (val: string, knownValue?: number | null) => void;
|
|
152
|
-
/** Directly set the numeric value (triggers format + onChange) */
|
|
153
|
-
setNumberValue: (val: number | null) => void;
|
|
154
|
-
/** Format + clamp on blur — call from onBlur. Returns the committed numeric value. */
|
|
155
|
-
commit: () => number | null;
|
|
156
|
-
/** Increment by step */
|
|
157
|
-
increment: (amount?: number) => void;
|
|
158
|
-
/** Decrement by step */
|
|
159
|
-
decrement: (amount?: number) => void;
|
|
160
|
-
/** Jump to maxValue */
|
|
161
|
-
incrementToMax: () => void;
|
|
162
|
-
/** Jump to minValue */
|
|
163
|
-
decrementToMin: () => void;
|
|
164
|
-
/** Raw options (for hooks that need them) */
|
|
165
|
-
options: UseNumberFieldStateOptions;
|
|
166
|
-
}
|
|
167
|
-
/** Reason for a value change — propagated through onValueChange details */
|
|
168
|
-
type ChangeReason = "input" | "clear" | "blur" | "paste" | "keyboard" | "increment" | "decrement" | "wheel" | "scrub";
|
|
169
|
-
interface UseNumberFieldProps extends UseNumberFieldStateOptions {
|
|
170
|
-
/** Visible label text (used for aria-label fallback) */
|
|
171
|
-
label?: string;
|
|
172
|
-
"aria-label"?: string;
|
|
173
|
-
"aria-describedby"?: string;
|
|
174
|
-
"aria-labelledby"?: string;
|
|
175
|
-
/** Form field name — renders a hidden input */
|
|
176
|
-
name?: string;
|
|
177
|
-
/** id for the input element */
|
|
178
|
-
id?: string;
|
|
179
|
-
/** Enable mouse-wheel increment/decrement */
|
|
180
|
-
allowMouseWheel?: boolean;
|
|
181
|
-
/**
|
|
182
|
-
* Controls what is placed in the clipboard on copy/cut.
|
|
183
|
-
* - 'formatted' (default): browser-native copy of display string
|
|
184
|
-
* - 'raw': numberValue as a plain JS number string (e.g. "1234.56")
|
|
185
|
-
* - 'number': alias for 'raw'
|
|
186
|
-
*/
|
|
187
|
-
copyBehavior?: "formatted" | "raw" | "number";
|
|
188
|
-
/** Milliseconds before press-and-hold repeat starts (default: 400) */
|
|
189
|
-
stepHoldDelay?: number;
|
|
190
|
-
/** Initial milliseconds between repeats during press-and-hold (default: 200) */
|
|
191
|
-
stepHoldInterval?: number;
|
|
192
|
-
onFocus?: (e: React.FocusEvent<HTMLInputElement>) => void;
|
|
193
|
-
onBlur?: (e: React.FocusEvent<HTMLInputElement>) => void;
|
|
194
|
-
/**
|
|
195
|
-
* Fires only when the value is committed — i.e. on blur, or when the user
|
|
196
|
-
* presses Enter — after formatting and clamping have been applied.
|
|
197
|
-
* `reason` is `"blur"` for focus loss and `"keyboard"` for Enter.
|
|
198
|
-
* Reach for this (instead of `onChange`) when you only care about the final,
|
|
199
|
-
* settled value: persisting it, validating server-side, firing a request, etc.
|
|
200
|
-
*/
|
|
201
|
-
onValueCommitted?: (value: number | null, details: {
|
|
202
|
-
reason: "blur" | "keyboard";
|
|
203
|
-
}) => void;
|
|
204
|
-
}
|
|
205
|
-
interface NumberFieldAria {
|
|
206
|
-
/**
|
|
207
|
-
* Props for the label element. Includes a `ref` callback that registers the
|
|
208
|
-
* label's presence with the hook — spread it onto whatever element you render
|
|
209
|
-
* as the label (built-in `<NumberField.Label>` or a custom primitive) so the
|
|
210
|
-
* input/group keep their `aria-labelledby` wiring and avoid dangling refs.
|
|
211
|
-
*/
|
|
212
|
-
labelProps: React.LabelHTMLAttributes<HTMLLabelElement> & {
|
|
213
|
-
ref?: React.RefCallback<HTMLElement>;
|
|
214
|
-
};
|
|
215
|
-
groupProps: React.HTMLAttributes<HTMLDivElement>;
|
|
216
|
-
inputProps: React.InputHTMLAttributes<HTMLInputElement>;
|
|
217
|
-
hiddenInputProps: React.InputHTMLAttributes<HTMLInputElement> | null;
|
|
218
|
-
incrementButtonProps: React.ButtonHTMLAttributes<HTMLButtonElement>;
|
|
219
|
-
decrementButtonProps: React.ButtonHTMLAttributes<HTMLButtonElement>;
|
|
220
|
-
descriptionProps: React.HTMLAttributes<HTMLElement>;
|
|
221
|
-
errorMessageProps: React.HTMLAttributes<HTMLElement>;
|
|
222
|
-
}
|
|
223
|
-
type StateRenderFn = (props: Record<string, unknown>, state: NumberFieldState) => React.ReactElement;
|
|
224
|
-
type RenderProp = React.ReactElement | StateRenderFn;
|
|
225
|
-
interface NumberFieldRootProps extends UseNumberFieldProps {
|
|
226
|
-
children?: React.ReactNode;
|
|
227
|
-
/** CSS class for the root wrapper div */
|
|
228
|
-
className?: string;
|
|
229
|
-
/** Inline style for the root wrapper div */
|
|
230
|
-
style?: React.CSSProperties;
|
|
231
|
-
/** Fires on every meaningful value change */
|
|
232
|
-
onValueChange?: (value: number | null, details: {
|
|
233
|
-
reason: ChangeReason;
|
|
234
|
-
formattedValue: string;
|
|
235
|
-
event?: React.SyntheticEvent;
|
|
236
|
-
}) => void;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Format presets — named Intl.NumberFormatOptions configurations for common
|
|
241
|
-
* number input patterns. Use these as the `formatOptions` prop value.
|
|
242
|
-
*
|
|
243
|
-
* @example
|
|
244
|
-
* import { presets } from 'raqam'
|
|
245
|
-
* <NumberField.Root formatOptions={presets.currency('USD')} />
|
|
246
|
-
* <NumberField.Root formatOptions={presets.percent} />
|
|
247
|
-
* <NumberField.Root formatOptions={presets.compact} />
|
|
248
|
-
*/
|
|
249
|
-
declare const presets: {
|
|
250
|
-
/** Currency with standard sign display. Shorthand for `{ style:'currency', currency:code }`. */
|
|
251
|
-
readonly currency: (code: string) => Intl.NumberFormatOptions;
|
|
252
|
-
/**
|
|
253
|
-
* Accounting currency — negatives shown as `(1,234.56)` instead of `-$1,234.56`.
|
|
254
|
-
* Requires the accounting format parser fix (built-in to raqam).
|
|
255
|
-
*/
|
|
256
|
-
readonly accounting: (code: string) => Intl.NumberFormatOptions;
|
|
257
|
-
/** Percentage — formats 0.42 as "42%" */
|
|
258
|
-
readonly percent: Intl.NumberFormatOptions;
|
|
259
|
-
/** Compact short — "1.2K", "3.4M" */
|
|
260
|
-
readonly compact: Intl.NumberFormatOptions;
|
|
261
|
-
/** Compact long — "1.2 thousand", "3.4 million" */
|
|
262
|
-
readonly compactLong: Intl.NumberFormatOptions;
|
|
263
|
-
/** Scientific notation — "1.234E3" */
|
|
264
|
-
readonly scientific: Intl.NumberFormatOptions;
|
|
265
|
-
/** Engineering notation — exponents always multiples of 3 */
|
|
266
|
-
readonly engineering: Intl.NumberFormatOptions;
|
|
267
|
-
/** Integer — no decimal places */
|
|
268
|
-
readonly integer: Intl.NumberFormatOptions;
|
|
269
|
-
/**
|
|
270
|
-
* Financial — always exactly 2 decimal places (fixed scale).
|
|
271
|
-
* Combine with `fixedDecimalScale` prop for strict display.
|
|
272
|
-
*/
|
|
273
|
-
readonly financial: Intl.NumberFormatOptions;
|
|
274
|
-
/**
|
|
275
|
-
* Unit — shorthand for `{ style:'unit', unit:unitCode }`.
|
|
276
|
-
* @example presets.unit('kilometer-per-hour') → { style:'unit', unit:'kilometer-per-hour' }
|
|
277
|
-
*/
|
|
278
|
-
readonly unit: (unit: string) => Intl.NumberFormatOptions;
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
interface LocaleConfig {
|
|
282
|
-
/** Extra digit block ranges to register */
|
|
283
|
-
digitBlocks?: DigitBlock[];
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Register additional digit blocks (called by locale plugins as a side effect).
|
|
287
|
-
* Duplicate ranges are silently ignored.
|
|
288
|
-
*/
|
|
289
|
-
declare function registerLocale(config: LocaleConfig): void;
|
|
290
|
-
/**
|
|
291
|
-
* Normalise any Unicode decimal digit in `input` to its ASCII equivalent (0–9).
|
|
292
|
-
* Non-digit characters pass through unchanged.
|
|
293
|
-
*/
|
|
294
|
-
declare function normalizeDigits(input: string): string;
|
|
1
|
+
import { L as LocaleInfo, F as FormatResult, P as ParseResult, D as DigitBlock, C as CaretBoundary } from './types-B2ZqkJI-.cjs';
|
|
2
|
+
export { a as ChangeReason, b as NumberFieldAria, c as NumberFieldRootProps, N as NumberFieldState, R as RenderProp, f as StateRenderFn, U as UseNumberFieldProps, g as UseNumberFieldStateOptions } from './types-B2ZqkJI-.cjs';
|
|
295
3
|
|
|
296
4
|
interface FormatterOptions {
|
|
297
5
|
locale?: string;
|
|
@@ -326,6 +34,14 @@ interface Parser {
|
|
|
326
34
|
parse(input: string): ParseResult;
|
|
327
35
|
isIntermediate(input: string): boolean;
|
|
328
36
|
getLocaleInfo(): LocaleInfo;
|
|
37
|
+
/**
|
|
38
|
+
* Strip formatting affordances (grouping separators, currency symbol, prefix/
|
|
39
|
+
* suffix, percent sign…) from `input`, returning the bare numeric string
|
|
40
|
+
* (ASCII digits, an optional leading "-", and at most one "."). Trailing zeros
|
|
41
|
+
* the user typed are preserved. Useful for deriving a precision-preserving raw
|
|
42
|
+
* value from a formatted display string.
|
|
43
|
+
*/
|
|
44
|
+
strip(input: string): string;
|
|
329
45
|
}
|
|
330
46
|
/**
|
|
331
47
|
* Create a locale-aware parser. Separator characters are extracted from
|
|
@@ -333,6 +49,21 @@ interface Parser {
|
|
|
333
49
|
*/
|
|
334
50
|
declare function createParser(opts?: ParserOptions): Parser;
|
|
335
51
|
|
|
52
|
+
interface LocaleConfig {
|
|
53
|
+
/** Extra digit block ranges to register */
|
|
54
|
+
digitBlocks?: DigitBlock[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Register additional digit blocks (called by locale plugins as a side effect).
|
|
58
|
+
* Duplicate ranges are silently ignored.
|
|
59
|
+
*/
|
|
60
|
+
declare function registerLocale(config: LocaleConfig): void;
|
|
61
|
+
/**
|
|
62
|
+
* Normalise any Unicode decimal digit in `input` to its ASCII equivalent (0–9).
|
|
63
|
+
* Non-digit characters pass through unchanged.
|
|
64
|
+
*/
|
|
65
|
+
declare function normalizeDigits(input: string): string;
|
|
66
|
+
|
|
336
67
|
/**
|
|
337
68
|
* Build a boolean array of length `formattedValue.length + 1`.
|
|
338
69
|
* `true` → cursor may rest at this position.
|
|
@@ -366,4 +97,46 @@ declare function getCaretBoundary(formattedValue: string, info: LocaleInfo): Car
|
|
|
366
97
|
*/
|
|
367
98
|
declare function computeNewCursorPosition(oldInput: string, oldCursor: number, newFormatted: string, info: LocaleInfo, inputType?: string): number;
|
|
368
99
|
|
|
369
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Format presets — named Intl.NumberFormatOptions configurations for common
|
|
102
|
+
* number input patterns. Use these as the `formatOptions` prop value.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* import { presets } from 'raqam'
|
|
106
|
+
* <NumberField.Root formatOptions={presets.currency('USD')} />
|
|
107
|
+
* <NumberField.Root formatOptions={presets.percent} />
|
|
108
|
+
* <NumberField.Root formatOptions={presets.compact} />
|
|
109
|
+
*/
|
|
110
|
+
declare const presets: {
|
|
111
|
+
/** Currency with standard sign display. Shorthand for `{ style:'currency', currency:code }`. */
|
|
112
|
+
readonly currency: (code: string) => Intl.NumberFormatOptions;
|
|
113
|
+
/**
|
|
114
|
+
* Accounting currency — negatives shown as `(1,234.56)` instead of `-$1,234.56`.
|
|
115
|
+
* Requires the accounting format parser fix (built-in to raqam).
|
|
116
|
+
*/
|
|
117
|
+
readonly accounting: (code: string) => Intl.NumberFormatOptions;
|
|
118
|
+
/** Percentage — formats 0.42 as "42%" */
|
|
119
|
+
readonly percent: Intl.NumberFormatOptions;
|
|
120
|
+
/** Compact short — "1.2K", "3.4M" */
|
|
121
|
+
readonly compact: Intl.NumberFormatOptions;
|
|
122
|
+
/** Compact long — "1.2 thousand", "3.4 million" */
|
|
123
|
+
readonly compactLong: Intl.NumberFormatOptions;
|
|
124
|
+
/** Scientific notation — "1.234E3" */
|
|
125
|
+
readonly scientific: Intl.NumberFormatOptions;
|
|
126
|
+
/** Engineering notation — exponents always multiples of 3 */
|
|
127
|
+
readonly engineering: Intl.NumberFormatOptions;
|
|
128
|
+
/** Integer — no decimal places */
|
|
129
|
+
readonly integer: Intl.NumberFormatOptions;
|
|
130
|
+
/**
|
|
131
|
+
* Financial — always exactly 2 decimal places (fixed scale).
|
|
132
|
+
* Combine with `fixedDecimalScale` prop for strict display.
|
|
133
|
+
*/
|
|
134
|
+
readonly financial: Intl.NumberFormatOptions;
|
|
135
|
+
/**
|
|
136
|
+
* Unit — shorthand for `{ style:'unit', unit:unitCode }`.
|
|
137
|
+
* @example presets.unit('kilometer-per-hour') → { style:'unit', unit:'kilometer-per-hour' }
|
|
138
|
+
*/
|
|
139
|
+
readonly unit: (unit: string) => Intl.NumberFormatOptions;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export { CaretBoundary, DigitBlock, FormatResult, type Formatter, type FormatterOptions, type LocaleConfig, LocaleInfo, ParseResult, type Parser, type ParserOptions, computeNewCursorPosition, createFormatter, createParser, getCaretBoundary, normalizeDigits, presets, registerLocale };
|