use-mask-input 3.3.4 → 3.3.5
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/CHANGELOG.md +7 -0
- package/dist/index.d.ts +575 -2
- package/package.json +6 -6
- package/src/inputmask.types.ts +607 -0
- package/src/types.ts +2 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [3.3.5](https://github.com/eduardoborges/use-mask-input/compare/3.3.4...3.3.5) (2023-08-30)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **types:** fix mask options with any type ([7b643b1](https://github.com/eduardoborges/use-mask-input/commit/7b643b1e6afc27ad4e49d5b528e31d1ff6427a8b))
|
|
7
|
+
|
|
1
8
|
## [3.3.4](https://github.com/eduardoborges/use-mask-input/compare/3.3.3...3.3.4) (2023-08-29)
|
|
2
9
|
|
|
3
10
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,584 @@
|
|
|
1
|
-
import Inputmask from 'inputmask';
|
|
2
1
|
import * as react_hook_form from 'react-hook-form';
|
|
3
2
|
import { UseFormRegisterReturn, FieldValues, RegisterOptions, UseFormRegister, Path } from 'react-hook-form';
|
|
4
3
|
import * as react from 'react';
|
|
5
4
|
import { RefCallback } from 'react';
|
|
6
5
|
|
|
6
|
+
type Range = {
|
|
7
|
+
start: string;
|
|
8
|
+
end: string;
|
|
9
|
+
} | [string, string];
|
|
10
|
+
type PositionCaretOnClick = 'none' | 'lvp' | 'radixFocus' | 'select' | 'ignore';
|
|
11
|
+
type InputMode = 'verbatim' | 'none' | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url';
|
|
12
|
+
type Casing = 'upper' | 'lower' | 'title';
|
|
13
|
+
type DefinitionValidator = (chrs: string, maskset: any, pos: number, strict: boolean, opts: Options$1) => boolean | CommandObject;
|
|
14
|
+
interface Options$1 {
|
|
15
|
+
/**
|
|
16
|
+
* Change the mask placeholder. Instead of "_", you can change the unfilled characters mask as you like, simply
|
|
17
|
+
* by adding the placeholder option. For example, placeholder: " " will change the default autofill with empty
|
|
18
|
+
* values.
|
|
19
|
+
*
|
|
20
|
+
* @default "_"
|
|
21
|
+
*/
|
|
22
|
+
placeholder?: string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Definition of the symbols used to indicate an optional part in the mask.
|
|
25
|
+
*
|
|
26
|
+
* @default { start: "[", end: "]" }
|
|
27
|
+
*/
|
|
28
|
+
optionalmarker?: Range | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Definition of the symbols used to indicate a quantifier in the mask.
|
|
31
|
+
*
|
|
32
|
+
* @default { start: "{", end: "}" }
|
|
33
|
+
*/
|
|
34
|
+
quantifiermarker?: Range | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Definition of the symbols used to indicate a group in the mask.
|
|
37
|
+
*
|
|
38
|
+
* @default { start: "(", end: ")" }
|
|
39
|
+
*/
|
|
40
|
+
groupmarker?: Range | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Definition of the symbols used to indicate an alternator part in the mask.
|
|
43
|
+
*
|
|
44
|
+
* @default "|"
|
|
45
|
+
*/
|
|
46
|
+
alternatormarker?: string | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Definition of the symbols used to escape a part in the mask.
|
|
49
|
+
*
|
|
50
|
+
* @default "\\"
|
|
51
|
+
*/
|
|
52
|
+
escapeChar?: string | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* The mask to use.
|
|
55
|
+
*/
|
|
56
|
+
mask?: string | string[] | ((opts: Options$1) => string | string[]) | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Use a regular expression as a mask. When using shorthands be aware that you need to double escape or use
|
|
59
|
+
* String.raw with a string literal.
|
|
60
|
+
*/
|
|
61
|
+
regex?: string | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Execute a function when the mask is completed.
|
|
64
|
+
*/
|
|
65
|
+
oncomplete?: (() => void) | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Execute a function when the mask is cleared.
|
|
68
|
+
*/
|
|
69
|
+
onincomplete?: (() => void) | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Execute a function when the mask is cleared.
|
|
72
|
+
*/
|
|
73
|
+
oncleared?: (() => void) | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Mask repeat function. Repeat the mask definition x-times.
|
|
76
|
+
* `*` ~ forever, otherwise specify an integer
|
|
77
|
+
*
|
|
78
|
+
* @default 0
|
|
79
|
+
*/
|
|
80
|
+
repeat?: number | string | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Toggle to allocate as much possible or the opposite. Non-greedy repeat function. With the non-greedy option
|
|
83
|
+
* set to `false`, you can specify `*` as repeat. This makes an endless repeat.
|
|
84
|
+
*
|
|
85
|
+
* @default false
|
|
86
|
+
*/
|
|
87
|
+
greedy?: boolean | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Automatically unmask the value when retrieved.
|
|
90
|
+
*
|
|
91
|
+
* When setting this option to true the plugin also expects the initial value from the server to be unmasked.
|
|
92
|
+
*
|
|
93
|
+
* @default false
|
|
94
|
+
*/
|
|
95
|
+
autoUnmask?: boolean | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* Remove the mask before submitting the form.
|
|
98
|
+
*
|
|
99
|
+
* @default false
|
|
100
|
+
*/
|
|
101
|
+
removeMaskOnSubmit?: boolean | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Remove the empty mask on blur or when not empty remove the optional trailing part.
|
|
104
|
+
*
|
|
105
|
+
* @default true
|
|
106
|
+
*/
|
|
107
|
+
clearMaskOnLostFocus?: boolean | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* Toggle to insert or overwrite input. This option can be altered by pressing the Insert key.
|
|
110
|
+
*
|
|
111
|
+
* @default true
|
|
112
|
+
*/
|
|
113
|
+
insertMode?: boolean | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Show selected caret when `insertMode = false`.
|
|
116
|
+
*
|
|
117
|
+
* @default true
|
|
118
|
+
*/
|
|
119
|
+
insertModeVisual?: boolean | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* Clear the incomplete input on blur.
|
|
122
|
+
*
|
|
123
|
+
* @default false
|
|
124
|
+
*/
|
|
125
|
+
clearIncomplete?: boolean | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* The alias to use.
|
|
128
|
+
*
|
|
129
|
+
* @default null
|
|
130
|
+
*/
|
|
131
|
+
alias?: string | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* Callback to implement autocomplete on certain keys for example.
|
|
134
|
+
*/
|
|
135
|
+
onKeyDown?: ((event: KeyboardEvent, buffer: string[], caretPos: {
|
|
136
|
+
begin: number;
|
|
137
|
+
end: number;
|
|
138
|
+
}, opts: Options$1) => void) | undefined;
|
|
139
|
+
/**
|
|
140
|
+
* Executes before masking the initial value to allow preprocessing of the initial value.
|
|
141
|
+
*/
|
|
142
|
+
onBeforeMask?: ((initialValue: string, opts: Options$1) => string) | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* This callback allows for preprocessing the pasted value before actually handling the value for masking.
|
|
145
|
+
* This can be useful for stripping away some characters before processing. You can also disable pasting
|
|
146
|
+
* a value by returning false in the `onBeforePaste` call.
|
|
147
|
+
*/
|
|
148
|
+
onBeforePaste?: ((pastedValue: string, opts: Options$1) => string) | undefined;
|
|
149
|
+
/**
|
|
150
|
+
* Executes before writing to the masked element. Use this to do some extra processing of the input. This can
|
|
151
|
+
* be useful when implementing an alias, ex. decimal alias, autofill the digits when leaving the inputfield.
|
|
152
|
+
*/
|
|
153
|
+
onBeforeWrite?: ((event: KeyboardEvent, buffer: string[], caretPos: number, opts: Options$1) => CommandObject) | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* Executes after unmasking to allow post-processing of the unmaskedvalue.
|
|
156
|
+
*
|
|
157
|
+
* @returns New unmasked value
|
|
158
|
+
*/
|
|
159
|
+
onUnMask?: ((maskedValue: string, unmaskedValue: string) => string) | undefined;
|
|
160
|
+
/**
|
|
161
|
+
* Shows the mask when the input gets focus.
|
|
162
|
+
*
|
|
163
|
+
* @default true
|
|
164
|
+
*/
|
|
165
|
+
showMaskOnFocus?: boolean | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* Shows the mask when the input is hevered by the mouse cursor.
|
|
168
|
+
*
|
|
169
|
+
* @default true
|
|
170
|
+
*/
|
|
171
|
+
showMaskOnHover?: boolean | undefined;
|
|
172
|
+
/**
|
|
173
|
+
* Callback function is executed on every keyvalidation with the key, result as the parameter.
|
|
174
|
+
*/
|
|
175
|
+
onKeyValidation?: ((key: number, result: boolean) => void) | undefined;
|
|
176
|
+
/**
|
|
177
|
+
* A character which can be used to skip an optional part of a mask.
|
|
178
|
+
*
|
|
179
|
+
* @default " "
|
|
180
|
+
*/
|
|
181
|
+
skipOptionalPartCharacter?: string | undefined;
|
|
182
|
+
/**
|
|
183
|
+
* Numeric input direction. Keeps the caret at the end.
|
|
184
|
+
*
|
|
185
|
+
* @default false
|
|
186
|
+
*/
|
|
187
|
+
numericInput?: boolean | undefined;
|
|
188
|
+
/**
|
|
189
|
+
* Align the input to the right
|
|
190
|
+
*
|
|
191
|
+
* By setting the rightAlign you can specify to right-align an inputmask. This is only applied in combination of
|
|
192
|
+
* the `numericInput` option or the `dir-attribute`.
|
|
193
|
+
*
|
|
194
|
+
* @default true
|
|
195
|
+
*/
|
|
196
|
+
rightAlign?: boolean | undefined;
|
|
197
|
+
/**
|
|
198
|
+
* Make escape behave like undo. (ctrl-Z) Pressing escape reverts the value to the value before focus.
|
|
199
|
+
*
|
|
200
|
+
* @default true
|
|
201
|
+
*/
|
|
202
|
+
undoOnEscape?: boolean | undefined;
|
|
203
|
+
/**
|
|
204
|
+
* Define the radixpoint (decimal separator)
|
|
205
|
+
*
|
|
206
|
+
* @default ""
|
|
207
|
+
*/
|
|
208
|
+
radixPoint?: string | undefined;
|
|
209
|
+
/**
|
|
210
|
+
* Define the groupseparator.
|
|
211
|
+
*
|
|
212
|
+
* @default ""
|
|
213
|
+
*/
|
|
214
|
+
groupSeparator?: string | undefined;
|
|
215
|
+
/**
|
|
216
|
+
* Use in combination with the alternator syntax Try to keep the mask static while typing. Decisions to alter the
|
|
217
|
+
* mask will be postponed if possible.
|
|
218
|
+
*
|
|
219
|
+
* ex. $(selector).inputmask({ mask: ["+55-99-9999-9999", "+55-99-99999-9999", ], keepStatic: true });
|
|
220
|
+
*
|
|
221
|
+
* typing 1212345123 => should result in +55-12-1234-5123 type extra 4 => switch to +55-12-12345-1234
|
|
222
|
+
*
|
|
223
|
+
* When the option is not set, it will default to `false`, except for multiple masks it will default to `true`!
|
|
224
|
+
*/
|
|
225
|
+
keepStatic?: boolean | null | undefined;
|
|
226
|
+
/**
|
|
227
|
+
* When enabled the caret position is set after the latest valid position on TAB.
|
|
228
|
+
*
|
|
229
|
+
* @default true
|
|
230
|
+
*/
|
|
231
|
+
positionCaretOnTab?: boolean | undefined;
|
|
232
|
+
/**
|
|
233
|
+
* Allows for tabbing through the different parts of the masked field.
|
|
234
|
+
*
|
|
235
|
+
* @default false
|
|
236
|
+
*/
|
|
237
|
+
tabThrough?: boolean | undefined;
|
|
238
|
+
/**
|
|
239
|
+
* List with the supported input types
|
|
240
|
+
*
|
|
241
|
+
* @default ["text", "tel", "url", "password", "search"]
|
|
242
|
+
*/
|
|
243
|
+
supportsInputType?: string[] | undefined;
|
|
244
|
+
/**
|
|
245
|
+
* Specify keyCodes which should not be considered in the keypress event, otherwise the `preventDefault` will
|
|
246
|
+
* stop their default behavior especially in FF.
|
|
247
|
+
*/
|
|
248
|
+
ignorables?: number[] | undefined;
|
|
249
|
+
/**
|
|
250
|
+
* With this call-in (hook) you can override the default implementation of the isComplete function.
|
|
251
|
+
*/
|
|
252
|
+
isComplete?: ((buffer: string[], opts: Options$1) => boolean) | undefined;
|
|
253
|
+
/**
|
|
254
|
+
* Hook to postValidate the result from `isValid`. Useful for validating the entry as a whole.
|
|
255
|
+
*/
|
|
256
|
+
postValidation?: ((buffer: string[], pos: number, char: string, currentResult: boolean, opts: Options$1, maskset: any, strict: boolean, fromCheckval: boolean) => boolean | CommandObject) | undefined;
|
|
257
|
+
/**
|
|
258
|
+
* Hook to preValidate the input. Useful for validating regardless of the definition.
|
|
259
|
+
*
|
|
260
|
+
* When returning `true`, the normal validation kicks in, otherwise, it is skipped.
|
|
261
|
+
*
|
|
262
|
+
* When returning a command object the actions are executed and further validation is stopped. If you want to
|
|
263
|
+
* continue further validation, you need to add the `rewritePosition` action.
|
|
264
|
+
*/
|
|
265
|
+
preValidation?: ((buffer: string[], pos: number, char: string, isSelection: boolean, opts: Options$1, maskset: any, caretPos: {
|
|
266
|
+
begin: number;
|
|
267
|
+
end: number;
|
|
268
|
+
}, strict: boolean) => boolean | CommandObject) | undefined;
|
|
269
|
+
/**
|
|
270
|
+
* The `staticDefinitionSymbol` option is used to indicate that the static entries in the mask can match a
|
|
271
|
+
* certain definition. Especially useful with alternators so that static element in the mask can match
|
|
272
|
+
* another alternation.
|
|
273
|
+
*
|
|
274
|
+
* @default undefined
|
|
275
|
+
*/
|
|
276
|
+
staticDefinitionSymbol?: string | undefined;
|
|
277
|
+
/**
|
|
278
|
+
* Just in time masking. With the `jitMasking` option you can enable jit masking. The mask will only be
|
|
279
|
+
* visible for the user entered characters.
|
|
280
|
+
*
|
|
281
|
+
* @default false
|
|
282
|
+
*/
|
|
283
|
+
jitMasking?: boolean | undefined;
|
|
284
|
+
/**
|
|
285
|
+
* Return nothing from the input `value` property when the user hasn't entered anything. If this is false,
|
|
286
|
+
* the mask might be returned.
|
|
287
|
+
*
|
|
288
|
+
* @default true
|
|
289
|
+
*/
|
|
290
|
+
nullable?: boolean | undefined;
|
|
291
|
+
/**
|
|
292
|
+
* Disable value property patching
|
|
293
|
+
*
|
|
294
|
+
* @default false
|
|
295
|
+
*/
|
|
296
|
+
noValuePatching?: boolean | undefined;
|
|
297
|
+
/**
|
|
298
|
+
* Positioning of the caret on click.
|
|
299
|
+
*
|
|
300
|
+
* Options:
|
|
301
|
+
*
|
|
302
|
+
* * `none`
|
|
303
|
+
* * `lvp` - based on the last valid position (default)
|
|
304
|
+
* * `radixFocus` - position caret to radixpoint on initial click
|
|
305
|
+
* * `select` - select the whole input
|
|
306
|
+
* * `ignore` - ignore the click and continue the mask
|
|
307
|
+
*
|
|
308
|
+
* @default "lvp"
|
|
309
|
+
*/
|
|
310
|
+
positionCaretOnClick?: PositionCaretOnClick | undefined;
|
|
311
|
+
/**
|
|
312
|
+
* Apply casing at the mask-level.
|
|
313
|
+
*
|
|
314
|
+
* @default undefined
|
|
315
|
+
*/
|
|
316
|
+
casing?: Casing | undefined;
|
|
317
|
+
/**
|
|
318
|
+
* Specify the inputmode - already in place for when browsers start to support them
|
|
319
|
+
* https://html.spec.whatwg.org/#input-modalities:-the-inputmode-attribute
|
|
320
|
+
*
|
|
321
|
+
* @default "verbatim"
|
|
322
|
+
*/
|
|
323
|
+
inputmode?: InputMode | undefined;
|
|
324
|
+
/**
|
|
325
|
+
* Specify to use the `data-inputmask` attributes or to ignore them.
|
|
326
|
+
*
|
|
327
|
+
* If you don't use data attributes you can disable the import by specifying `importDataAttributes: false`.
|
|
328
|
+
*
|
|
329
|
+
* @default true
|
|
330
|
+
*/
|
|
331
|
+
importDataAttributes?: boolean | undefined;
|
|
332
|
+
/**
|
|
333
|
+
* Alter the behavior of the char shifting on entry or deletion.
|
|
334
|
+
*
|
|
335
|
+
* In some cases shifting the mask entries or deletion should be more restrictive.
|
|
336
|
+
*
|
|
337
|
+
* Ex. date masks. Shifting month to day makes no sense
|
|
338
|
+
*
|
|
339
|
+
* @default true
|
|
340
|
+
*/
|
|
341
|
+
shiftPositions?: boolean | undefined;
|
|
342
|
+
/**
|
|
343
|
+
* Use the default defined definitions from the prototype.
|
|
344
|
+
*
|
|
345
|
+
* @default true
|
|
346
|
+
*/
|
|
347
|
+
usePrototypeDefinitions?: boolean | undefined;
|
|
348
|
+
/**
|
|
349
|
+
* Minimum value. This needs to be in the same format as the `inputFormat` when used with the datetime alias.
|
|
350
|
+
*/
|
|
351
|
+
min?: string | number | undefined;
|
|
352
|
+
/**
|
|
353
|
+
* Maximum value. This needs to be in the same format as the `inputFormat` when used with the datetime alias.
|
|
354
|
+
*/
|
|
355
|
+
max?: string | number | undefined;
|
|
356
|
+
/**
|
|
357
|
+
* Number of fractionalDigits.
|
|
358
|
+
*
|
|
359
|
+
* Possible values:
|
|
360
|
+
*
|
|
361
|
+
* * A number describing the number of fractional digits.
|
|
362
|
+
* * `*`
|
|
363
|
+
* * Quantifier syntax like `2,4`. When the quantifier syntax is used, the `digitsOptional` option is ignored
|
|
364
|
+
*
|
|
365
|
+
* @default "*"
|
|
366
|
+
*/
|
|
367
|
+
digits?: string | number | undefined;
|
|
368
|
+
/**
|
|
369
|
+
* Specify wheter the digits are optional.
|
|
370
|
+
*
|
|
371
|
+
* @default true
|
|
372
|
+
*/
|
|
373
|
+
digitsOptional?: boolean | undefined;
|
|
374
|
+
/**
|
|
375
|
+
* Enforces the decimal part when leaving the input field.
|
|
376
|
+
*
|
|
377
|
+
* @default false
|
|
378
|
+
*/
|
|
379
|
+
enforceDigitsOnBlur?: boolean | undefined;
|
|
380
|
+
/**
|
|
381
|
+
* Allow to enter -.
|
|
382
|
+
*
|
|
383
|
+
* @default true
|
|
384
|
+
*/
|
|
385
|
+
allowMinus?: boolean | undefined;
|
|
386
|
+
/**
|
|
387
|
+
* Define your negationSymbol.
|
|
388
|
+
*
|
|
389
|
+
* @default { front: "-", back: "" }
|
|
390
|
+
*/
|
|
391
|
+
negationSymbol?: {
|
|
392
|
+
front: string;
|
|
393
|
+
back: string;
|
|
394
|
+
} | undefined;
|
|
395
|
+
/**
|
|
396
|
+
* Define a prefix.
|
|
397
|
+
*
|
|
398
|
+
* @default ""
|
|
399
|
+
*/
|
|
400
|
+
prefix?: string | undefined;
|
|
401
|
+
/**
|
|
402
|
+
* Define a suffix.
|
|
403
|
+
*
|
|
404
|
+
* @default ""
|
|
405
|
+
*/
|
|
406
|
+
suffix?: string | undefined;
|
|
407
|
+
/**
|
|
408
|
+
* Set the maximum value when the user types a number which is greater that the value of max.
|
|
409
|
+
*
|
|
410
|
+
* @default false
|
|
411
|
+
*/
|
|
412
|
+
SetMaxOnOverflow?: boolean | undefined;
|
|
413
|
+
/**
|
|
414
|
+
* Define the step the ctrl-up & ctrl-down must take.
|
|
415
|
+
*
|
|
416
|
+
* @default 1
|
|
417
|
+
*/
|
|
418
|
+
step?: number | undefined;
|
|
419
|
+
/**
|
|
420
|
+
* Make unmasking returning a number instead of a string.
|
|
421
|
+
*
|
|
422
|
+
* Be warned that using the unmaskAsNumber option together with jQuery.serialize will fail as serialize expects a string. (See issue #1288)
|
|
423
|
+
*
|
|
424
|
+
* @default false
|
|
425
|
+
*/
|
|
426
|
+
unmaskAsNumber?: boolean | undefined;
|
|
427
|
+
/**
|
|
428
|
+
* Indicates whether the value passed for initialization is text or a number.
|
|
429
|
+
*
|
|
430
|
+
* * `text` - radixpoint should be the same as in the options
|
|
431
|
+
* * `number` - radixpoint should be a . as the default for a number in js
|
|
432
|
+
*
|
|
433
|
+
* @default "text"
|
|
434
|
+
*/
|
|
435
|
+
inputType?: 'text' | 'number' | undefined;
|
|
436
|
+
/**
|
|
437
|
+
* Set the function for rounding the values when set.
|
|
438
|
+
*
|
|
439
|
+
* Other examples:
|
|
440
|
+
* * `Math.floor`
|
|
441
|
+
* * `fn(x) { // do your own rounding logic // return x; }`
|
|
442
|
+
*
|
|
443
|
+
* @default Math.round
|
|
444
|
+
*/
|
|
445
|
+
roundingFN?: ((input: number) => number) | undefined;
|
|
446
|
+
/**
|
|
447
|
+
* Define shortcuts. This will allow typing 1k => 1000, 2m => 2000000
|
|
448
|
+
*
|
|
449
|
+
* To disable just pass shortcuts: `null` as option
|
|
450
|
+
*
|
|
451
|
+
* @default {k: "000", m: "000000"}
|
|
452
|
+
*/
|
|
453
|
+
shortcuts?: {
|
|
454
|
+
[shortcut: string]: string;
|
|
455
|
+
} | null | undefined;
|
|
456
|
+
/**
|
|
457
|
+
* Format used to input a date. This option is only effective for the datetime alias.
|
|
458
|
+
*
|
|
459
|
+
* Supported symbols
|
|
460
|
+
*
|
|
461
|
+
* * `d` - Day of the month as digits; no leading zero for single-digit days.
|
|
462
|
+
* * `dd` - Day of the month as digits; leading zero for single-digit days.
|
|
463
|
+
* * `ddd` - Day of the week as a three-letter abbreviation.
|
|
464
|
+
* * `dddd` - Day of the week as its full name.
|
|
465
|
+
* * `m` - Month as digits; no leading zero for single-digit months.
|
|
466
|
+
* * `mm` - Month as digits; leading zero for single-digit months.
|
|
467
|
+
* * `mmm` - Month as a three-letter abbreviation.
|
|
468
|
+
* * `mmmm` - Month as its full name.
|
|
469
|
+
* * `yy` - Year as last two digits; leading zero for years less than 10.
|
|
470
|
+
* * `yyyy` - Year as 4 digits.
|
|
471
|
+
* * `h` - Hours; no leading zero for single-digit hours (12-hour clock).
|
|
472
|
+
* * `hh` - Hours; leading zero for single-digit hours (12-hour clock).
|
|
473
|
+
* * `hx` - Hours; no limit; `x` = number of digits ~ use as h2, h3, ...
|
|
474
|
+
* * `H` - Hours; no leading zero for single-digit hours (24-hour clock).
|
|
475
|
+
* * `HH` - Hours; leading zero for single-digit hours (24-hour clock).
|
|
476
|
+
* * `Hx` - Hours; no limit; `x` = number of digits ~ use as H2, H3, ...
|
|
477
|
+
* * `M` - Minutes; no leading zero for single-digit minutes. Uppercase M unlike CF timeFormat's m to avoid
|
|
478
|
+
* conflict with months.
|
|
479
|
+
* * `MM` - Minutes; leading zero for single-digit minutes. Uppercase MM unlike CF timeFormat's mm to avoid
|
|
480
|
+
* conflict with months.
|
|
481
|
+
* * `s` - Seconds; no leading zero for single-digit seconds.
|
|
482
|
+
* * `ss` - Seconds; leading zero for single-digit seconds.
|
|
483
|
+
* * `l` - Milliseconds. 3 digits.
|
|
484
|
+
* * `L` - Milliseconds. 2 digits.
|
|
485
|
+
* * `t` - Lowercase, single-character time marker string: a or p.
|
|
486
|
+
* * `tt` - Two-character time marker string: am or pm.
|
|
487
|
+
* * `T` - Single-character time marker string: A or P.
|
|
488
|
+
* * `TT` - Two-character time marker string: AM or PM.
|
|
489
|
+
* * `Z` - US timezone abbreviation, e.g. EST or MDT. With non-US timezones or in the Opera browser, the
|
|
490
|
+
* GMT/UTC offset is returned, e.g. GMT-0500
|
|
491
|
+
* * `o` - GMT/UTC timezone offset, e.g. -0500 or +0230.
|
|
492
|
+
* * `S` - The date's ordinal suffix (st, nd, rd, or th). Works well with d.
|
|
493
|
+
*
|
|
494
|
+
* @default "isoDateTime"
|
|
495
|
+
*/
|
|
496
|
+
inputFormat?: string | undefined;
|
|
497
|
+
/**
|
|
498
|
+
* Format of the unmasked value. This is only effective when used with the datetime alias.
|
|
499
|
+
*/
|
|
500
|
+
outputFormat?: string | undefined;
|
|
501
|
+
/**
|
|
502
|
+
* Visual format when the input looses focus
|
|
503
|
+
*/
|
|
504
|
+
displayFormat?: string | undefined;
|
|
505
|
+
/**
|
|
506
|
+
* Add new definitions to this inputmask.
|
|
507
|
+
*/
|
|
508
|
+
definitions?: {
|
|
509
|
+
[key: string]: Definition;
|
|
510
|
+
} | undefined;
|
|
511
|
+
/**
|
|
512
|
+
* Enable/disable prefilling of the year.
|
|
513
|
+
* Although you can just over type the proposed value without deleting, many seems to see a problem with the year prediction.
|
|
514
|
+
* This options is to disable this feature.
|
|
515
|
+
*
|
|
516
|
+
* @default true
|
|
517
|
+
*/
|
|
518
|
+
prefillYear?: boolean | undefined;
|
|
519
|
+
}
|
|
520
|
+
interface Definition {
|
|
521
|
+
validator: string | DefinitionValidator;
|
|
522
|
+
casing?: Casing | undefined;
|
|
523
|
+
cardinality?: number | undefined;
|
|
524
|
+
placeholder?: string | undefined;
|
|
525
|
+
definitionSymbol?: string | undefined;
|
|
526
|
+
}
|
|
527
|
+
interface InsertPosition {
|
|
528
|
+
/**
|
|
529
|
+
* Position to insert.
|
|
530
|
+
*/
|
|
531
|
+
pos: number;
|
|
532
|
+
/**
|
|
533
|
+
* Character to insert.
|
|
534
|
+
*/
|
|
535
|
+
c: string;
|
|
536
|
+
/**
|
|
537
|
+
* @default true
|
|
538
|
+
*/
|
|
539
|
+
fromIsValid?: boolean | undefined;
|
|
540
|
+
/**
|
|
541
|
+
* @default true
|
|
542
|
+
*/
|
|
543
|
+
strict?: boolean | undefined;
|
|
544
|
+
}
|
|
545
|
+
interface CommandObject {
|
|
546
|
+
/**
|
|
547
|
+
* Position to insert.
|
|
548
|
+
*/
|
|
549
|
+
pos?: number | undefined;
|
|
550
|
+
/**
|
|
551
|
+
* Character to insert.
|
|
552
|
+
*/
|
|
553
|
+
c?: string | undefined;
|
|
554
|
+
/**
|
|
555
|
+
* Position of the caret.
|
|
556
|
+
*/
|
|
557
|
+
caret?: number | undefined;
|
|
558
|
+
/**
|
|
559
|
+
* Position(s) to remove.
|
|
560
|
+
*/
|
|
561
|
+
remove?: number | number[] | undefined;
|
|
562
|
+
/**
|
|
563
|
+
* Position(s) to add.
|
|
564
|
+
*/
|
|
565
|
+
insert?: InsertPosition | InsertPosition[] | undefined;
|
|
566
|
+
/**
|
|
567
|
+
* * `true` => refresh validPositions from the complete buffer .
|
|
568
|
+
* * `{ start: , end: }` => refresh from start to end.
|
|
569
|
+
*/
|
|
570
|
+
refreshFromBuffer?: true | {
|
|
571
|
+
start: number;
|
|
572
|
+
end: number;
|
|
573
|
+
} | undefined;
|
|
574
|
+
/**
|
|
575
|
+
* Rewrite the maskPos within the isvalid function.
|
|
576
|
+
*/
|
|
577
|
+
rewritePosition?: number | undefined;
|
|
578
|
+
}
|
|
579
|
+
|
|
7
580
|
type Mask = 'email' | 'cpf' | 'datetime' | 'numeric' | 'currency' | 'decimal' | 'integer' | (string & {}) | (string[] & {}) | null;
|
|
8
|
-
type Options =
|
|
581
|
+
type Options = Options$1;
|
|
9
582
|
type Input = HTMLInputElement | HTMLTextAreaElement | HTMLElement | HTMLInputElement | null;
|
|
10
583
|
|
|
11
584
|
declare const withHookFormMask: (register: UseFormRegisterReturn, mask: Mask, options?: Options) => UseFormRegisterReturn;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-mask-input",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.5",
|
|
4
4
|
"description": "A react Hook for build elegant input masks. Compatible with React Hook Form",
|
|
5
5
|
"author": "Eduardo Borges<euduardoborges@gmail.com>",
|
|
6
6
|
"type": "module",
|
|
@@ -40,20 +40,20 @@
|
|
|
40
40
|
"@rollup/plugin-commonjs": "25.0.4",
|
|
41
41
|
"@rollup/plugin-node-resolve": "15.2.1",
|
|
42
42
|
"@semantic-release/changelog": "6.0.3",
|
|
43
|
-
"@semantic-release/commit-analyzer": "10.0.
|
|
43
|
+
"@semantic-release/commit-analyzer": "10.0.4",
|
|
44
44
|
"@semantic-release/git": "10.0.1",
|
|
45
45
|
"@semantic-release/github": "9.0.4",
|
|
46
46
|
"@semantic-release/npm": "10.0.5",
|
|
47
|
-
"@semantic-release/release-notes-generator": "11.0.
|
|
47
|
+
"@semantic-release/release-notes-generator": "11.0.7",
|
|
48
48
|
"@types/inputmask": "5.0.3",
|
|
49
49
|
"@types/node": "16",
|
|
50
50
|
"@types/react": ">=16.4 || 17 || 18",
|
|
51
51
|
"@types/react-dom": ">=16.4 || 17 || 18",
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "6.
|
|
53
|
-
"@typescript-eslint/parser": "6.
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "6.5.0",
|
|
53
|
+
"@typescript-eslint/parser": "6.5.0",
|
|
54
54
|
"@vitest/coverage-v8": "0.34.3",
|
|
55
55
|
"esbuild": "0.19.2",
|
|
56
|
-
"eslint": "8.
|
|
56
|
+
"eslint": "8.48.0",
|
|
57
57
|
"eslint-config-airbnb": "19.0.4",
|
|
58
58
|
"eslint-config-airbnb-typescript": "17.1.0",
|
|
59
59
|
"eslint-plugin-import": "2.28.1",
|
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
|
|
3
|
+
type Range = { start: string; end: string } | [string, string];
|
|
4
|
+
|
|
5
|
+
type PositionCaretOnClick = 'none' | 'lvp' | 'radixFocus' | 'select' | 'ignore';
|
|
6
|
+
|
|
7
|
+
type InputMode = 'verbatim' | 'none' | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url';
|
|
8
|
+
|
|
9
|
+
type Casing = 'upper' | 'lower' | 'title';
|
|
10
|
+
|
|
11
|
+
// `maskset` typed as `any`, since its content is not described in the documentation
|
|
12
|
+
type DefinitionValidator = (
|
|
13
|
+
chrs: string,
|
|
14
|
+
maskset: any,
|
|
15
|
+
pos: number,
|
|
16
|
+
strict: boolean,
|
|
17
|
+
opts: Options,
|
|
18
|
+
) => boolean | CommandObject;
|
|
19
|
+
|
|
20
|
+
export interface Options {
|
|
21
|
+
/**
|
|
22
|
+
* Change the mask placeholder. Instead of "_", you can change the unfilled characters mask as you like, simply
|
|
23
|
+
* by adding the placeholder option. For example, placeholder: " " will change the default autofill with empty
|
|
24
|
+
* values.
|
|
25
|
+
*
|
|
26
|
+
* @default "_"
|
|
27
|
+
*/
|
|
28
|
+
placeholder?: string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Definition of the symbols used to indicate an optional part in the mask.
|
|
31
|
+
*
|
|
32
|
+
* @default { start: "[", end: "]" }
|
|
33
|
+
*/
|
|
34
|
+
optionalmarker?: Range | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Definition of the symbols used to indicate a quantifier in the mask.
|
|
37
|
+
*
|
|
38
|
+
* @default { start: "{", end: "}" }
|
|
39
|
+
*/
|
|
40
|
+
quantifiermarker?: Range | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Definition of the symbols used to indicate a group in the mask.
|
|
43
|
+
*
|
|
44
|
+
* @default { start: "(", end: ")" }
|
|
45
|
+
*/
|
|
46
|
+
groupmarker?: Range | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Definition of the symbols used to indicate an alternator part in the mask.
|
|
49
|
+
*
|
|
50
|
+
* @default "|"
|
|
51
|
+
*/
|
|
52
|
+
alternatormarker?: string | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Definition of the symbols used to escape a part in the mask.
|
|
55
|
+
*
|
|
56
|
+
* @default "\\"
|
|
57
|
+
*/
|
|
58
|
+
escapeChar?: string | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* The mask to use.
|
|
61
|
+
*/
|
|
62
|
+
mask?: string | string[] | ((opts: Options) => string | string[]) | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Use a regular expression as a mask. When using shorthands be aware that you need to double escape or use
|
|
65
|
+
* String.raw with a string literal.
|
|
66
|
+
*/
|
|
67
|
+
regex?: string | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Execute a function when the mask is completed.
|
|
70
|
+
*/
|
|
71
|
+
oncomplete?: (() => void) | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Execute a function when the mask is cleared.
|
|
74
|
+
*/
|
|
75
|
+
onincomplete?: (() => void) | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Execute a function when the mask is cleared.
|
|
78
|
+
*/
|
|
79
|
+
oncleared?: (() => void) | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Mask repeat function. Repeat the mask definition x-times.
|
|
82
|
+
* `*` ~ forever, otherwise specify an integer
|
|
83
|
+
*
|
|
84
|
+
* @default 0
|
|
85
|
+
*/
|
|
86
|
+
repeat?: number | string | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Toggle to allocate as much possible or the opposite. Non-greedy repeat function. With the non-greedy option
|
|
89
|
+
* set to `false`, you can specify `*` as repeat. This makes an endless repeat.
|
|
90
|
+
*
|
|
91
|
+
* @default false
|
|
92
|
+
*/
|
|
93
|
+
greedy?: boolean | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Automatically unmask the value when retrieved.
|
|
96
|
+
*
|
|
97
|
+
* When setting this option to true the plugin also expects the initial value from the server to be unmasked.
|
|
98
|
+
*
|
|
99
|
+
* @default false
|
|
100
|
+
*/
|
|
101
|
+
autoUnmask?: boolean | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Remove the mask before submitting the form.
|
|
104
|
+
*
|
|
105
|
+
* @default false
|
|
106
|
+
*/
|
|
107
|
+
removeMaskOnSubmit?: boolean | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* Remove the empty mask on blur or when not empty remove the optional trailing part.
|
|
110
|
+
*
|
|
111
|
+
* @default true
|
|
112
|
+
*/
|
|
113
|
+
clearMaskOnLostFocus?: boolean | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Toggle to insert or overwrite input. This option can be altered by pressing the Insert key.
|
|
116
|
+
*
|
|
117
|
+
* @default true
|
|
118
|
+
*/
|
|
119
|
+
insertMode?: boolean | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* Show selected caret when `insertMode = false`.
|
|
122
|
+
*
|
|
123
|
+
* @default true
|
|
124
|
+
*/
|
|
125
|
+
insertModeVisual?: boolean | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* Clear the incomplete input on blur.
|
|
128
|
+
*
|
|
129
|
+
* @default false
|
|
130
|
+
*/
|
|
131
|
+
clearIncomplete?: boolean | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* The alias to use.
|
|
134
|
+
*
|
|
135
|
+
* @default null
|
|
136
|
+
*/
|
|
137
|
+
alias?: string | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* Callback to implement autocomplete on certain keys for example.
|
|
140
|
+
*/
|
|
141
|
+
onKeyDown?:
|
|
142
|
+
| ((
|
|
143
|
+
event: KeyboardEvent,
|
|
144
|
+
buffer: string[],
|
|
145
|
+
caretPos: { begin: number; end: number },
|
|
146
|
+
opts: Options,
|
|
147
|
+
) => void)
|
|
148
|
+
| undefined;
|
|
149
|
+
/**
|
|
150
|
+
* Executes before masking the initial value to allow preprocessing of the initial value.
|
|
151
|
+
*/
|
|
152
|
+
onBeforeMask?: ((initialValue: string, opts: Options) => string) | undefined;
|
|
153
|
+
/**
|
|
154
|
+
* This callback allows for preprocessing the pasted value before actually handling the value for masking.
|
|
155
|
+
* This can be useful for stripping away some characters before processing. You can also disable pasting
|
|
156
|
+
* a value by returning false in the `onBeforePaste` call.
|
|
157
|
+
*/
|
|
158
|
+
onBeforePaste?: ((pastedValue: string, opts: Options) => string) | undefined;
|
|
159
|
+
/**
|
|
160
|
+
* Executes before writing to the masked element. Use this to do some extra processing of the input. This can
|
|
161
|
+
* be useful when implementing an alias, ex. decimal alias, autofill the digits when leaving the inputfield.
|
|
162
|
+
*/
|
|
163
|
+
onBeforeWrite?:
|
|
164
|
+
| ((event: KeyboardEvent, buffer: string[], caretPos: number, opts: Options) => CommandObject)
|
|
165
|
+
| undefined;
|
|
166
|
+
/**
|
|
167
|
+
* Executes after unmasking to allow post-processing of the unmaskedvalue.
|
|
168
|
+
*
|
|
169
|
+
* @returns New unmasked value
|
|
170
|
+
*/
|
|
171
|
+
onUnMask?: ((maskedValue: string, unmaskedValue: string) => string) | undefined;
|
|
172
|
+
/**
|
|
173
|
+
* Shows the mask when the input gets focus.
|
|
174
|
+
*
|
|
175
|
+
* @default true
|
|
176
|
+
*/
|
|
177
|
+
showMaskOnFocus?: boolean | undefined;
|
|
178
|
+
/**
|
|
179
|
+
* Shows the mask when the input is hevered by the mouse cursor.
|
|
180
|
+
*
|
|
181
|
+
* @default true
|
|
182
|
+
*/
|
|
183
|
+
showMaskOnHover?: boolean | undefined;
|
|
184
|
+
/**
|
|
185
|
+
* Callback function is executed on every keyvalidation with the key, result as the parameter.
|
|
186
|
+
*/
|
|
187
|
+
onKeyValidation?: ((key: number, result: boolean) => void) | undefined;
|
|
188
|
+
/**
|
|
189
|
+
* A character which can be used to skip an optional part of a mask.
|
|
190
|
+
*
|
|
191
|
+
* @default " "
|
|
192
|
+
*/
|
|
193
|
+
skipOptionalPartCharacter?: string | undefined;
|
|
194
|
+
/**
|
|
195
|
+
* Numeric input direction. Keeps the caret at the end.
|
|
196
|
+
*
|
|
197
|
+
* @default false
|
|
198
|
+
*/
|
|
199
|
+
numericInput?: boolean | undefined;
|
|
200
|
+
/**
|
|
201
|
+
* Align the input to the right
|
|
202
|
+
*
|
|
203
|
+
* By setting the rightAlign you can specify to right-align an inputmask. This is only applied in combination of
|
|
204
|
+
* the `numericInput` option or the `dir-attribute`.
|
|
205
|
+
*
|
|
206
|
+
* @default true
|
|
207
|
+
*/
|
|
208
|
+
rightAlign?: boolean | undefined;
|
|
209
|
+
/**
|
|
210
|
+
* Make escape behave like undo. (ctrl-Z) Pressing escape reverts the value to the value before focus.
|
|
211
|
+
*
|
|
212
|
+
* @default true
|
|
213
|
+
*/
|
|
214
|
+
undoOnEscape?: boolean | undefined;
|
|
215
|
+
/**
|
|
216
|
+
* Define the radixpoint (decimal separator)
|
|
217
|
+
*
|
|
218
|
+
* @default ""
|
|
219
|
+
*/
|
|
220
|
+
radixPoint?: string | undefined;
|
|
221
|
+
/**
|
|
222
|
+
* Define the groupseparator.
|
|
223
|
+
*
|
|
224
|
+
* @default ""
|
|
225
|
+
*/
|
|
226
|
+
groupSeparator?: string | undefined;
|
|
227
|
+
/**
|
|
228
|
+
* Use in combination with the alternator syntax Try to keep the mask static while typing. Decisions to alter the
|
|
229
|
+
* mask will be postponed if possible.
|
|
230
|
+
*
|
|
231
|
+
* ex. $(selector).inputmask({ mask: ["+55-99-9999-9999", "+55-99-99999-9999", ], keepStatic: true });
|
|
232
|
+
*
|
|
233
|
+
* typing 1212345123 => should result in +55-12-1234-5123 type extra 4 => switch to +55-12-12345-1234
|
|
234
|
+
*
|
|
235
|
+
* When the option is not set, it will default to `false`, except for multiple masks it will default to `true`!
|
|
236
|
+
*/
|
|
237
|
+
keepStatic?: boolean | null | undefined;
|
|
238
|
+
/**
|
|
239
|
+
* When enabled the caret position is set after the latest valid position on TAB.
|
|
240
|
+
*
|
|
241
|
+
* @default true
|
|
242
|
+
*/
|
|
243
|
+
positionCaretOnTab?: boolean | undefined;
|
|
244
|
+
/**
|
|
245
|
+
* Allows for tabbing through the different parts of the masked field.
|
|
246
|
+
*
|
|
247
|
+
* @default false
|
|
248
|
+
*/
|
|
249
|
+
tabThrough?: boolean | undefined;
|
|
250
|
+
/**
|
|
251
|
+
* List with the supported input types
|
|
252
|
+
*
|
|
253
|
+
* @default ["text", "tel", "url", "password", "search"]
|
|
254
|
+
*/
|
|
255
|
+
supportsInputType?: string[] | undefined;
|
|
256
|
+
/**
|
|
257
|
+
* Specify keyCodes which should not be considered in the keypress event, otherwise the `preventDefault` will
|
|
258
|
+
* stop their default behavior especially in FF.
|
|
259
|
+
*/
|
|
260
|
+
ignorables?: number[] | undefined;
|
|
261
|
+
/**
|
|
262
|
+
* With this call-in (hook) you can override the default implementation of the isComplete function.
|
|
263
|
+
*/
|
|
264
|
+
isComplete?: ((buffer: string[], opts: Options) => boolean) | undefined;
|
|
265
|
+
/**
|
|
266
|
+
* Hook to postValidate the result from `isValid`. Useful for validating the entry as a whole.
|
|
267
|
+
*/
|
|
268
|
+
postValidation?:
|
|
269
|
+
| ((
|
|
270
|
+
buffer: string[],
|
|
271
|
+
pos: number,
|
|
272
|
+
char: string,
|
|
273
|
+
currentResult: boolean,
|
|
274
|
+
opts: Options,
|
|
275
|
+
maskset: any,
|
|
276
|
+
strict: boolean,
|
|
277
|
+
fromCheckval: boolean,
|
|
278
|
+
) => boolean | CommandObject)
|
|
279
|
+
| undefined;
|
|
280
|
+
/**
|
|
281
|
+
* Hook to preValidate the input. Useful for validating regardless of the definition.
|
|
282
|
+
*
|
|
283
|
+
* When returning `true`, the normal validation kicks in, otherwise, it is skipped.
|
|
284
|
+
*
|
|
285
|
+
* When returning a command object the actions are executed and further validation is stopped. If you want to
|
|
286
|
+
* continue further validation, you need to add the `rewritePosition` action.
|
|
287
|
+
*/
|
|
288
|
+
preValidation?:
|
|
289
|
+
| ((
|
|
290
|
+
buffer: string[],
|
|
291
|
+
pos: number,
|
|
292
|
+
char: string,
|
|
293
|
+
isSelection: boolean,
|
|
294
|
+
opts: Options,
|
|
295
|
+
maskset: any,
|
|
296
|
+
caretPos: { begin: number; end: number },
|
|
297
|
+
strict: boolean,
|
|
298
|
+
) => boolean | CommandObject)
|
|
299
|
+
| undefined;
|
|
300
|
+
/**
|
|
301
|
+
* The `staticDefinitionSymbol` option is used to indicate that the static entries in the mask can match a
|
|
302
|
+
* certain definition. Especially useful with alternators so that static element in the mask can match
|
|
303
|
+
* another alternation.
|
|
304
|
+
*
|
|
305
|
+
* @default undefined
|
|
306
|
+
*/
|
|
307
|
+
staticDefinitionSymbol?: string | undefined;
|
|
308
|
+
/**
|
|
309
|
+
* Just in time masking. With the `jitMasking` option you can enable jit masking. The mask will only be
|
|
310
|
+
* visible for the user entered characters.
|
|
311
|
+
*
|
|
312
|
+
* @default false
|
|
313
|
+
*/
|
|
314
|
+
jitMasking?: boolean | undefined;
|
|
315
|
+
/**
|
|
316
|
+
* Return nothing from the input `value` property when the user hasn't entered anything. If this is false,
|
|
317
|
+
* the mask might be returned.
|
|
318
|
+
*
|
|
319
|
+
* @default true
|
|
320
|
+
*/
|
|
321
|
+
nullable?: boolean | undefined;
|
|
322
|
+
/**
|
|
323
|
+
* Disable value property patching
|
|
324
|
+
*
|
|
325
|
+
* @default false
|
|
326
|
+
*/
|
|
327
|
+
noValuePatching?: boolean | undefined;
|
|
328
|
+
/**
|
|
329
|
+
* Positioning of the caret on click.
|
|
330
|
+
*
|
|
331
|
+
* Options:
|
|
332
|
+
*
|
|
333
|
+
* * `none`
|
|
334
|
+
* * `lvp` - based on the last valid position (default)
|
|
335
|
+
* * `radixFocus` - position caret to radixpoint on initial click
|
|
336
|
+
* * `select` - select the whole input
|
|
337
|
+
* * `ignore` - ignore the click and continue the mask
|
|
338
|
+
*
|
|
339
|
+
* @default "lvp"
|
|
340
|
+
*/
|
|
341
|
+
positionCaretOnClick?: PositionCaretOnClick | undefined;
|
|
342
|
+
/**
|
|
343
|
+
* Apply casing at the mask-level.
|
|
344
|
+
*
|
|
345
|
+
* @default undefined
|
|
346
|
+
*/
|
|
347
|
+
casing?: Casing | undefined;
|
|
348
|
+
/**
|
|
349
|
+
* Specify the inputmode - already in place for when browsers start to support them
|
|
350
|
+
* https://html.spec.whatwg.org/#input-modalities:-the-inputmode-attribute
|
|
351
|
+
*
|
|
352
|
+
* @default "verbatim"
|
|
353
|
+
*/
|
|
354
|
+
inputmode?: InputMode | undefined;
|
|
355
|
+
/**
|
|
356
|
+
* Specify to use the `data-inputmask` attributes or to ignore them.
|
|
357
|
+
*
|
|
358
|
+
* If you don't use data attributes you can disable the import by specifying `importDataAttributes: false`.
|
|
359
|
+
*
|
|
360
|
+
* @default true
|
|
361
|
+
*/
|
|
362
|
+
importDataAttributes?: boolean | undefined;
|
|
363
|
+
/**
|
|
364
|
+
* Alter the behavior of the char shifting on entry or deletion.
|
|
365
|
+
*
|
|
366
|
+
* In some cases shifting the mask entries or deletion should be more restrictive.
|
|
367
|
+
*
|
|
368
|
+
* Ex. date masks. Shifting month to day makes no sense
|
|
369
|
+
*
|
|
370
|
+
* @default true
|
|
371
|
+
*/
|
|
372
|
+
shiftPositions?: boolean | undefined;
|
|
373
|
+
/**
|
|
374
|
+
* Use the default defined definitions from the prototype.
|
|
375
|
+
*
|
|
376
|
+
* @default true
|
|
377
|
+
*/
|
|
378
|
+
usePrototypeDefinitions?: boolean | undefined;
|
|
379
|
+
/**
|
|
380
|
+
* Minimum value. This needs to be in the same format as the `inputFormat` when used with the datetime alias.
|
|
381
|
+
*/
|
|
382
|
+
min?: string | number | undefined;
|
|
383
|
+
/**
|
|
384
|
+
* Maximum value. This needs to be in the same format as the `inputFormat` when used with the datetime alias.
|
|
385
|
+
*/
|
|
386
|
+
max?: string | number | undefined;
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Number of fractionalDigits.
|
|
390
|
+
*
|
|
391
|
+
* Possible values:
|
|
392
|
+
*
|
|
393
|
+
* * A number describing the number of fractional digits.
|
|
394
|
+
* * `*`
|
|
395
|
+
* * Quantifier syntax like `2,4`. When the quantifier syntax is used, the `digitsOptional` option is ignored
|
|
396
|
+
*
|
|
397
|
+
* @default "*"
|
|
398
|
+
*/
|
|
399
|
+
digits?: string | number | undefined;
|
|
400
|
+
/**
|
|
401
|
+
* Specify wheter the digits are optional.
|
|
402
|
+
*
|
|
403
|
+
* @default true
|
|
404
|
+
*/
|
|
405
|
+
digitsOptional?: boolean | undefined;
|
|
406
|
+
/**
|
|
407
|
+
* Enforces the decimal part when leaving the input field.
|
|
408
|
+
*
|
|
409
|
+
* @default false
|
|
410
|
+
*/
|
|
411
|
+
enforceDigitsOnBlur?: boolean | undefined;
|
|
412
|
+
/**
|
|
413
|
+
* Allow to enter -.
|
|
414
|
+
*
|
|
415
|
+
* @default true
|
|
416
|
+
*/
|
|
417
|
+
allowMinus?: boolean | undefined;
|
|
418
|
+
/**
|
|
419
|
+
* Define your negationSymbol.
|
|
420
|
+
*
|
|
421
|
+
* @default { front: "-", back: "" }
|
|
422
|
+
*/
|
|
423
|
+
negationSymbol?: { front: string; back: string } | undefined;
|
|
424
|
+
/**
|
|
425
|
+
* Define a prefix.
|
|
426
|
+
*
|
|
427
|
+
* @default ""
|
|
428
|
+
*/
|
|
429
|
+
prefix?: string | undefined;
|
|
430
|
+
/**
|
|
431
|
+
* Define a suffix.
|
|
432
|
+
*
|
|
433
|
+
* @default ""
|
|
434
|
+
*/
|
|
435
|
+
suffix?: string | undefined;
|
|
436
|
+
/**
|
|
437
|
+
* Set the maximum value when the user types a number which is greater that the value of max.
|
|
438
|
+
*
|
|
439
|
+
* @default false
|
|
440
|
+
*/
|
|
441
|
+
SetMaxOnOverflow?: boolean | undefined;
|
|
442
|
+
/**
|
|
443
|
+
* Define the step the ctrl-up & ctrl-down must take.
|
|
444
|
+
*
|
|
445
|
+
* @default 1
|
|
446
|
+
*/
|
|
447
|
+
step?: number | undefined;
|
|
448
|
+
/**
|
|
449
|
+
* Make unmasking returning a number instead of a string.
|
|
450
|
+
*
|
|
451
|
+
* Be warned that using the unmaskAsNumber option together with jQuery.serialize will fail as serialize expects a string. (See issue #1288)
|
|
452
|
+
*
|
|
453
|
+
* @default false
|
|
454
|
+
*/
|
|
455
|
+
unmaskAsNumber?: boolean | undefined;
|
|
456
|
+
/**
|
|
457
|
+
* Indicates whether the value passed for initialization is text or a number.
|
|
458
|
+
*
|
|
459
|
+
* * `text` - radixpoint should be the same as in the options
|
|
460
|
+
* * `number` - radixpoint should be a . as the default for a number in js
|
|
461
|
+
*
|
|
462
|
+
* @default "text"
|
|
463
|
+
*/
|
|
464
|
+
inputType?: 'text' | 'number' | undefined;
|
|
465
|
+
/**
|
|
466
|
+
* Set the function for rounding the values when set.
|
|
467
|
+
*
|
|
468
|
+
* Other examples:
|
|
469
|
+
* * `Math.floor`
|
|
470
|
+
* * `fn(x) { // do your own rounding logic // return x; }`
|
|
471
|
+
*
|
|
472
|
+
* @default Math.round
|
|
473
|
+
*/
|
|
474
|
+
roundingFN?: ((input: number) => number) | undefined;
|
|
475
|
+
/**
|
|
476
|
+
* Define shortcuts. This will allow typing 1k => 1000, 2m => 2000000
|
|
477
|
+
*
|
|
478
|
+
* To disable just pass shortcuts: `null` as option
|
|
479
|
+
*
|
|
480
|
+
* @default {k: "000", m: "000000"}
|
|
481
|
+
*/
|
|
482
|
+
shortcuts?: { [shortcut: string]: string } | null | undefined;
|
|
483
|
+
/**
|
|
484
|
+
* Format used to input a date. This option is only effective for the datetime alias.
|
|
485
|
+
*
|
|
486
|
+
* Supported symbols
|
|
487
|
+
*
|
|
488
|
+
* * `d` - Day of the month as digits; no leading zero for single-digit days.
|
|
489
|
+
* * `dd` - Day of the month as digits; leading zero for single-digit days.
|
|
490
|
+
* * `ddd` - Day of the week as a three-letter abbreviation.
|
|
491
|
+
* * `dddd` - Day of the week as its full name.
|
|
492
|
+
* * `m` - Month as digits; no leading zero for single-digit months.
|
|
493
|
+
* * `mm` - Month as digits; leading zero for single-digit months.
|
|
494
|
+
* * `mmm` - Month as a three-letter abbreviation.
|
|
495
|
+
* * `mmmm` - Month as its full name.
|
|
496
|
+
* * `yy` - Year as last two digits; leading zero for years less than 10.
|
|
497
|
+
* * `yyyy` - Year as 4 digits.
|
|
498
|
+
* * `h` - Hours; no leading zero for single-digit hours (12-hour clock).
|
|
499
|
+
* * `hh` - Hours; leading zero for single-digit hours (12-hour clock).
|
|
500
|
+
* * `hx` - Hours; no limit; `x` = number of digits ~ use as h2, h3, ...
|
|
501
|
+
* * `H` - Hours; no leading zero for single-digit hours (24-hour clock).
|
|
502
|
+
* * `HH` - Hours; leading zero for single-digit hours (24-hour clock).
|
|
503
|
+
* * `Hx` - Hours; no limit; `x` = number of digits ~ use as H2, H3, ...
|
|
504
|
+
* * `M` - Minutes; no leading zero for single-digit minutes. Uppercase M unlike CF timeFormat's m to avoid
|
|
505
|
+
* conflict with months.
|
|
506
|
+
* * `MM` - Minutes; leading zero for single-digit minutes. Uppercase MM unlike CF timeFormat's mm to avoid
|
|
507
|
+
* conflict with months.
|
|
508
|
+
* * `s` - Seconds; no leading zero for single-digit seconds.
|
|
509
|
+
* * `ss` - Seconds; leading zero for single-digit seconds.
|
|
510
|
+
* * `l` - Milliseconds. 3 digits.
|
|
511
|
+
* * `L` - Milliseconds. 2 digits.
|
|
512
|
+
* * `t` - Lowercase, single-character time marker string: a or p.
|
|
513
|
+
* * `tt` - Two-character time marker string: am or pm.
|
|
514
|
+
* * `T` - Single-character time marker string: A or P.
|
|
515
|
+
* * `TT` - Two-character time marker string: AM or PM.
|
|
516
|
+
* * `Z` - US timezone abbreviation, e.g. EST or MDT. With non-US timezones or in the Opera browser, the
|
|
517
|
+
* GMT/UTC offset is returned, e.g. GMT-0500
|
|
518
|
+
* * `o` - GMT/UTC timezone offset, e.g. -0500 or +0230.
|
|
519
|
+
* * `S` - The date's ordinal suffix (st, nd, rd, or th). Works well with d.
|
|
520
|
+
*
|
|
521
|
+
* @default "isoDateTime"
|
|
522
|
+
*/
|
|
523
|
+
inputFormat?: string | undefined;
|
|
524
|
+
/**
|
|
525
|
+
* Format of the unmasked value. This is only effective when used with the datetime alias.
|
|
526
|
+
*/
|
|
527
|
+
outputFormat?: string | undefined;
|
|
528
|
+
/**
|
|
529
|
+
* Visual format when the input looses focus
|
|
530
|
+
*/
|
|
531
|
+
displayFormat?: string | undefined;
|
|
532
|
+
/**
|
|
533
|
+
* Add new definitions to this inputmask.
|
|
534
|
+
*/
|
|
535
|
+
definitions?:
|
|
536
|
+
| {
|
|
537
|
+
[key: string]: Definition;
|
|
538
|
+
}
|
|
539
|
+
| undefined;
|
|
540
|
+
/**
|
|
541
|
+
* Enable/disable prefilling of the year.
|
|
542
|
+
* Although you can just over type the proposed value without deleting, many seems to see a problem with the year prediction.
|
|
543
|
+
* This options is to disable this feature.
|
|
544
|
+
*
|
|
545
|
+
* @default true
|
|
546
|
+
*/
|
|
547
|
+
prefillYear?: boolean | undefined;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
export interface Definition {
|
|
551
|
+
validator: string | DefinitionValidator;
|
|
552
|
+
casing?: Casing | undefined;
|
|
553
|
+
cardinality?: number | undefined;
|
|
554
|
+
placeholder?: string | undefined;
|
|
555
|
+
definitionSymbol?: string | undefined;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
interface InsertPosition {
|
|
559
|
+
/**
|
|
560
|
+
* Position to insert.
|
|
561
|
+
*/
|
|
562
|
+
pos: number;
|
|
563
|
+
/**
|
|
564
|
+
* Character to insert.
|
|
565
|
+
*/
|
|
566
|
+
c: string;
|
|
567
|
+
/**
|
|
568
|
+
* @default true
|
|
569
|
+
*/
|
|
570
|
+
fromIsValid?: boolean | undefined;
|
|
571
|
+
/**
|
|
572
|
+
* @default true
|
|
573
|
+
*/
|
|
574
|
+
strict?: boolean | undefined;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
interface CommandObject {
|
|
578
|
+
/**
|
|
579
|
+
* Position to insert.
|
|
580
|
+
*/
|
|
581
|
+
pos?: number | undefined;
|
|
582
|
+
/**
|
|
583
|
+
* Character to insert.
|
|
584
|
+
*/
|
|
585
|
+
c?: string | undefined;
|
|
586
|
+
/**
|
|
587
|
+
* Position of the caret.
|
|
588
|
+
*/
|
|
589
|
+
caret?: number | undefined;
|
|
590
|
+
/**
|
|
591
|
+
* Position(s) to remove.
|
|
592
|
+
*/
|
|
593
|
+
remove?: number | number[] | undefined;
|
|
594
|
+
/**
|
|
595
|
+
* Position(s) to add.
|
|
596
|
+
*/
|
|
597
|
+
insert?: InsertPosition | InsertPosition[] | undefined;
|
|
598
|
+
/**
|
|
599
|
+
* * `true` => refresh validPositions from the complete buffer .
|
|
600
|
+
* * `{ start: , end: }` => refresh from start to end.
|
|
601
|
+
*/
|
|
602
|
+
refreshFromBuffer?: true | { start: number; end: number } | undefined;
|
|
603
|
+
/**
|
|
604
|
+
* Rewrite the maskPos within the isvalid function.
|
|
605
|
+
*/
|
|
606
|
+
rewritePosition?: number | undefined;
|
|
607
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import Inputmask from 'inputmask';
|
|
1
|
+
import { Options as MaskOptions } from './inputmask.types';
|
|
3
2
|
|
|
4
3
|
export type { UseFormRegister, UseFormRegisterReturn } from 'react-hook-form';
|
|
5
4
|
|
|
6
5
|
export type Mask = 'email' | 'cpf' | 'datetime' | 'numeric' | 'currency' | 'decimal' | 'integer' | (string & {}) | (string[] & {}) | null;
|
|
7
|
-
export type Options =
|
|
6
|
+
export type Options = MaskOptions;
|
|
8
7
|
export type Input = HTMLInputElement | HTMLTextAreaElement | HTMLElement | HTMLInputElement | null;
|