use-mask-input 1.0.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/example/App.example.d.ts +3 -0
  2. package/dist/{useMaskInput.test.d.ts → example/index.d.ts} +0 -0
  3. package/dist/index.js +1 -2
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.modern.js +1 -2
  6. package/dist/index.modern.js.map +1 -1
  7. package/dist/useMaskInput.d.ts +3 -3
  8. package/node_modules/inputmask/README.md +109 -79
  9. package/node_modules/inputmask/bundle.js +6 -5
  10. package/node_modules/inputmask/dist/inputmask.es6.js +5 -0
  11. package/node_modules/inputmask/dist/inputmask.js +2892 -2608
  12. package/node_modules/inputmask/dist/inputmask.min.js +3 -3
  13. package/node_modules/inputmask/dist/jquery.inputmask.js +2829 -2534
  14. package/node_modules/inputmask/dist/jquery.inputmask.min.js +3 -3
  15. package/node_modules/inputmask/lib/bindings/inputmask.es6.js +5 -0
  16. package/node_modules/inputmask/lib/canUseDOM.js +7 -0
  17. package/node_modules/inputmask/lib/defaults.js +101 -0
  18. package/node_modules/inputmask/lib/definitions.js +13 -0
  19. package/node_modules/inputmask/lib/dependencyLibs/data.js +8 -0
  20. package/node_modules/inputmask/lib/dependencyLibs/events.js +199 -0
  21. package/node_modules/inputmask/lib/dependencyLibs/extend.js +58 -0
  22. package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.jquery.js +4 -3
  23. package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.js +12 -343
  24. package/node_modules/inputmask/lib/environment.js +9 -0
  25. package/node_modules/inputmask/lib/escapeRegex.js +4 -0
  26. package/node_modules/inputmask/lib/eventhandlers.js +513 -0
  27. package/node_modules/inputmask/lib/eventruler.js +124 -0
  28. package/node_modules/inputmask/lib/extensions/inputmask.date.extensions.js +552 -385
  29. package/node_modules/inputmask/lib/extensions/inputmask.extensions.js +116 -97
  30. package/node_modules/inputmask/lib/extensions/inputmask.numeric.extensions.js +594 -565
  31. package/node_modules/inputmask/lib/global/window.js +2 -6
  32. package/node_modules/inputmask/lib/inputHandling.js +252 -0
  33. package/node_modules/inputmask/lib/inputmask.js +129 -126
  34. package/node_modules/inputmask/lib/inputmaskElement.js +26 -20
  35. package/node_modules/inputmask/lib/jquery.inputmask.js +3 -1
  36. package/node_modules/inputmask/lib/keycode.json +6 -1
  37. package/node_modules/inputmask/lib/mask-lexer.js +467 -0
  38. package/node_modules/inputmask/lib/mask.js +244 -0
  39. package/node_modules/inputmask/lib/masktoken.js +13 -0
  40. package/node_modules/inputmask/lib/polyfills/Array.includes.js +48 -0
  41. package/node_modules/inputmask/lib/polyfills/Object.getPrototypeOf.js +7 -0
  42. package/node_modules/inputmask/lib/positioning.js +348 -0
  43. package/node_modules/inputmask/lib/validation-tests.js +597 -0
  44. package/node_modules/inputmask/lib/validation.js +664 -0
  45. package/node_modules/inputmask/package.json +41 -71
  46. package/package.json +40 -43
  47. package/node_modules/inputmask/CHANGELOG.md +0 -714
  48. package/node_modules/inputmask/index.js +0 -1
  49. package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.jqlite.js +0 -170
  50. package/node_modules/inputmask/lib/maskScope.js +0 -2498
  51. package/node_modules/inputmask/lib/maskset.js +0 -466
@@ -4,418 +4,585 @@
4
4
  Copyright (c) Robin Herbots
5
5
  Licensed under the MIT license
6
6
  */
