-
Notifications
You must be signed in to change notification settings - Fork 417
/
index.d.ts
1825 lines (1632 loc) · 82.2 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Note that ES6 modules cannot directly export class objects.
* This file should be imported using the CommonJS-style:
* import AutoNumeric = require('autonumeric');
*
* Alternatively, if --allowSyntheticDefaultImports or
* --esModuleInterop is turned on, this file can also be
* imported as a default import:
* import AutoNumeric from 'autonumeric';
*
* Refer to the TypeScript documentation at
* https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require
* to understand common workarounds for this limitation of ES6 modules.
*
* @packageDocumentation
*/
/**
* The class constructor function is the exported object from the file
*/
export = AutoNumeric;
import {
AutoNumericEventInitialized,
AutoNumericEventInvalidFormula,
AutoNumericEventRawValueModified,
AutoNumericEventFormatted,
AutoNumericEventValidFormula,
AutoNumericGlobal,
CallbackOptions,
GetValueCallback,
NameValuePair,
Options,
OptionsHandler,
OutputFormatOption,
PredefinedOptions
} from 'autonumeric';
declare global {
interface GlobalEventHandlersEventMap {
/** When an invalid value is corrected. */
"autoNumeric:correctedValue": CustomEvent<null>;
/** When the AutoNumeric element is initialized. */
"autoNumeric:initialized": CustomEvent<AutoNumericEventInitialized>;
/** When the user tries to validate an invalid math expression. */
"autoNumeric:invalidFormula": CustomEvent<AutoNumericEventInvalidFormula>;
/** When an invalid value is entered (ie. when the raw value is out of the min/max range). */
"autoNumeric:invalidValue": CustomEvent<null>;
/** When the `rawValue` is modified. */
"autoNumeric:rawValueModified": CustomEvent<AutoNumericEventRawValueModified>;
/** When all the formatting is done and the formatted string is modified. */
"autoNumeric:formatted": CustomEvent<AutoNumericEventFormatted>;
/** When the `minimumValue` is not respected. */
"autoNumeric:minExceeded": CustomEvent<null>;
/** When the `maximumValue` is not respected. */
"autoNumeric:maxExceeded": CustomEvent<null>;
/** When the user validates a valid math expression. */
"autoNumeric:validFormula": CustomEvent<AutoNumericEventValidFormula>;
}
}
declare class AutoNumeric {
/**
* Enables the AutoNumeric feature for the given element.
*
* The DOM element must be one of the allowed elements. Allowed elements are `<input>`, as well as some
* other text-containing elements such `<div>`. See the documentation for the full list.
*
* When not an `input` element, the element may have the `contenteditable` set. If it does, all
* entered values are formatted according to the given options. Otherwise, the formatted value is
* set once and no further edits are possible.
*
* @param element Either one of the allowed elements, or a CSS selector string for a single element.
* @param initialValue Initial value, when `null`, the value of the DOM element is used.
* @param options Settings for AutoNumeric.
*/
constructor(
element: string | HTMLElement,
initialValue?: string | number | null,
options?: CallbackOptions | string | (CallbackOptions | string)[] | null
);
/**
* Enables the AutoNumeric feature for the given element.
*
* The DOM element must be one of the allowed elements. Allowed elements are `<input>`, as well as some
* other text-containing elements such `<div>`. See the documentation for the full list.
*
* When not an `input` element, the element may have the `contenteditable` set. If it does, all
* entered values are formatted according to the given options. Otherwise, the formatted value is
* set once and no further edits are possible.
*
* @param element Either one of the allowed elements, or a CSS selector string for a single element.
* @param options Settings for AutoNumeric.
*/
constructor(
element: string | HTMLElement,
options: CallbackOptions | (CallbackOptions | string)[]
);
/**
* Enables the AutoNumeric feature for the given elements.
*
* The DOM element must be one of the allowed elements. Allowed elements are `<input>`, as well as some
* other text-containing elements such `<div>`. See the documentation for the full list.
*
* When not an `input` element, the element may have the `contenteditable` set. If it does, all
* entered values are formatted according to the given options. Otherwise, the formatted value is
* set once and no further edits are possible.
* @param elements A list of elements, which may be a CSS selector string.
* @param initialValue Initial value to set. Can be an array to set a different value for each element. When `null`, the
* value of the DOM element is used.
* @param options AutoNumeric options. Can be an array to use a different set of options for each element.
*/
static multiple(
elements: string | HTMLElement[] | { rootElement: HTMLElement; exclude?: HTMLInputElement[] },
initialValue?: number | string | (number | string | null)[] | null,
options?: CallbackOptions | string | (CallbackOptions | string)[] | null
): AutoNumeric[];
/**
* Enables the AutoNumeric feature for the given elements.
*
* The DOM element must be one of the allowed elements. Allowed elements are `<input>`, as well as some
* other text-containing elements such `<div>`. See the documentation for the full list.
*
* When not an `input` element, the element may have the `contenteditable` set. If it does, all
* entered values are formatted according to the given options. Otherwise, the formatted value is
* set once and no further edits are possible.
* @param elements A list of elements, which may be a CSS selector string.
* @param options AutoNumeric options. Can be an array to use a different set of options for each element.
*/
static multiple(
elements: string | HTMLElement[] | { rootElement: HTMLElement; exclude?: HTMLInputElement[] },
options: CallbackOptions | (CallbackOptions | string)[]
): AutoNumeric[];
/**
* Return true in the settings are valid
*/
static areSettingsValid(options: Options): boolean;
/**
* Format the given number with the given options. This returns the formatted value as a string.
* @param domElement An element with a value to format.
* @param options Options to use instead of the default options.
* @return The formatted string.
*/
static format(value: number | string | HTMLElement, ...options: Options[]): string;
/**
* Format the value of the DOM element with the given options and returns the formatted value as a string.
* @param domElement An element with a value to format.
* @param options Options to use instead of the default options.
* @return The formatted string.
*/
static formatAndSet(domElement: HTMLElement, options?: Options | null): string;
/**
* Return the AutoNumeric object that manages the given DOM element
*/
static getAutoNumericElement(domElement: HTMLElement): AutoNumeric;
/**
* Return the default AutoNumeric settings
*/
static getDefaultConfig(): Required<Options>;
/**
* Return all the predefined options in one object
*/
static getPredefinedOptions(): PredefinedOptions;
/**
* Returns the unformatted value following the `outputFormat` setting, from the given DOM element or query selector.
*
* See the non-static `getLocalized` method documentation for more details.
*
* @param value A string to localize, or a DOM element with a value to localize.
* @param forcedOutputFormat Override for the `outputFormat` option.
* @param callback Callback to invoke with the localized value.
* @returns The localized value.
*/
static getLocalized(value: string | HTMLElement, forcedOutputFormat?: OutputFormatOption | null, callback?: ((value: string | number) => void) | null): string | number;
/**
* Returns the unformatted value following the `outputFormat` setting, from the given DOM element or query selector.
*
* See the non-static `getLocalized` method documentation for more details.
*
* @param value A string to localize, or a DOM element with a value to localize.
* @param callback Callback to invoke with the localized value.
* @returns The localized value.
*/
static getLocalized(value: string | HTMLElement, callback: (value: string | number) => void): string | number;
/**
* Return true if the given DOM element has an AutoNumeric object that manages it.
*/
static isManagedByAutoNumeric(domElement: HTMLElement): boolean;
/**
* Unformats and localizes the given formatted string with the given options.
*
* This basically allows to get the localized value without first having to initialize an AutoNumeric object.
*
* The returned value may be either a string or a number, depending on the `outputFormat` option.
*
* @param value A string to unformat and localize, or an input element with a value to unformat and localize.
* @param options Optional options to use instead of the current options of this instance.
* @returns The localized value.
*/
static localize(value: number | string | HTMLElement, options?: Options | null): number | string;
/**
* Unformats and localizes the value of the given element with the given options, then sets the localized
* value on the element.
*
* This basically allows to set the localized value without first having to initialize an AutoNumeric object.
*
* The returned value may be either a string or a number, depending on the `outputFormat` option.
*
* @param value A string to unformat and localize, or an input element with a value to unformat and localize.
* @param options Optional options to use instead of the current options of this instance.
* @returns The localized value.
*/
static localizeAndSet(domElement: HTMLElement, options?: Options | null): number | string;
/**
* Merge the current options with the given list of options.
*
* If a `string` is given, then we try to get the related pre-defined option using that string as its name.
*
* When merging the options, the latest option overwrite any previously set. This allows to fine tune a pre-defined option for instance.
*
* @param options List of options to set.
* @returns The merged options.
*/
static mergeOptions(options: (Options | string)[]): Options;
/**
* Test if the given DOM element, or the element selected by the given selector string is already managed by AutoNumeric
* (if it has been initialized on the current page).
*
* @param domElementOrSelector The DOM element to test. A string is interpreted as a CSS selector that should return one element, if any.
* @returns Whether the element is managed by AutoNumeric.
*/
static test(domElement: HTMLElement | string): boolean;
/**
* Unformats the given formatted string with the given options. This returns a numeric string.
*
* It can also unformat the given DOM element value with the given options and returns the unformatted numeric string.
*
* Note: This does *not* update that element value.
*
* This basically allows to get the unformatted value without first having to initialize an AutoNumeric object.
*
* The returned value might be a string or a number, depending on the `outputFormat` option.
* @param value A number, or a string that represent a JavaScript number, or a DOM element with a value.
* @param options Optional to use instead of the default options.
* @returns The unformatted value.
*/
static unformat(value: string | number | HTMLElement, ...options: Options[]): number | string;
/**
* Unformats the given DOM element value, and set the resulting value back as the element value.
*
* The returned value might be a string or a number, depending on the `outputFormat` option.
* @param domElement DOM element with a value to unformat and set.
* @param options Optional to use instead of the default options.
* @returns The unformatted value.
*/
static unformatAndSet(value: HTMLElement, options?: Options | null): number | string;
/**
* Set the given value on the AutoNumeric object that manages the given DOM element, if any.
* @param element DOM element with a value to unformat and set. Can be a CSS selector string.
* @param newValue The new value to set. Can be `null` when `emptyInputBehavior` is set to `null`.
* @param options A settings object that will override the current settings. Note: the update is done only if the `newValue` is defined.
* @param saveChangeToHistory If set to `true`, then the change is recorded in the history table. Defaults to `true`.
* @returns The AutoNumeric instance of the given element, or `null` if no such instance was found.
*/
static set(element: HTMLElement | string, newValue: number | string | null, options?: CallbackOptions | null, saveChangeToHistory?: boolean): AutoNumeric | null;
/**
* Validate the given option object.
*
* If the options are valid, this function returns nothing, otherwise if the options are invalid, this function throws an error.
*
* This tests if the options are not conflicting and are well formatted.
*
* This function is lenient since it only tests the settings properties ; it ignores any other properties the options object could have.
*
* @param options Options to validate.
* @param shouldExtendDefaultOptions If `true`, then this function will extend the `userOptions` passed by the user, with the default options.
* @param originalOptions The user can pass the original options (and not the one that are generated from the default settings
* and the various usability corrections), in order to add compatibility and conflicts checks.
* @throws If the given options are not valid.
*/
static validate(options: Options, shouldExtendDefaultOptions?: boolean, originalOptions?: Options | null): void;
/**
* Returns the AutoNumeric version number (for debugging purpose).
*
* @returns The current AutoNumeric version.
*/
static version(): string;
/**
* Contains convenience methods to update individual options, and also allows the options to be reset.
*/
readonly options: OptionsHandler;
/**
* Whenever {@link init} is used to initialize other DOM elements, a shared local `init` list of those elements is stored in
* the AutoNumeric instances.
*
* This allows for neat things like modifying all those linked AutoNumeric elements globally, with only one call.
*
* Use this property to access the handler that provides methods to modify all linked elements.
*/
readonly global: AutoNumericGlobal;
/**
* Set the given element value, and format it immediately.
* Additionally, this `set()` method can accept options that will be merged into the current AutoNumeric element, taking precedence over any previous settings.
*
* @example anElement.set('12345.67') // Formats the value
* @example anElement.set(12345.67) // Formats the value
* @example anElement.set(12345.67, { decimalCharacter : ',' }) // Update the settings and formats the value in one go
* @example anElement.northAmerican().set('$12,345.67') // Set an already formatted value (this does not _exactly_ respect the currency symbol/negative placements, but only remove all non-numbers characters, according to the ones given in the settings)
* @example anElement.set(null) // Set the rawValue and element value to `null`
*
* @param newValue The value must be a Number, a numeric string or `null` (if `emptyInputBehavior` is set to `null`)
* @param options A settings object that will override the current settings. Note: the update is done only if the `newValue` is defined.
* @param saveChangeToHistory If set to `true`, then the change is recorded in the history table
* @returns This instance for chaining method calls.
*/
set(
newValue: number | string | null,
options?: CallbackOptions,
saveChangeToHistory?: boolean
): AutoNumeric;
/**
* Set the given value directly as the DOM element value, without formatting it beforehand.
*
* You can also set the value and update the setting in one go (the value will again not be formatted immediately).
* @param value New value to set.
* @param options New options to set.
* @returns This instance for chaining method calls.
*/
setUnformatted(value: number | string | null, options?: CallbackOptions): AutoNumeric;
// The get() function is deprecated and should not be used. Omitted from TS def for that reason.
/**
* Return the current formatted value of the AutoNumeric element as a string.
* @param callback Optional callback that, when given, is called with the value and the AutoNumeric instance.
* @returns The formatted value.
*/
getFormatted(
callback?: GetValueCallback<string> | null
): string;
/**
* Return the element unformatted value as a real JavaScript number.
* @param callback Optional callback that, when given, is called with the value and the AutoNumeric instance.
* @returns The number value.
*/
getNumber(
callback?: GetValueCallback<number | null> | null
): number | null;
/**
* Return the unformatted value as a string.
* This can also return `null` if `rawValue` is null.
* @param callback Optional callback that, when given, is called with the value and the AutoNumeric instance.
* @returns The numerical value.
*/
getNumericString(
callback?: GetValueCallback<string | null> | null
): string | null;
/**
* Returns the unformatted value, but following the `outputFormat` setting, which means the output can either be:
*
* - a string (that could or could not represent a number, ie. "12345,67-"), or
* - a plain number (if the setting `'number'` is used).
*
* By default the returned values are an ISO numeric string "1234.56" or "-1234.56" where the decimal character is a period.
*
* Check the `outputFormat` option definition for more details.
* @param forcedOutputFormat Override for the `outputFormat` option.
* @param callback Optional callback that, when given, is called with the value and the AutoNumeric instance.
* @returns The localized value.
*/
getLocalized(forcedOutputFormat?: OutputFormatOption | null, callback?: GetValueCallback<string | number> | null): string | number;
/**
* Returns the unformatted value, but following the `outputFormat` setting, which means the output can either be:
*
* - a string (that could or could not represent a number, ie. "12345,67-"), or
* - a plain number (if the setting `'number'` is used).
*
* By default the returned values are an ISO numeric string "1234.56" or "-1234.56" where the decimal character is a period.
*
* Check the `outputFormat` option definition for more details.
* @param callback Optional callback that, when given, is called with the value and the AutoNumeric instance.
* @returns The localized value.
*/
getLocalized(callback: GetValueCallback<string | number>): string | number;
/**
* Returns the options object containing all the current autoNumeric settings in effect.
* You can then directly access each option by using its name:
*
* > anElement.getSettings().optionNameAutoCompleted
* @returns The current settings for this instance.
*/
getSettings(): Required<Options>;
/**
* Force each element of the local AutoNumeric element list to reformat its value
* @returns This instance for chaining method calls.
*/
reformat(): AutoNumeric;
/**
* Remove the formatting and keep only the raw unformatted value (as a numericString) in each element of the local AutoNumeric element list
* @returns This instance for chaining method calls.
*/
unformat(): AutoNumeric;
/**
* Remove the formatting and keep only the localized unformatted value in the element, with the option to override the default outputFormat if needed
*
* @param forcedOutputFormat If set to something different from `null`, then this is used as an overriding outputFormat option
* @returns This instance for chaining method calls.
*/
unformatLocalized(forcedOutputFormat?: OutputFormatOption): AutoNumeric;
/**
* Return `true` if *all* the autoNumeric-managed elements are pristine, if their raw value hasn't changed.
*
* By default, this returns `true` if the raw unformatted value is still the same even if the formatted one has changed (due to a configuration update for instance).
*
* @param checkOnlyRawValue If set to `true`, the pristine value is done on the raw unformatted value, not the formatted one. If set to `false`, this also checks that the formatted value hasn't changed.
* @returns If this instance is pristine.
*/
isPristine(checkOnlyRawValue?: boolean): boolean;
/**
* Select the formatted element content, based on the `selectNumberOnly` option
*
* @returns This instance for chaining method calls.
*/
select(): AutoNumeric;
/**
* Select only the numbers in the formatted element content, leaving out the currency symbol, whatever the value of the `selectNumberOnly` option
*
* @returns This instance for chaining method calls.
*/
selectNumber(): AutoNumeric;
/**
* Select only the integer part in the formatted element content, whatever the value of `selectNumberOnly`
*
* @returns This instance for chaining method calls.
*/
selectInteger(): AutoNumeric;
/**
* Select only the decimal part in the formatted element content, whatever the value of `selectNumberOnly`
* Multiple cases are possible:
*
* - +1.234,57suffixText
* - € +1.234,57suffixText
* - +€ 1.234,57suffixText
* - € 1.234,57+suffixText
* - 1.234,57+ €suffixText
* - 1.234,57 €+suffixText
* - +1.234,57 €suffixText
* @returns This instance for chaining method calls.
*/
selectDecimal(): AutoNumeric;
/**
* Reset the element value either to the empty string '', or the currency sign, depending on the `emptyInputBehavior` option value.
* If you set the `forceClearAll` argument to `true`, then the `emptyInputBehavior` option is overridden
* and the whole input is cleared, including any currency sign.
*
* @param forceClearAll `true` to clear the the entire input, including the currency sign.
* @returns This instance for chaining method calls.
*/
clear(forceClearAll?: boolean): AutoNumeric;
/**
* Updates the AutoNumeric settings, and immediately format the element accordingly.
* @param options New options to set. When multiple options are specified, later options override previous options.
* @returns This instance for chaining method calls.
*/
update(...options: CallbackOptions[]): AutoNumeric;
/**
* Remove the autoNumeric data and event listeners from the element, but keep the element content intact.
*
* This also clears the value from sessionStorage (or cookie, depending on browser supports).
*
* Note: this does not remove the formatting.
*/
remove(): void;
/**
* Remove the autoNumeric data and event listeners from the element, and reset its value to the empty string.
* This also clears the value from sessionStorage (or cookie, depending on browser supports).
*/
wipe(): void;
/**
* Remove the autoNumeric data and event listeners from the element, and delete the DOM element altogether
*/
nuke(): void;
/**
* Return the DOM element reference of the autoNumeric-managed element. The exact type depends
* on the element that on which AutoNumeric was initialized - AutoNumeric supports input elements
* as well as other content editable elements such as div elements.
*/
node(): HTMLElement;
/**
* Return the DOM element reference of the parent node of the AutoNumeric managed element
*
* @returns The parent of the AutoNumeric element.
*/
parent(): HTMLElement;
/**
* Detach the current AutoNumeric element from the shared local `init` list.
*
* This means any changes made on that local shared list will not be transmitted to that element anymore.
*
* Note: The user can provide another AutoNumeric element, and detach this one instead of the current one.
*
* @param otherAnElement Element to detach.
* @returns This instance for chaining method calls.
*/
detach(otherAnElement?: AutoNumeric | null): AutoNumeric;
/**
* Attach the given AutoNumeric element to the shared local `init` list.
*
* When doing that, by default the DOM content is left untouched.
*
* The user can force a reformat with the new shared list options by passing a second argument to `true`.
*
* @param otherAnElement Element to attach.
* @param reFormat Whether to reformat the value after the element was attached. Defaults to `true`.
* @returns This instance for chaining method calls.
*/
attach(otherAnElement: AutoNumeric, reFormat?: boolean): AutoNumeric;
/**
* Use the current AutoNumeric element settings to initialize the DOM element(s) given as a parameter.
*
* Doing so will *link* the AutoNumeric elements together since they will share the same local AutoNumeric element list.
*
* (cf. prototype pattern : https://en.wikipedia.org/wiki/Prototype_pattern)
*
* You can `init` either a single DOM element (in that case an AutoNumeric object will be returned), or an array of DOM elements or a string that will be used as a CSS selector. In the latter cases, an array of AutoNumeric objects will then be returned (or an empty array if nothing gets selected by the CSS selector).
*
* Use case : Once you have an AutoNumeric element already setup correctly with the right options, you can use it as many times you want to initialize as many other DOM elements as needed.
*
* Note: this works only on elements that can be managed by autoNumeric.
*
* @param domElement A single element to initialize.
* @param attached If set to `false`, then the newly generated AutoNumeric element will not share the same local element list.
* @returns The initialized AutoNumeric instance.
*/
init(domElement: HTMLElement, attached?: boolean): AutoNumeric;
/**
* Use the current AutoNumeric element settings to initialize the DOM element(s) given as a parameter.
*
* Doing so will *link* the AutoNumeric elements together since they will share the same local AutoNumeric element list.
*
* (cf. prototype pattern : https://en.wikipedia.org/wiki/Prototype_pattern)
*
* You can `init` either a single DOM element (in that case an AutoNumeric object will be returned), or an array of DOM elements or a string that will be used as a CSS selector. In the latter cases, an array of AutoNumeric objects will then be returned (or an empty array if nothing gets selected by the CSS selector).
*
* Use case : Once you have an AutoNumeric element already setup correctly with the right options, you can use it as many times you want to initialize as many other DOM elements as needed.
*
* Note: this works only on elements that can be managed by autoNumeric.
*
* @param domElement A list of elements, or a string representing a CSS selector.
* @param attached If set to `false`, then the newly generated AutoNumeric element will not share the same local element list.
* @returns The initialized AutoNumeric instances.
*/
init(domElement: HTMLElement[] | string, attached?: boolean): AutoNumeric[];
/**
* Return a reference to the parent <form> element if it exists, otherwise return `null`.
*
* If the parent form element as already been found, this directly return a reference to it.
*
* However, you can force AutoNumeric to search again for its reference by passing `true` as a parameter to this method.
*
* This method updates the `this.parentForm` attribute.
*
* In either case, whenever a new parent form is set for the current AutoNumeric element, we make sure to update the anCount and anFormHandler attributes on both the old form and the new one (for instance in case the user moved the input elements with `appendChild()` since AutoNumeric cannot not detect that).
*
* @param forceSearch Whether to force a new search for the parent `<form>` element, discarding any previously found one. Defaults to `false`.
*
* @returns The form element containing this AutoNumeric element, if any.
*/
form(forceSearch?: boolean): HTMLFormElement | null;
/**
* Return a string in standard URL-encoded notation with the form input values being unformatted.
*
* This string can be used as a query for instance.
*
* @returns The formatted string.
*/
formNumericString(): string;
/**
* Return a string in standard URL-encoded notation with the form input values being formatted.
*
* @returns The formatted string.
*/
formFormatted(): string;
/**
* Return a string in standard URL-encoded notation with the form input values, with localized values.
*
* The default output format can be overridden by passing the option as a parameter.
*
* @param forcedOutputFormat If set to something different from `null`, then this is used as an override for the `outputFormat` option
* @returns The localized string.
*/
formLocalized(forcedOutputFormat?: OutputFormatOption | null): string;
/**
* Return an array containing an object for each form <input> element. The name of each pair is the name of the DOM elements.
* The value is is stringified numeric value of each AutoNumeric input.
* @returns The numerical values.
*/
formArrayNumericString(): NameValuePair<number | string>[];
/**
* Return an array containing an object for each form <input> element. The name of each pair is the name of the DOM elements.
* The value is is formatted value of each AutoNumeric input.
* @returns The formatted values.
*/
formArrayFormatted(): NameValuePair<string>[];
/**
* Return an array containing an object for each form <input> element. The name of each pair is the name of the DOM elements.
*
* The value is is localized value of each AutoNumeric input.
*
* Values might be a string or a number, depending on the `outputFormat` option.
*
* @param forcedOutputFormat If set to something different from `null`, then this is used as an override for the `outputFormat` option
* @returns The localized values.
*/
formArrayLocalized(forcedOutputFormat?: OutputFormatOption | null): NameValuePair<number | string>[];
/**
* Return an array containing an object for each form <input> element, stringified as a JSON string.
* The name of each pair is the name of the DOM elements. The value is is localized value of each AutoNumeric input.
* @returns The numerical values.
*/
formJsonNumericString(): string;
/**
* Return an array containing an object for each form <input> element, stringified as a JSON string.
* The name of each pair is the name of the DOM elements. The value is is formatted value of each AutoNumeric input.
* @returns The formatted values.
*/
formJsonFormatted(): string;
/**
* Return an array containing an object for each form <input> element, stringified as a JSON string.
* The name of each pair is the name of the DOM elements. The value is is localized value of each AutoNumeric input.
* @param forcedOutputFormat If set to something different from `null`, then this is used as an override for the `outputFormat` option.
* @returns The localized values.
*/
formJsonLocalized(forcedOutputFormat?: OutputFormatOption | null): string;
/**
* Unformat all the autoNumeric-managed elements that are a child of the parent <form> element of this DOM element, to numeric strings
*
* @returns This instance for chaining method calls.
*/
formUnformat(): AutoNumeric;
/**
* Unformat all the autoNumeric-managed elements that are a child of the parent `<form>` element of
* this DOM element, to localized strings
*
* @returns This instance for chaining method calls.
*/
formUnformatLocalized(): AutoNumeric;
/**
* Reformat all the autoNumeric-managed elements that are a child of the parent <form> element of this DOM element
*
* @returns This instance for chaining method calls.
*/
formReformat(): AutoNumeric;
/**
* Generate an array of numeric strings from the `<input>` elements, and pass it to the given callback.
* Under the hood, the array is generated via a call to `formArrayNumericString()`.
*
* @param callback Callback to invoke with the values.
* @returns This instance for chaining method calls.
*/
formSubmitArrayNumericString(callback: (pairs: NameValuePair<number | string>[]) => void): AutoNumeric;
/**
* Generate an array of the current formatted values from the `<input>` elements, and pass it to the given callback.
* Under the hood, the array is generated via a call to `formArrayFormatted()`.
*
* @param callback Callback to invoke with the values.
* @returns This instance for chaining method calls.
*/
formSubmitArrayFormatted(callback: (pairs: NameValuePair<string>[]) => void): AutoNumeric;
/**
* Generate an array of localized strings from the `<input>` elements, and pass it to the given callback.
*
* Under the hood, the array is generated via a call to `formArrayLocalized()`.
*
* Values might be a string or a number, depending on the `outputFormat` option.
* @param callback Callback to invoke with the values.
* @param forcedOutputFormat If set to something different from `null`, then this is used as an override for the `outputFormat` option.
* @returns This instance for chaining method calls.
*/
formSubmitArrayLocalized(callback: (pairs: NameValuePair<number | string>[]) => void, forcedOutputFormat?: OutputFormatOption | null): AutoNumeric;
/**
* Generate a JSON string with the numeric strings values from the `<input>` elements, and pass it to the given callback.
* Under the hood, the array is generated via a call to `formJsonNumericString()`.
*
* @param callback Callback to invoke with the values.
* @returns This instance for chaining method calls.
*/
formSubmitJsonNumericString(callback: (values: string) => void): AutoNumeric;
/**
* Generate a JSON string with the current formatted values from the `<input>` elements, and pass it to the given callback.
* Under the hood, the array is generated via a call to `formJsonFormatted()`.
*
* @param callback Callback to invoke with the values.
* @returns This instance for chaining method calls.
*/
formSubmitJsonFormatted(callback: (values: string) => void): AutoNumeric;
/**
* Generate a JSON string with the localized strings values from the `<input>` elements, and pass it to the given callback.
* Under the hood, the array is generated via a call to `formJsonLocalized()`.
*
* @param callback Callback to invoke with the values.
* @param forcedOutputFormat If set to something different from `null`, then this is used as an override for the `outputFormat` option.
* @returns This instance for chaining method calls.
*/
formSubmitJsonLocalized(callback: (values: string) => void, forcedOutputFormat?: null | string): AutoNumeric;
/**
* Update the settings to use the Brazilian pre-defined language options.
* Those pre-defined options can be overridden by passing an option object as a parameter.
*
* @param optionOverride Optional options to override the pre-defined options.
* @returns This instance for chaining method calls.
*/
brazilian(optionOverride?: CallbackOptions | null): AutoNumeric;
/**
* Update the settings to use the British pre-defined language options.
* Those pre-defined options can be overridden by passing an option object as a parameter.
*
* @param optionOverride Optional options to override the pre-defined options.
* @returns This instance for chaining method calls.
*/
british(optionOverride?: CallbackOptions | null): AutoNumeric;
/**
* Update the settings to use the Chinese pre-defined language options.
* Those pre-defined options can be overridden by passing an option object as a parameter.
*
* @param optionOverride Optional options to override the pre-defined options.
* @returns This instance for chaining method calls.
*/
chinese(optionOverride?: CallbackOptions | null): AutoNumeric;
/**
* Update the settings to use the French pre-defined language options.
* Those pre-defined options can be overridden by passing an option object as a parameter.
*
* @param optionOverride Optional options to override the pre-defined options.
* @returns This instance for chaining method calls.
*/
french(optionOverride?: CallbackOptions | null): AutoNumeric;
/**
* Update the settings to use the Japanese pre-defined language options.
* Those pre-defined options can be overridden by passing an option object as a parameter.
*
* @param optionOverride Optional options to override the pre-defined options.
* @returns This instance for chaining method calls.
*/
japanese(optionOverride?: CallbackOptions | null): AutoNumeric;
/**
* Update the settings to use the North American pre-defined language options.
* Those pre-defined options can be overridden by passing an option object as a parameter.
*
* @param optionOverride Optional options to override the pre-defined options.
* @returns This instance for chaining method calls.
*/
northAmerican(optionOverride?: CallbackOptions | null): AutoNumeric;
/**
* Update the settings to use the Spanish pre-defined language options.
* Those pre-defined options can be overridden by passing an option object as a parameter.
*
* @param optionOverride Optional options to override the pre-defined options.
* @returns This instance for chaining method calls.
*/
spanish(optionOverride?: CallbackOptions | null): AutoNumeric;
/**
* Update the settings to use the Swiss pre-defined language options.
* Those pre-defined options can be overridden by passing an option object as a parameter.
*
* @param optionOverride Optional options to override the pre-defined options.
* @returns This instance for chaining method calls.
*/
swiss(optionOverride?: CallbackOptions | null): AutoNumeric;
}
/**
* Exposes the types used in that definitions file
*/
declare namespace AutoNumeric {
/**
* Callback that can optionally be passed to the various `get*` methods. Receives
* the value as well as the current AutoNumeric instance.
* @typeParam T Type of the value returned by the get method.
*/
export type GetValueCallback<T> = (value: T, instance: AutoNumeric) => void;
export type OutputFormatOption =
| "string"
| "number"
| "."
| "-."
| ","
| "-,"
| ".-"
| ",-"
| null;
export type CaretPositionOption =
| "start"
| "end"
| "decimalLeft"
| "decimalRight"
| "doNoForceCaretPosition";
export type CurrencySymbolPlacementOption = "p" | "s";
export type EmptyInputBehaviorOption =
| "null"
| "focus"
| "press"
| "always"
| "min"
| "max"
| "zero"
| number
| string /* representing a number */;
export type LeadingZeroOption = "allow" | "deny" | "keep";
export type NegativePositiveSignPlacementOption =
| "p"
| "s"
| "l"
| "r"
| null;
export type OnInvalidPasteOption =
| "error"
| "ignore"
| "clamp"
| "truncate"
| "replace";
export type OverrideMinMaxLimitsOption =
| "ceiling"
| "floor"
| "ignore"
| "invalid"
| null;
export type RoundingMethodOption =
| "S"
| "A"
| "s"
| "a"
| "B"
| "U"
| "D"
| "C"
| "F"
| "N05"
| "CHF"
| "U05"
| "D05";
export type DigitalGroupSpacingOption =
| "2"
| "2t"
| "2s"
| "3"
| "4"
export type NegativeBracketsTypeOnBlurOption =
| "(,)"
| "[,]"
| "<,>"
| "{,}"
| "〈,〉"
| "「,」"
| "⸤,⸥"
| "⟦,⟧"
| "‹,›"
| "«,»";
export type SerializeSpacesOption = "+" | "%20";
export type ValueOrCallback<T> = T | ((instance: AutoNumeric, key: string) => T);
export type OptionsHandler = {
[K in keyof Options]-?: (value: Required<Options[K]>) => AutoNumeric
} & {
/**
* Reset any options set previously, by overwriting them with the default settings
* @returns This AutoNumeric instance for chaining method calls.
*/
reset: () => AutoNumeric;
};
/**
* A pair with a name and a string value.
* @typeParam T Type of the value.
*/
export interface NameValuePair<T> {
/** The name of this pair. */
name: string;
/** The value of this pair. */
value: T;
}
export interface Options {
/**
* Allow padding the decimal places with zeros.
* @default true
*/
allowDecimalPadding?: boolean | number | string | "floats";
/**
* Determine where should be positioned the caret on focus
* @default null
*/
caretPositionOnFocus?: CaretPositionOption | null;
/**
* Defines if the decimal character or decimal character alternative should be accepted when there is already a
* decimal character shown in the element.
*
* If set to `true`, any decimal character input will be accepted and will subsequently modify the decimal character
* position, as well as the `rawValue`.
*
* If set to `false`, the decimal character and its alternative key will be dropped as before. This is the default setting.
* @default false
*/
alwaysAllowDecimalCharacter?: boolean;
/**
* Determine if a local list of AutoNumeric objects must be kept when initializing the elements and others
* @default true
*/
createLocalList?: boolean;