7
- var Inputmask = require("../inputmask"), $ = Inputmask.dependencyLib,
8
- keyCode = require("../keycode"),
9
- //supported codes for formatting
10
- //http://blog.stevenlevithan.com/archives/date-time-format
11
- //https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings?view=netframework-4.7
12
- formatCode = { //regex, valueSetter, type, displayformatter
13
- d: ["[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", Date.prototype.getDate], //Day of the month as digits; no leading zero for single-digit days.
14
- dd: ["0[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", function () {
15
- return pad(Date.prototype.getDate.call(this), 2);
16
- }], //Day of the month as digits; leading zero for single-digit days.
17
- ddd: [""], //Day of the week as a three-letter abbreviation.
18
- dddd: [""], //Day of the week as its full name.
19
- m: ["[1-9]|1[012]", Date.prototype.setMonth, "month", function () {
20
- return Date.prototype.getMonth.call(this) + 1;
21
- }], //Month as digits; no leading zero for single-digit months.
22
- mm: ["0[1-9]|1[012]", Date.prototype.setMonth, "month", function () {
23
- return pad(Date.prototype.getMonth.call(this) + 1, 2);
24
- }], //Month as digits; leading zero for single-digit months.
25
- mmm: [""], //Month as a three-letter abbreviation.
26
- mmmm: [""], //Month as its full name.
27
- yy: ["[0-9]{2}", Date.prototype.setFullYear, "year", function () {
28
- return pad(Date.prototype.getFullYear.call(this), 2);
29
- }], //Year as last two digits; leading zero for years less than 10.
30
- yyyy: ["[0-9]{4}", Date.prototype.setFullYear, "year", function () {
31
- return pad(Date.prototype.getFullYear.call(this), 4);
32
- }],
33
- h: ["[1-9]|1[0-2]", Date.prototype.setHours, "hours", Date.prototype.getHours], //Hours; no leading zero for single-digit hours (12-hour clock).
34
- hh: ["0[1-9]|1[0-2]", Date.prototype.setHours, "hours", function () {
35
- return pad(Date.prototype.getHours.call(this), 2);
36
- }], //Hours; leading zero for single-digit hours (12-hour clock).
37
- hx: [function (x) {
38
- return `[0-9]{${x}}`;
39
- }, Date.prototype.setHours, "hours", function (x) {
40
- return Date.prototype.getHours;
41
- }], //Hours; no limit; set maximum digits
42
- H: ["1?[0-9]|2[0-3]", Date.prototype.setHours, "hours", Date.prototype.getHours], //Hours; no leading zero for single-digit hours (24-hour clock).
43
- HH: ["0[0-9]|1[0-9]|2[0-3]", Date.prototype.setHours, "hours", function () {
44
- return pad(Date.prototype.getHours.call(this), 2);
45
- }], //Hours; leading zero for single-digit hours (24-hour clock).
46
- Hx: [function (x) {
47
- return `[0-9]{${x}}`;
48
- }, Date.prototype.setHours, "hours", function (x) {
49
- return function () {
50
- return pad(Date.prototype.getHours.call(this), x);
51
- };
52
- }], //Hours; no limit; set maximum digits
53
- M: ["[1-5]?[0-9]", Date.prototype.setMinutes, "minutes", Date.prototype.getMinutes], //Minutes; no leading zero for single-digit minutes. Uppercase M unlike CF timeFormat's m to avoid conflict with months.
54
- MM: ["0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]", Date.prototype.setMinutes, "minutes", function () {
55
- return pad(Date.prototype.getMinutes.call(this), 2);
56
- }], //Minutes; leading zero for single-digit minutes. Uppercase MM unlike CF timeFormat's mm to avoid conflict with months.
57
- s: ["[1-5]?[0-9]", Date.prototype.setSeconds, "seconds", Date.prototype.getSeconds], //Seconds; no leading zero for single-digit seconds.
58
- ss: ["0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]", Date.prototype.setSeconds, "seconds", function () {
59
- return pad(Date.prototype.getSeconds.call(this), 2);
60
- }], //Seconds; leading zero for single-digit seconds.
61
- l: ["[0-9]{3}", Date.prototype.setMilliseconds, "milliseconds", function () {
62
- return pad(Date.prototype.getMilliseconds.call(this), 3);
63
- }], //Milliseconds. 3 digits.
64
- L: ["[0-9]{2}", Date.prototype.setMilliseconds, "milliseconds", function () {
65
- return pad(Date.prototype.getMilliseconds.call(this), 2);
66
- }], //Milliseconds. 2 digits.
67
- t: ["[ap]"], //Lowercase, single-character time marker string: a or p.
68
- tt: ["[ap]m"], //two-character time marker string: am or pm.
69
- T: ["[AP]"], //single-character time marker string: A or P.
70
- TT: ["[AP]M"], //two-character time marker string: AM or PM.
71
- Z: [""], //US timezone abbreviation, e.g. EST or MDT. With non-US timezones or in the Opera browser, the GMT/UTC offset is returned, e.g. GMT-0500
72
- o: [""], //GMT/UTC timezone offset, e.g. -0500 or +0230.
73
- S: [""] //The date's ordinal suffix (st, nd, rd, or th).
74
- },
75
- formatAlias = {
76
- isoDate: "yyyy-mm-dd", //2007-06-09
77
- isoTime: "HH:MM:ss", //17:46:21
78
- isoDateTime: "yyyy-mm-dd'T'HH:MM:ss", //2007-06-09T17:46:21
79
- isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'" //2007-06-09T22:46:21Z
80
- };
7
+ import Inputmask from "../inputmask";
8
+ import keyCode from "../keycode.json";
9
+ import escapeRegex from "../escapeRegex";
10
+ import {seekNext} from "../positioning";
11
+ import {getMaskTemplate} from "../validation-tests";
12
+
13
+ const $ = Inputmask.dependencyLib;
14
+
15
+ class DateObject {
16
+ constructor(mask, format, opts) {
17
+ this.mask = mask;
18
+ this.format = format;
19
+ this.opts = opts;
20
+ this._date = new Date(1, 0, 1);
21
+ this.initDateObject(mask, this.opts);
22
+ }
23
+
24
+ get date() {
25
+ if (this._date === undefined) {
26
+ this._date = new Date(1, 0, 1);
27
+ this.initDateObject(undefined, this.opts);
28
+ }
29
+ return this._date;
30
+ }
31
+
32
+ initDateObject(mask, opts) {
33
+ let match;
34
+ getTokenizer(opts).lastIndex = 0;
35
+ while ((match = getTokenizer(opts).exec(this.format))) {
36
+ let dynMatches = new RegExp("\\d+$").exec(match[0]),
37
+ fcode = dynMatches ? (match[0][0] + "x") : match[0],
38
+ value;
39
+ if (mask !== undefined) {
40
+ if (dynMatches) {
41
+ let lastIndex = getTokenizer(opts).lastIndex,
42
+ tokanMatch = getTokenMatch(match.index, opts);
43
+ getTokenizer(opts).lastIndex = lastIndex;
44
+ value = mask.slice(0, mask.indexOf(tokanMatch.nextMatch[0]));
45
+ } else {
46
+ value = mask.slice(0, fcode.length);
47
+ }
48
+ mask = mask.slice(value.length);
49
+ }
50
+
51
+ if (Object.prototype.hasOwnProperty.call(formatCode, fcode)) {
52
+ this.setValue(this, value, fcode, formatCode[fcode][2], formatCode[fcode][1]);
53
+ }
54
+ }
55
+ }
56
+
57
+ setValue(dateObj, value, fcode, targetProp, dateOperation) {
58
+ if (value !== undefined) {
59
+ dateObj[targetProp] = targetProp === "ampm" ? value : value.replace(/[^0-9]/g, "0");
60
+ dateObj["raw" + targetProp] = value.replace(/\s/g, "_");
61
+ }
62
+ if (dateOperation !== undefined) {
63
+ let datavalue = dateObj[targetProp];
64
+ if ((targetProp === "day" && parseInt(datavalue) === 29) || (targetProp === "month" && parseInt(datavalue) === 2)) {
65
+ if (parseInt(dateObj.day) === 29 && parseInt(dateObj.month) === 2 && (dateObj.year === "" || dateObj.year === undefined)) {
66
+ //set temporary leap year in dateObj
67
+ dateObj._date.setFullYear(2012, 1, 29);
68
+ }
69
+ }
70
+ if (targetProp === "day") {
71
+ useDateObject = true;
72
+ if (parseInt(datavalue) === 0)
73
+ datavalue = 1;
74
+ }
75
+ if (targetProp === "month")
76
+ useDateObject = true;
77
+ if (targetProp === "year") {
78
+ useDateObject = true;
79
+ if (datavalue.length < 4)
80
+ datavalue = pad(datavalue, 4, true);
81
+ }
82
+ if (datavalue !== "" && !isNaN(datavalue)) dateOperation.call(dateObj._date, datavalue);
83
+ if (targetProp === "ampm")
84
+ dateOperation.call(dateObj._date, datavalue);
85
+ }
86
+ }
87
+
88
+ reset() {
89
+ this._date = new Date(1, 0, 1);
90
+ }
91
+
92
+ reInit() {
93
+ this._date = undefined;
94
+ this.date;
95
+ }
96
+ }
97
+
98
+ let currentYear = new Date().getFullYear(),
99
+ useDateObject = false,
100
+ //supported codes for formatting
101
+ //http://blog.stevenlevithan.com/archives/date-time-format
102
+ //https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings?view=netframework-4.7
103
+ formatCode = { //regex, valueSetter, type, displayformatter
104
+ d: ["[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", Date.prototype.getDate], //Day of the month as digits; no leading zero for single-digit days.
105
+ dd: ["0[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", function () {
106
+ return pad(Date.prototype.getDate.call(this), 2);
107
+ }], //Day of the month as digits; leading zero for single-digit days.
108
+ ddd: [""], //Day of the week as a three-letter abbreviation.
109
+ dddd: [""], //Day of the week as its full name.
110
+ m: ["[1-9]|1[012]", function (val) {
111
+ let mval = val ? parseInt(val) : 0;
112
+ if (mval > 0) mval--;
113
+ return Date.prototype.setMonth.call(this, mval);
114
+ }, "month", function () {
115
+ return Date.prototype.getMonth.call(this) + 1;
116
+ }], //Month as digits; no leading zero for single-digit months.
117
+ mm: ["0[1-9]|1[012]", function (val) {
118
+ let mval = val ? parseInt(val) : 0;
119
+ if (mval > 0) mval--;
120
+ return Date.prototype.setMonth.call(this, mval);
121
+ }, "month", function () {
122
+ return pad(Date.prototype.getMonth.call(this) + 1, 2);
123
+ }], //Month as digits; leading zero for single-digit months.
124
+ mmm: [""], //Month as a three-letter abbreviation.
125
+ mmmm: [""], //Month as its full name.
126
+ yy: ["[0-9]{2}", Date.prototype.setFullYear, "year", function () {
127
+ return pad(Date.prototype.getFullYear.call(this), 2);
128
+ }], //Year as last two digits; leading zero for years less than 10.
129
+ yyyy: ["[0-9]{4}", Date.prototype.setFullYear, "year", function () {
130
+ return pad(Date.prototype.getFullYear.call(this), 4);
131
+ }],
132
+ h: ["[1-9]|1[0-2]", Date.prototype.setHours, "hours", Date.prototype.getHours], //Hours; no leading zero for single-digit hours (12-hour clock).
133
+ hh: ["0[1-9]|1[0-2]", Date.prototype.setHours, "hours", function () {
134
+ return pad(Date.prototype.getHours.call(this), 2);
135
+ }], //Hours; leading zero for single-digit hours (12-hour clock).
136
+ hx: [function (x) {
137
+ return `[0-9]{${x}}`;
138
+ }, Date.prototype.setHours, "hours", function (x) {
139
+ return Date.prototype.getHours;
140
+ }], //Hours; no limit; set maximum digits
141
+ H: ["1?[0-9]|2[0-3]", Date.prototype.setHours, "hours", Date.prototype.getHours], //Hours; no leading zero for single-digit hours (24-hour clock).
142
+ HH: ["0[0-9]|1[0-9]|2[0-3]", Date.prototype.setHours, "hours", function () {
143
+ return pad(Date.prototype.getHours.call(this), 2);
144
+ }], //Hours; leading zero for single-digit hours (24-hour clock).
145
+ Hx: [function (x) {
146
+ return `[0-9]{${x}}`;
147
+ }, Date.prototype.setHours, "hours", function (x) {
148
+ return function () {
149
+ return pad(Date.prototype.getHours.call(this), x);
150
+ };
151
+ }], //Hours; no limit; set maximum digits
152
+ M: ["[1-5]?[0-9]", Date.prototype.setMinutes, "minutes", Date.prototype.getMinutes], //Minutes; no leading zero for single-digit minutes. Uppercase M unlike CF timeFormat's m to avoid conflict with months.
153
+ MM: ["0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]", Date.prototype.setMinutes, "minutes", function () {
154
+ return pad(Date.prototype.getMinutes.call(this), 2);
155
+ }], //Minutes; leading zero for single-digit minutes. Uppercase MM unlike CF timeFormat's mm to avoid conflict with months.
156
+ s: ["[1-5]?[0-9]", Date.prototype.setSeconds, "seconds", Date.prototype.getSeconds], //Seconds; no leading zero for single-digit seconds.
157
+ ss: ["0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]", Date.prototype.setSeconds, "seconds", function () {
158
+ return pad(Date.prototype.getSeconds.call(this), 2);
159
+ }], //Seconds; leading zero for single-digit seconds.
160
+ l: ["[0-9]{3}", Date.prototype.setMilliseconds, "milliseconds", function () {
161
+ return pad(Date.prototype.getMilliseconds.call(this), 3);
162
+ }], //Milliseconds. 3 digits.
163
+ L: ["[0-9]{2}", Date.prototype.setMilliseconds, "milliseconds", function () {
164
+ return pad(Date.prototype.getMilliseconds.call(this), 2);
165
+ }], //Milliseconds. 2 digits.
166
+ t: ["[ap]", setAMPM, "ampm", getAMPM, 1], //Lowercase, single-character time marker string: a or p.
167
+ tt: ["[ap]m", setAMPM, "ampm", getAMPM, 2], //two-character time marker string: am or pm.
168
+ T: ["[AP]", setAMPM, "ampm", getAMPM, 1], //single-character time marker string: A or P.
169
+ TT: ["[AP]M", setAMPM, "ampm", getAMPM, 2], //two-character time marker string: AM or PM.
170
+ Z: [".*", undefined, "Z", getTimeZoneAbbreviated], //US timezone abbreviation, e.g. EST or MDT. With non-US timezones or in the Opera browser, the GMT/UTC offset is returned, e.g. GMT-0500
171
+ o: [""], //GMT/UTC timezone offset, e.g. -0500 or +0230.
172
+ S: [""] //The date's ordinal suffix (st, nd, rd, or th).
173
+ },
174
+ formatAlias = {
175
+ isoDate: "yyyy-mm-dd", //2007-06-09
176
+ isoTime: "HH:MM:ss", //17:46:21
177
+ isoDateTime: "yyyy-mm-dd'T'HH:MM:ss", //2007-06-09T17:46:21
178
+ isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'" //2007-06-09T22:46:21Z
179
+ };
180
+
181
+ function setAMPM(value) {
182
+ const hours = this.getHours();
183
+ if (value.toLowerCase().includes("p")) {
184
+ this.setHours(hours + 12);
185
+ // console.log("setAMPM + 12");
186
+ } else if (value.toLowerCase().includes("a") && hours >= 12) {
187
+ this.setHours(hours - 12);
188
+ }
189
+ }
190
+
191
+ function getAMPM() {
192
+ let date = this,
193
+ hours = date.getHours();
194
+ hours = hours || 12;
195
+ return hours >= 12 ? "PM" : "AM";
196
+ }
197
+
198
+ function getTimeZoneAbbreviated() {
199
+ //not perfect, but ok for now
200
+ let date = this, {1: tz} = date.toString().match(/\((.+)\)/);
201
+ if (tz.includes(" ")) {
202
+ tz = tz.replace("-", " ").toUpperCase();
203
+ tz = tz.split(" ").map(([first]) => first).join("");
204
+ }
205
+ return tz;
206
+ }
81
207
 
82
208
  function formatcode(match) {
83
- var dynMatches = new RegExp("\\d+$").exec(match[0]);
84
- if (dynMatches && dynMatches[0] !== undefined) {
85
- var fcode = formatCode[match[0][0] + "x"].slice("");
86
- fcode[0] = fcode[0](dynMatches[0]);
87
- fcode[3] = fcode[3](dynMatches[0]);
88
-
89
- return fcode;
90
- } else if (formatCode[match[0]]) {
91
- return formatCode[match[0]];
92
- }
209
+ var dynMatches = new RegExp("\\d+$").exec(match[0]);
210
+ if (dynMatches && dynMatches[0] !== undefined) {
211
+ var fcode = formatCode[match[0][0] + "x"].slice("");
212
+ fcode[0] = fcode[0](dynMatches[0]);
213
+ fcode[3] = fcode[3](dynMatches[0]);
214
+
215
+ return fcode;
216
+ } else if (formatCode[match[0]]) {
217
+ return formatCode[match[0]];
218
+ }
93
219
  }
94
220
 
95
221
  function getTokenizer(opts) {
96
- if (!opts.tokenizer) {
97
- var tokens = [], dyntokens = [];
98
- for (var ndx in formatCode) {
99
- if (/\.*x$/.test(ndx)) {
100
- var dynToken = ndx[0] + "\\d+";
101
- if (dyntokens.indexOf(dynToken) === -1) {
102
- dyntokens.push(dynToken);
103
- }
104
- } else if (tokens.indexOf(ndx[0]) === -1) {
105
- tokens.push(ndx[0]);
106
- }
107
- }
108
- opts.tokenizer = "(" + (dyntokens.length > 0 ? dyntokens.join("|") + "|" : "") + tokens.join("+|") + ")+?|.";
109
- opts.tokenizer = new RegExp(opts.tokenizer, "g");
110
- }
111
-
112
- return opts.tokenizer;
222
+ if (!opts.tokenizer) {
223
+ var tokens = [], dyntokens = [];
224
+ for (var ndx in formatCode) {
225
+ if (/\.*x$/.test(ndx)) {
226
+ var dynToken = ndx[0] + "\\d+";
227
+ if (dyntokens.indexOf(dynToken) === -1) {
228
+ dyntokens.push(dynToken);
229
+ }
230
+ } else if (tokens.indexOf(ndx[0]) === -1) {
231
+ tokens.push(ndx[0]);
232
+ }
233
+ }
234
+ opts.tokenizer = "(" + (dyntokens.length > 0 ? dyntokens.join("|") + "|" : "") + tokens.join("+|") + ")+?|.";
235
+ opts.tokenizer = new RegExp(opts.tokenizer, "g");
236
+ }
237
+
238
+ return opts.tokenizer;
113
239
  }
114
240
 
115
- function isValidDate(dateParts, currentResult) {
116
- return !isFinite(dateParts.rawday)
117
- || (dateParts.day == "29" && !isFinite(dateParts.rawyear))
118
- || new Date(dateParts.date.getFullYear(), isFinite(dateParts.rawmonth) ? dateParts.month : dateParts.date.getMonth() + 1, 0).getDate() >= dateParts.day
119
- ? currentResult
120
- : false; //take corrective action if possible
241
+ function prefillYear(dateParts, currentResult, opts) {
242
+ if (dateParts.year !== dateParts.rawyear) {
243
+ var crrntyear = currentYear.toString(),
244
+ enteredPart = dateParts.rawyear.replace(/[^0-9]/g, ""),
245
+ currentYearPart = crrntyear.slice(0, enteredPart.length),
246
+ currentYearNextPart = crrntyear.slice(enteredPart.length);
247
+ if (enteredPart.length === 2 && enteredPart === currentYearPart) {
248
+ const entryCurrentYear = new Date(currentYear, dateParts.month - 1, dateParts.day);
249
+ if (dateParts.day == entryCurrentYear.getDate() && (!opts.max || opts.max.date.getTime() >= entryCurrentYear.getTime())) {
250
+ //update dateParts
251
+ dateParts.date.setFullYear(currentYear);
252
+ dateParts.year = crrntyear;
253
+ //update result
254
+ currentResult.insert = [{
255
+ pos: currentResult.pos + 1,
256
+ c: currentYearNextPart[0]
257
+ }, {
258
+ pos: currentResult.pos + 2,
259
+ c: currentYearNextPart[1]
260
+ }];
261
+ }
262
+ }
263
+ }
264
+
265
+ return currentResult;
121
266
  }
122
267
 
123
- function isDateInRange(dateParts, opts) {
124
- var result = true;
125
- if (opts.min) {
126
- if (dateParts["rawyear"]) {
127
- var rawYear = dateParts["rawyear"].replace(/[^0-9]/g, ""),
128
- minYear = opts.min.year.substr(0, rawYear.length);
129
- result = minYear <= rawYear;
130
- }
131
- if (dateParts["year"] === dateParts["rawyear"]) {
132
- if (opts.min.date.getTime() === opts.min.date.getTime()) {
133
- result = opts.min.date.getTime() <= dateParts.date.getTime();
134
- }
135
- }
136
- }
137
-
138
- if (result && opts.max && opts.max.date.getTime() === opts.max.date.getTime()) {
139
- result = opts.max.date.getTime() >= dateParts.date.getTime();
140
- }
141
- return result;
268
+ function isValidDate(dateParts, currentResult, opts) {
269
+ if (!useDateObject) return true;
270
+ if (dateParts.rawday === undefined
271
+ || (!isFinite(dateParts.rawday) && new Date(dateParts.date.getFullYear(), isFinite(dateParts.rawmonth) ? dateParts.month : dateParts.date.getMonth() + 1, 0).getDate() >= dateParts.day)
272
+ || (dateParts.day == "29" && (!isFinite(dateParts.rawyear) || dateParts.rawyear === undefined || dateParts.rawyear === ""))
273
+ || new Date(dateParts.date.getFullYear(), isFinite(dateParts.rawmonth) ? dateParts.month : dateParts.date.getMonth() + 1, 0).getDate() >= dateParts.day) {
274
+ return currentResult;
275
+ } else { //take corrective action if possible
276
+ if (dateParts.day == "29") {
277
+ var tokenMatch = getTokenMatch(currentResult.pos, opts);
278
+ if (tokenMatch.targetMatch[0] === "yyyy" && currentResult.pos - tokenMatch.targetMatchIndex === 2) {
279
+ currentResult.remove = currentResult.pos + 1;
280
+ return currentResult;
281
+ }
282
+ } else if (dateParts.month == "02" && dateParts.day == "30" && currentResult.c !== undefined) {
283
+ dateParts.day = "03";
284
+ dateParts.date.setDate(3);
285
+ dateParts.date.setMonth(1);
286
+ currentResult.insert = [{pos: currentResult.pos, c: "0"}, {pos: currentResult.pos + 1, c: currentResult.c}];
287
+ currentResult.caret = seekNext.call(this, currentResult.pos + 1);
288
+ return currentResult;
289
+ }
290
+ return false;
291
+ }
292
+ }
293
+
294
+ function isDateInRange(dateParts, result, opts, maskset, fromCheckval) {
295
+ if (!result) return result;
296
+ if (result && opts.min) {
297
+ if (/*useDateObject && (dateParts["year"] === undefined || dateParts["yearSet"]) && */opts.min.date.getTime() === opts.min.date.getTime()) {
298
+ let match;
299
+ dateParts.reset();
300
+ getTokenizer(opts).lastIndex = 0;
301
+ while ((match = getTokenizer(opts).exec(opts.inputFormat))) {
302
+ var fcode;
303
+ if ((fcode = formatcode(match))) {
304
+ if (fcode[3]) {
305
+ var setFn = fcode[1];
306
+ var current = dateParts[fcode[2]],
307
+ minVal = opts.min[fcode[2]],
308
+ maxVal = opts.max ? opts.max[fcode[2]] : minVal,
309
+ curVal = [];
310
+
311
+ let forceCurrentValue = false;
312
+ for (let i = 0; i < minVal.length; i++) {
313
+ if (maskset.validPositions[i + match.index] === undefined && !forceCurrentValue) {
314
+ curVal[i] = minVal[i];
315
+ // ADD +1 to whoile
316
+ if (fcode[2] === "year" && current.length - 1 == i && minVal != maxVal)
317
+ curVal = (parseInt(curVal.join("")) + 1).toString().split("");
318
+ if (fcode[2] === "ampm" && minVal != maxVal && opts.min.date.getTime() > dateParts.date.getTime())
319
+ curVal[i] = maxVal[i];
320
+ } else {
321
+ curVal[i] = current[i];
322
+ forceCurrentValue = forceCurrentValue || current[i] > minVal[i];
323
+ }
324
+ }
325
+
326
+ setFn.call(dateParts._date, curVal.join(""));
327
+ }
328
+ }
329
+ }
330
+
331
+ result = opts.min.date.getTime() <= dateParts.date.getTime();
332
+ dateParts.reInit();
333
+ }
334
+ }
335
+
336
+ if (result && opts.max) {
337
+ if (opts.max.date.getTime() === opts.max.date.getTime()) {
338
+ result = opts.max.date.getTime() >= dateParts.date.getTime();
339
+ }
340
+ }
341
+ return result;
142
342
  }
143
343
 
144
344
  //parse the given format and return a mask pattern
145
345
  //when a dateObjValue is passed a datestring in the requested format is returned
146
346
  function parse(format, dateObjValue, opts, raw) {
147
- //parse format to regex string
148
- var mask = "", match, fcode;
149
- getTokenizer(opts).lastIndex = 0;
150
- while ((match = getTokenizer(opts).exec(format))) {
151
- if (dateObjValue === undefined) {
152
- if ((fcode = formatcode(match))) {
153
- mask += "(" + fcode[0] + ")";
154
- } else {
155
- switch (match[0]) {
156
- case "[":
157
- mask += "(";
158
- break;
159
- case "]":
160
- mask += ")?";
161
- break;
162
- default:
163
- mask += Inputmask.escapeRegex(match[0]);
164
- }
165
- }
166
- } else {
167
- if ((fcode = formatcode(match))) {
168
- if (raw !== true && fcode[3]) {
169
- var getFn = fcode[3];
170
- mask += getFn.call(dateObjValue.date);
171
- } else if (fcode[2]) {
172
- mask += dateObjValue["raw" + fcode[2]];
173
- } else {
174
- mask += match[0];
175
- }
176
- } else {
177
- mask += match[0];
178
- }
179
- }
180
- }
181
- return mask;
347
+ //parse format to regex string
348
+ var mask = "", match, fcode;
349
+ getTokenizer(opts).lastIndex = 0;
350
+ while ((match = getTokenizer(opts).exec(format))) {
351
+ if (dateObjValue === undefined) {
352
+ if ((fcode = formatcode(match))) {
353
+ mask += "(" + fcode[0] + ")";
354
+ } else {
355
+ switch (match[0]) {
356
+ case "[":
357
+ mask += "(";
358
+ break;
359
+ case "]":
360
+ mask += ")?";
361
+ break;
362
+ default:
363
+ mask += escapeRegex(match[0]);
364
+ }
365
+ }
366
+ } else {
367
+ if ((fcode = formatcode(match))) {
368
+ if (raw !== true && fcode[3]) {
369
+ var getFn = fcode[3];
370
+ mask += getFn.call(dateObjValue.date);
371
+ } else if (fcode[2]) {
372
+ mask += dateObjValue["raw" + fcode[2]];
373
+ } else {
374
+ mask += match[0];
375
+ }
376
+ } else {
377
+ mask += match[0];
378
+ }
379
+ }
380
+ }
381
+ return mask;
182
382
  }
183
383
 
184
384
  //padding function
185
- function pad(val, len) {
186
- val = String(val);
187
- len = len || 2;
188
- while (val.length < len) val = "0" + val;
189
- return val;
385
+ function pad(val, len, right) {
386
+ val = String(val);
387
+ len = len || 2;
388
+ while (val.length < len) val = right ? val + "0" : "0" + val;
389
+ return val;
190
390
  }
191
391
 
192
- function analyseMask(maskString, format, opts) {
193
- var dateObj = {"date": new Date(1, 0, 1)}, targetProp, mask = maskString, match, dateOperation;
194
-
195
- function extendProperty(value) {
196
- var correctedValue = value.replace(/[^0-9]/g, "0");
197
- // if (correctedValue != value) { //only do correction on incomplete values
198
- // //determine best validation match
199
- // var enteredPart = value.replace(/[^0-9]/g, ""),
200
- // enteredPartIndex = value.indexOf(enteredPart),
201
- // minPart = (opts.min && opts.min[targetProp] || value).slice(enteredPartIndex, enteredPartIndex + enteredPart.length),
202
- // maxPart = (opts.max && opts.max[targetProp] || value).slice(enteredPartIndex, enteredPartIndex + enteredPart.length),
203
- // correctedPart = enteredPart < minPart ? minPart : (enteredPart > maxPart ? maxPart : correctedValue.slice(enteredPartIndex, enteredPartIndex + enteredPart.length));
204
- // correctedValue = correctedValue.split("");
205
- // correctedValue.splice(enteredPartIndex, 1, correctedPart);
206
- // correctedValue = correctedValue.join("");
207
- // }
208
- return correctedValue;
209
- }
210
-
211
- function setValue(dateObj, value, opts) {
212
- dateObj[targetProp] = extendProperty(value);
213
- dateObj["raw" + targetProp] = value;
214
-
215
- if (dateOperation !== undefined) {
216
- dateOperation.call(dateObj.date, targetProp == "month" ? parseInt(dateObj[targetProp]) - 1 : dateObj[targetProp]);
217
- }
218
- }
219
-
220
- if (typeof mask === "string") {
221
- getTokenizer(opts).lastIndex = 0;
222
- while ((match = getTokenizer(opts).exec(format))) {
223
- var value = mask.slice(0, match[0].length);
224
- if (formatCode.hasOwnProperty(match[0])) {
225
- // targetValidator = formatCode[match[0]][0];
226
- targetProp = formatCode[match[0]][2];
227
- dateOperation = formatCode[match[0]][1];
228
- setValue(dateObj, value, opts);
229
- }
230
- mask = mask.slice(value.length);
231
- }
232
-
233
- return dateObj;
234
- } else if (mask && typeof mask === "object" && mask.hasOwnProperty("date")) {
235
- return mask;
236
- }
237
- return undefined;
392
+ function analyseMask(mask, format, opts) {
393
+ if (typeof mask === "string") {
394
+ return new DateObject(mask, format, opts);
395
+ } else if (mask && typeof mask === "object" && Object.prototype.hasOwnProperty.call(mask, "date")) {
396
+ return mask;
397
+ }
398
+ return undefined;
238
399
  }
239
400
 
240
401
  function importDate(dateObj, opts) {
241
- var match, date = "";
242
-
243
- getTokenizer(opts).lastIndex = 0;
244
- while ((match = getTokenizer(opts).exec(opts.inputFormat))) {
245
- if (match[0].charAt(0) === "d") {
246
- date += pad(dateObj.getDate(), match[0].length);
247
- } else if (match[0].charAt(0) === "m") {
248
- date += pad((dateObj.getMonth() + 1), match[0].length);
249
- } else if (match[0] === "yyyy") {
250
- date += dateObj.getFullYear().toString();
251
- } else if (match[0].charAt(0) === "y") {
252
- date += pad(dateObj.getYear(), match[0].length);
253
- }
254
- }
255
-
256
- return date;
402
+ return parse(opts.inputFormat, {date: dateObj}, opts);
257
403
  }
258
404
 
259
405
  function getTokenMatch(pos, opts) {
260
- var calcPos = 0, targetMatch, match, matchLength = 0;
261
- getTokenizer(opts).lastIndex = 0;
262
- while ((match = getTokenizer(opts).exec(opts.inputFormat))) {
263
- var dynMatches = new RegExp("\\d+$").exec(match[0]);
264
- matchLength = dynMatches ? parseInt(dynMatches[0]) : match[0].length;
265
- calcPos += matchLength;
266
- if (calcPos >= pos) {
267
- targetMatch = match;
268
- match = getTokenizer(opts).exec(opts.inputFormat);
269
- break;
270
- }
271
- }
272
- return {
273
- targetMatchIndex: calcPos - matchLength,
274
- nextMatch: match,
275
- targetMatch: targetMatch
276
- };
406
+ var calcPos = 0, targetMatch, match, matchLength = 0;
407
+ getTokenizer(opts).lastIndex = 0;
408
+ while ((match = getTokenizer(opts).exec(opts.inputFormat))) {
409
+ var dynMatches = new RegExp("\\d+$").exec(match[0]);
410
+ matchLength = dynMatches ? parseInt(dynMatches[0]) : match[0].length;
411
+ calcPos += matchLength;
412
+ if (calcPos >= pos + 1) {
413
+ targetMatch = match;
414
+ match = getTokenizer(opts).exec(opts.inputFormat);
415
+ break;
416
+ }
417
+ }
418
+ return {
419
+ targetMatchIndex: calcPos - matchLength,
420
+ nextMatch: match,
421
+ targetMatch: targetMatch
422
+ };
277
423
  }
278
424
 
279
425
 
280
426
  Inputmask.extendAliases({
281
- "datetime": {
282
- mask: function (opts) {
283
- //do not allow numeric input in datetime alias
284
- opts.numericInput = false;
285
-
286
- //localize
287
- formatCode.S = opts.i18n.ordinalSuffix.join("|");
288
-
289
- opts.inputFormat = formatAlias[opts.inputFormat] || opts.inputFormat; //resolve possible formatAlias
290
- opts.displayFormat = formatAlias[opts.displayFormat] || opts.displayFormat || opts.inputFormat; //resolve possible formatAlias
291
- opts.outputFormat = formatAlias[opts.outputFormat] || opts.outputFormat || opts.inputFormat; //resolve possible formatAlias
292
- opts.placeholder = opts.placeholder !== "" ? opts.placeholder : opts.inputFormat.replace(/[[\]]/, "");
293
- opts.regex = parse(opts.inputFormat, undefined, opts);
294
- opts.min = analyseMask(opts.min, opts.inputFormat, opts);
295
- opts.max = analyseMask(opts.max, opts.inputFormat, opts);
296
- return null; //migrate to regex mask
297
- },
298
- placeholder: "", //set default as none (~ auto); when a custom placeholder is passed it will be used
299
- inputFormat: "isoDateTime", //format used to input the date
300
- displayFormat: undefined, //visual format when the input looses focus
301
- outputFormat: undefined, //unmasking format
302
- min: null, //needs to be in the same format as the inputfornat
303
- max: null, //needs to be in the same format as the inputfornat,
304
- skipOptionalPartCharacter: "",
305
- // Internationalization strings
306
- i18n: {
307
- dayNames: [
308
- "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
309
- "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"
310
- ],
311
- monthNames: [
312
- "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
313
- "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
314
- ],
315
- ordinalSuffix: ["st", "nd", "rd", "th"]
316
- },
317
- preValidation: function (buffer, pos, c, isSelection, opts, maskset, caretPos, strict) {
318
- if (strict) return true;
319
- if (isNaN(c) && buffer[pos] !== c) {
320
- var tokenMatch = getTokenMatch(pos, opts);
321
- if (tokenMatch.nextMatch && tokenMatch.nextMatch[0] === c && tokenMatch.targetMatch[0].length > 1) {
322
- var validator = formatCode[tokenMatch.targetMatch[0]][0];
323
- if (new RegExp(validator).test("0" + buffer[pos - 1])) {
324
- buffer[pos] = buffer[pos - 1];
325
- buffer[pos - 1] = "0";
326
- return {
327
- fuzzy: true,
328
- buffer: buffer,
329
- refreshFromBuffer: {start: pos - 1, end: pos + 1},
330
- pos: pos + 1
331
- };
332
- }
333
- }
334
- }
335
- return true;
336
- },
337
- postValidation: function (buffer, pos, c, currentResult, opts, maskset, strict) {
338
- if (strict) return true;
339
- var tokenMatch, validator;
340
- if (currentResult === false) {
341
- tokenMatch = getTokenMatch(pos + 1, opts);
342
- if (tokenMatch.targetMatch && tokenMatch.targetMatchIndex === pos && tokenMatch.targetMatch[0].length > 1 && formatCode[tokenMatch.targetMatch[0]] !== undefined) {
343
- validator = formatCode[tokenMatch.targetMatch[0]][0];
344
- if (new RegExp(validator).test("0" + c)) {
345
- return {
346
- insert: [{pos: pos, c: "0"}, {pos: pos + 1, c: c}],
347
- pos: pos + 1
348
- };
349
- }
350
- }
351
- return currentResult;
352
- }
353
-
354
- if (currentResult.fuzzy) {
355
- buffer = currentResult.buffer;
356
- pos = currentResult.pos;
357
- }
358
-
359
- //full validate target
360
- tokenMatch = getTokenMatch(pos, opts);
361
- if (tokenMatch.targetMatch && tokenMatch.targetMatch[0] && formatCode[tokenMatch.targetMatch[0]] !== undefined) {
362
- validator = formatCode[tokenMatch.targetMatch[0]][0];
363
- var part = buffer.slice(tokenMatch.targetMatchIndex, tokenMatch.targetMatchIndex + tokenMatch.targetMatch[0].length);
364
- if (new RegExp(validator).test(part.join("")) === false && tokenMatch.targetMatch[0].length === 2 && maskset.validPositions[tokenMatch.targetMatchIndex] && maskset.validPositions[tokenMatch.targetMatchIndex + 1]) {
365
- maskset.validPositions[tokenMatch.targetMatchIndex + 1].input = "0";
366
- }
367
- }
368
-
369
- var result = currentResult, dateParts = analyseMask(buffer.join(""), opts.inputFormat, opts);
370
- if (result && dateParts.date.getTime() === dateParts.date.getTime()) { //check for a valid date ~ an invalid date returns NaN which isn't equal
371
- result = isValidDate(dateParts, result);
372
- result = result && isDateInRange(dateParts, opts);
373
- }
374
-
375
- if (pos && result && currentResult.pos !== pos) {
376
- return {
377
- buffer: parse(opts.inputFormat, dateParts, opts).split(""),
378
- refreshFromBuffer: {start: pos, end: currentResult.pos}
379
- };
380
- }
381
-
382
- return result;
383
- }
384
- ,
385
- onKeyDown: function (e, buffer, caretPos, opts) {
386
- var input = this;
387
- if (e.ctrlKey && e.keyCode === keyCode.RIGHT) {
388
- input.inputmask._valueSet(importDate(new Date(), opts));
389
- $(input).trigger("setvalue");
390
- }
391
- }
392
- ,
393
- onUnMask: function (maskedValue, unmaskedValue, opts) {
394
- return unmaskedValue ? parse(opts.outputFormat, analyseMask(maskedValue, opts.inputFormat, opts), opts, true) : unmaskedValue;
395
- }
396
- ,
397
- casing: function (elem, test, pos, validPositions) {
398
- if (test.nativeDef.indexOf("[ap]") == 0) return elem.toLowerCase();
399
- if (test.nativeDef.indexOf("[AP]") == 0) return elem.toUpperCase();
400
- return elem;
401
- }
402
- ,
403
- onBeforeMask: function (initialValue, opts) {
404
- if (Object.prototype.toString.call(initialValue) === "[object Date]") {
405
- initialValue = importDate(initialValue, opts);
406
- }
407
-
408
- return initialValue;
409
- }
410
- ,
411
- insertMode: false,
412
- shiftPositions:
413
- false,
414
- keepStatic:
415
- false,
416
- inputmode:
417
- "numeric"
418
- }
419
- });
427
+ "datetime": {
428
+ mask: function (opts) {
429
+ //do not allow numeric input in datetime alias
430
+ opts.numericInput = false;
431
+
432
+ //localize
433
+ formatCode.S = opts.i18n.ordinalSuffix.join("|");
420
434
 
421
- module.exports = Inputmask;
435
+ opts.inputFormat = formatAlias[opts.inputFormat] || opts.inputFormat; //resolve possible formatAlias
436
+ opts.displayFormat = formatAlias[opts.displayFormat] || opts.displayFormat || opts.inputFormat; //resolve possible formatAlias
437
+ opts.outputFormat = formatAlias[opts.outputFormat] || opts.outputFormat || opts.inputFormat; //resolve possible formatAlias
438
+ opts.placeholder = opts.placeholder !== "" ? opts.placeholder : opts.inputFormat.replace(/[[\]]/, "");
439
+ opts.regex = parse(opts.inputFormat, undefined, opts);
440
+ opts.min = analyseMask(opts.min, opts.inputFormat, opts);
441
+ opts.max = analyseMask(opts.max, opts.inputFormat, opts);
442
+ return null; //migrate to regex mask
443
+ },
444
+ placeholder: "", //set default as none (~ auto); when a custom placeholder is passed it will be used
445
+ inputFormat: "isoDateTime", //format used to input the date
446
+ displayFormat: null, //visual format when the input looses focus
447
+ outputFormat: null, //unmasking format
448
+ min: null, //needs to be in the same format as the inputfornat
449
+ max: null, //needs to be in the same format as the inputfornat,
450
+ skipOptionalPartCharacter: "",
451
+ // Internationalization strings
452
+ i18n: {
453
+ dayNames: [
454
+ "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
455
+ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"
456
+ ],
457
+ monthNames: [
458
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
459
+ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
460
+ ],
461
+ ordinalSuffix: ["st", "nd", "rd", "th"]
462
+ },
463
+ preValidation: function (buffer, pos, c, isSelection, opts, maskset, caretPos, strict) {
464
+ if (strict) return true;
465
+ if (isNaN(c) && buffer[pos] !== c) {
466
+ var tokenMatch = getTokenMatch(pos, opts);
467
+ if (tokenMatch.nextMatch && tokenMatch.nextMatch[0] === c && tokenMatch.targetMatch[0].length > 1) {
468
+ var validator = formatCode[tokenMatch.targetMatch[0]][0];
469
+ if (new RegExp(validator).test("0" + buffer[pos - 1])) {
470
+ buffer[pos] = buffer[pos - 1];
471
+ buffer[pos - 1] = "0";
472
+ return {
473
+ fuzzy: true,
474
+ buffer: buffer,
475
+ refreshFromBuffer: {start: pos - 1, end: pos + 1},
476
+ pos: pos + 1
477
+ };
478
+ }
479
+ }
480
+ }
481
+ return true;
482
+ },
483
+ postValidation: function (buffer, pos, c, currentResult, opts, maskset, strict, fromCheckval) {
484
+ const inputmask = this;
485
+
486
+ if (strict) return true;
487
+ var tokenMatch, validator;
488
+ if (currentResult === false) { //try some shifting
489
+ tokenMatch = getTokenMatch(pos + 1, opts);
490
+ if (tokenMatch.targetMatch && tokenMatch.targetMatchIndex === pos && tokenMatch.targetMatch[0].length > 1 && formatCode[tokenMatch.targetMatch[0]] !== undefined) {
491
+ validator = formatCode[tokenMatch.targetMatch[0]][0];
492
+ } else {
493
+ tokenMatch = getTokenMatch(pos + 2, opts);
494
+ if (tokenMatch.targetMatch && tokenMatch.targetMatchIndex === pos + 1 && tokenMatch.targetMatch[0].length > 1 && formatCode[tokenMatch.targetMatch[0]] !== undefined) {
495
+ validator = formatCode[tokenMatch.targetMatch[0]][0];
496
+ }
497
+ }
498
+ if (validator !== undefined) {
499
+ if (maskset.validPositions[pos + 1] !== undefined && new RegExp(validator).test(c + "0")) {
500
+ buffer[pos] = c;
501
+ buffer[pos + 1] = "0";
502
+ currentResult = {
503
+ //insert: [{pos: pos, c: "0"}, {pos: pos + 1, c: c}],
504
+ pos: pos + 2, //this will triggeer a refreshfrombuffer
505
+ caret: pos
506
+ };
507
+ } else if (new RegExp(validator).test("0" + c)) {
508
+ buffer[pos] = "0";
509
+ buffer[pos + 1] = c;
510
+ currentResult = {
511
+ //insert: [{pos: pos, c: "0"}, {pos: pos + 1, c: c}],
512
+ pos: pos + 2 //this will triggeer a refreshfrombuffer
513
+ };
514
+ }
515
+ }
516
+
517
+ if (currentResult === false) return currentResult;
518
+ }
519
+
520
+ if (currentResult.fuzzy) {
521
+ buffer = currentResult.buffer;
522
+ pos = currentResult.pos;
523
+ }
524
+
525
+ //full validate target
526
+ tokenMatch = getTokenMatch(pos, opts);
527
+ if (tokenMatch.targetMatch && tokenMatch.targetMatch[0] && formatCode[tokenMatch.targetMatch[0]] !== undefined) {
528
+ let fcode = formatCode[tokenMatch.targetMatch[0]];
529
+ validator = fcode[0];
530
+ var part = buffer.slice(tokenMatch.targetMatchIndex, tokenMatch.targetMatchIndex + tokenMatch.targetMatch[0].length);
531
+ if (new RegExp(validator).test(part.join("")) === false && tokenMatch.targetMatch[0].length === 2 && maskset.validPositions[tokenMatch.targetMatchIndex] && maskset.validPositions[tokenMatch.targetMatchIndex + 1]) {
532
+ maskset.validPositions[tokenMatch.targetMatchIndex + 1].input = "0";
533
+ }
534
+ if (fcode[2] == "year") {
535
+ var _buffer = getMaskTemplate.call(inputmask, false, 1, undefined, true);
536
+ for (let i = pos + 1; i < buffer.length; i++) {
537
+ buffer[i] = _buffer[i];
538
+ delete maskset.validPositions[i];
539
+ }
540
+ }
541
+ }
542
+
543
+ var result = currentResult, dateParts = analyseMask(buffer.join(""), opts.inputFormat, opts);
544
+ if (result && dateParts.date.getTime() === dateParts.date.getTime()) { //check for a valid date ~ an invalid date returns NaN which isn't equal
545
+ if (opts.prefillYear) result = prefillYear(dateParts, result, opts);
546
+ result = isValidDate.call(inputmask, dateParts, result, opts);
547
+ result = isDateInRange(dateParts, result, opts, maskset, fromCheckval);
548
+ }
549
+
550
+ if (pos !== undefined && result && currentResult.pos !== pos) {
551
+ return {
552
+ buffer: parse(opts.inputFormat, dateParts, opts).split(""),
553
+ refreshFromBuffer: {start: pos, end: currentResult.pos},
554
+ pos: currentResult.caret || currentResult.pos //correct caret position
555
+ };
556
+ }
557
+
558
+ return result;
559
+ },
560
+ onKeyDown: function (e, buffer, caretPos, opts) {
561
+ var input = this;
562
+ if (e.ctrlKey && e.keyCode === keyCode.RIGHT) {
563
+ input.inputmask._valueSet(importDate(new Date(), opts));
564
+ $(input).trigger("setvalue");
565
+ }
566
+ },
567
+ onUnMask: function (maskedValue, unmaskedValue, opts) {
568
+ return unmaskedValue ? parse(opts.outputFormat, analyseMask(maskedValue, opts.inputFormat, opts), opts, true) : unmaskedValue;
569
+ },
570
+ casing: function (elem, test, pos, validPositions) {
571
+ if (test.nativeDef.indexOf("[ap]") == 0) return elem.toLowerCase();
572
+ if (test.nativeDef.indexOf("[AP]") == 0) return elem.toUpperCase();
573
+ return elem;
574
+ },
575
+ onBeforeMask: function (initialValue, opts) {
576
+ if (Object.prototype.toString.call(initialValue) === "[object Date]") {
577
+ initialValue = importDate(initialValue, opts);
578
+ }
579
+
580
+ return initialValue;
581
+ },
582
+ insertMode: false,
583
+ shiftPositions: false,
584
+ keepStatic: false,
585
+ inputmode: "numeric",
586
+ prefillYear: true //Allows to disable prefill for datetime year.
587
+ }
588
+ });