use-mask-input 3.0.6 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +13 -19
  2. package/dist/index.cjs +191 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.ts +34 -3
  5. package/dist/index.js +184 -1
  6. package/dist/index.js.map +1 -1
  7. package/package.json +49 -48
  8. package/src/index.tsx +3 -2
  9. package/src/types.ts +6 -0
  10. package/src/useMaskInput.ts +12 -9
  11. package/src/utils.spec.ts +14 -0
  12. package/src/utils.ts +23 -0
  13. package/src/withHookFormMask.ts +8 -17
  14. package/src/withMask.ts +5 -6
  15. package/dist/example/App.example.d.ts +0 -3
  16. package/dist/example/index.d.ts +0 -1
  17. package/dist/index.modern.js +0 -2
  18. package/dist/index.modern.js.map +0 -1
  19. package/dist/index.umd.js +0 -2
  20. package/dist/index.umd.js.map +0 -1
  21. package/dist/useMaskInput.d.ts +0 -9
  22. package/dist/withHookFormMask.d.ts +0 -16
  23. package/dist/withMask.d.ts +0 -3
  24. package/node_modules/inputmask/LICENSE.txt +0 -7
  25. package/node_modules/inputmask/README.md +0 -1279
  26. package/node_modules/inputmask/bundle.js +0 -6
  27. package/node_modules/inputmask/dist/bindings/inputmask.binding.js +0 -26
  28. package/node_modules/inputmask/dist/inputmask.es6.js +0 -5
  29. package/node_modules/inputmask/dist/inputmask.js +0 -3031
  30. package/node_modules/inputmask/dist/inputmask.min.js +0 -8
  31. package/node_modules/inputmask/dist/jquery.inputmask.js +0 -2985
  32. package/node_modules/inputmask/dist/jquery.inputmask.min.js +0 -8
  33. package/node_modules/inputmask/lib/bindings/inputmask.binding.js +0 -26
  34. package/node_modules/inputmask/lib/bindings/inputmask.es6.js +0 -5
  35. package/node_modules/inputmask/lib/canUseDOM.js +0 -7
  36. package/node_modules/inputmask/lib/defaults.js +0 -101
  37. package/node_modules/inputmask/lib/definitions.js +0 -13
  38. package/node_modules/inputmask/lib/dependencyLibs/data.js +0 -8
  39. package/node_modules/inputmask/lib/dependencyLibs/events.js +0 -199
  40. package/node_modules/inputmask/lib/dependencyLibs/extend.js +0 -58
  41. package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.jquery.js +0 -13
  42. package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.js +0 -41
  43. package/node_modules/inputmask/lib/environment.js +0 -9
  44. package/node_modules/inputmask/lib/escapeRegex.js +0 -4
  45. package/node_modules/inputmask/lib/eventhandlers.js +0 -513
  46. package/node_modules/inputmask/lib/eventruler.js +0 -124
  47. package/node_modules/inputmask/lib/extensions/inputmask.date.extensions.js +0 -588
  48. package/node_modules/inputmask/lib/extensions/inputmask.extensions.js +0 -133
  49. package/node_modules/inputmask/lib/extensions/inputmask.numeric.extensions.js +0 -631
  50. package/node_modules/inputmask/lib/global/window.js +0 -3
  51. package/node_modules/inputmask/lib/inputHandling.js +0 -252
  52. package/node_modules/inputmask/lib/inputmask.js +0 -355
  53. package/node_modules/inputmask/lib/inputmaskElement.js +0 -33
  54. package/node_modules/inputmask/lib/jquery.inputmask.js +0 -81
  55. package/node_modules/inputmask/lib/keycode.json +0 -25
  56. package/node_modules/inputmask/lib/mask-lexer.js +0 -467
  57. package/node_modules/inputmask/lib/mask.js +0 -244
  58. package/node_modules/inputmask/lib/masktoken.js +0 -13
  59. package/node_modules/inputmask/lib/polyfills/Array.includes.js +0 -48
  60. package/node_modules/inputmask/lib/polyfills/Object.getPrototypeOf.js +0 -7
  61. package/node_modules/inputmask/lib/positioning.js +0 -348
  62. package/node_modules/inputmask/lib/validation-tests.js +0 -597
  63. package/node_modules/inputmask/lib/validation.js +0 -664
  64. package/node_modules/inputmask/package.json +0 -60
  65. package/src/example/App.example.tsx +0 -68
  66. package/src/example/index.tsx +0 -5
@@ -1,597 +0,0 @@
1
- export {
2
- determineTestTemplate,
3
- getDecisionTaker,
4
- getMaskTemplate,
5
- getPlaceholder,
6
- getTest,
7
- getTests,
8
- getTestTemplate,
9
- isSubsetOf
10
- };
11
- import Inputmask from "./inputmask";
12
-
13
- function getLocator(tst, align) { //need to align the locators to be correct
14
- var locator = (tst.alternation != undefined ? tst.mloc[getDecisionTaker(tst)] : tst.locator).join("");
15
- if (locator !== "") while (locator.length < align) locator += "0";
16
- return locator;
17
- }
18
-
19
- function getDecisionTaker(tst) {
20
- var decisionTaker = tst.locator[tst.alternation];
21
- if (typeof decisionTaker == "string" && decisionTaker.length > 0) { //no decision taken ~ take first one as decider
22
- decisionTaker = decisionTaker.split(",")[0];
23
- }
24
- return decisionTaker !== undefined ? decisionTaker.toString() : "";
25
- }
26
-
27
- //tobe put on prototype?
28
- function getPlaceholder(pos, test, returnPL) {
29
- const inputmask = this,
30
- opts = this.opts,
31
- maskset = this.maskset;
32
-
33
- test = test || getTest.call(inputmask, pos).match;
34
- if (test.placeholder !== undefined || returnPL === true) {
35
- return typeof test.placeholder === "function" ? test.placeholder(opts) : test.placeholder;
36
- } else if (test.static === true) {
37
- if (pos > -1 && maskset.validPositions[pos] === undefined) {
38
- var tests = getTests.call(inputmask, pos),
39
- staticAlternations = [],
40
- prevTest;
41
- if (tests.length > 1 + (tests[tests.length - 1].match.def === "" ? 1 : 0)) {
42
- for (var i = 0; i < tests.length; i++) {
43
- if (tests[i].match.def !== "" && tests[i].match.optionality !== true && tests[i].match.optionalQuantifier !== true &&
44
- (tests[i].match.static === true || (prevTest === undefined || tests[i].match.fn.test(prevTest.match.def, maskset, pos, true, opts) !== false))) {
45
- staticAlternations.push(tests[i]);
46
- if (tests[i].match.static === true) prevTest = tests[i];
47
- if (staticAlternations.length > 1) {
48
- if (/[0-9a-bA-Z]/.test(staticAlternations[0].match.def)) {
49
- return opts.placeholder.charAt(pos % opts.placeholder.length);
50
- }
51
- }
52
- }
53
- }
54
- }
55
- }
56
- return test.def;
57
- }
58
-
59
- return opts.placeholder.charAt(pos % opts.placeholder.length);
60
- }
61
-
62
- //tobe put on prototype?
63
- function getMaskTemplate(baseOnInput, minimalPos, includeMode, noJit, clearOptionalTail) {
64
- //includeMode true => input, undefined => placeholder, false => mask
65
-
66
- var inputmask = this,
67
- opts = this.opts,
68
- maskset = this.maskset;
69
-
70
-
71
- var greedy = opts.greedy;
72
- if (clearOptionalTail && opts.greedy) {
73
- opts.greedy = false;
74
- inputmask.maskset.tests = {};
75
- }
76
- minimalPos = minimalPos || 0;
77
- var maskTemplate = [],
78
- ndxIntlzr, pos = 0,
79
- test, testPos, jitRenderStatic;
80
- do {
81
- if (baseOnInput === true && maskset.validPositions[pos]) {
82
- testPos = (clearOptionalTail && maskset.validPositions[pos].match.optionality
83
- && maskset.validPositions[pos + 1] === undefined
84
- && (maskset.validPositions[pos].generatedInput === true || (maskset.validPositions[pos].input == opts.skipOptionalPartCharacter && pos > 0)))
85
- ? determineTestTemplate.call(inputmask, pos, getTests.call(inputmask, pos, ndxIntlzr, pos - 1))
86
- : maskset.validPositions[pos];
87
- test = testPos.match;
88
- ndxIntlzr = testPos.locator.slice();
89
- maskTemplate.push(includeMode === true ? testPos.input : includeMode === false ? test.nativeDef : getPlaceholder.call(inputmask, pos, test));
90
- } else {
91
- testPos = getTestTemplate.call(inputmask, pos, ndxIntlzr, pos - 1);
92
- test = testPos.match;
93
- ndxIntlzr = testPos.locator.slice();
94
- var jitMasking = noJit === true ? false : (opts.jitMasking !== false ? opts.jitMasking : test.jit);
95
- //check for groupSeparator is a hack for the numerics as we don't want the render of the groupSeparator beforehand
96
- jitRenderStatic = ((jitRenderStatic && test.static && test.def !== opts.groupSeparator && test.fn === null) || (maskset.validPositions[pos - 1] && test.static && test.def !== opts.groupSeparator && test.fn === null)) && maskset.tests[pos] && maskset.tests[pos].length === 1;
97
- if (jitRenderStatic || jitMasking === false || jitMasking === undefined /*|| pos < lvp*/ || (typeof jitMasking === "number" && isFinite(jitMasking) && jitMasking > pos)) {
98
- maskTemplate.push(includeMode === false ? test.nativeDef : getPlaceholder.call(inputmask, pos, test));
99
- } else {
100
- jitRenderStatic = false;
101
- }
102
- }
103
-
104
- pos++;
105
- } while ((test.static !== true || test.def !== "") || minimalPos > pos);
106
- if (maskTemplate[maskTemplate.length - 1] === "") {
107
- maskTemplate.pop(); //drop the last one which is empty
108
- }
109
- if (includeMode !== false || //do not alter the masklength when just retrieving the maskdefinition
110
- maskset.maskLength === undefined) //just make sure the maskLength gets initialized in all cases (needed for isValid)
111
- {
112
- maskset.maskLength = pos - 1;
113
- }
114
-
115
- opts.greedy = greedy;
116
- return maskTemplate;
117
- }
118
-
119
- //tobe put on prototype?
120
- function getTestTemplate(pos, ndxIntlzr, tstPs) {
121
- var inputmask = this,
122
- maskset = this.maskset;
123
-
124
- return maskset.validPositions[pos] || determineTestTemplate.call(inputmask, pos, getTests.call(inputmask, pos, ndxIntlzr ? ndxIntlzr.slice() : ndxIntlzr, tstPs));
125
- }
126
-
127
- //tobe put on prototype?
128
- function determineTestTemplate(pos, tests) {
129
- var inputmask = this,
130
- opts = this.opts;
131
- var optionalityLevel = determineOptionalityLevel(pos, tests);
132
- pos = pos > 0 ? pos - 1 : 0;
133
- var altTest = getTest.call(inputmask, pos), targetLocator = getLocator(altTest), tstLocator, closest, bestMatch;
134
- if (opts.greedy && tests.length > 1 && tests[tests.length - 1].match.def === "")
135
- tests.pop();
136
- // console.log(" optionality = " + optionalityLevel);
137
- // console.log(" - " + JSON.stringify(tests));
138
- for (var ndx = 0; ndx < tests.length; ndx++) { //find best matching
139
- var tst = tests[ndx];
140
- tstLocator = getLocator(tst, targetLocator.length);
141
- var distance = Math.abs(tstLocator - targetLocator);
142
-
143
- if (closest === undefined
144
- || (tstLocator !== "" && distance < closest)
145
- || (bestMatch && !opts.greedy &&
146
- (bestMatch.match.optionality && bestMatch.match.optionality - optionalityLevel > 0) &&
147
- bestMatch.match.newBlockMarker === "master" &&
148
- ((!tst.match.optionality || tst.match.optionality - optionalityLevel < 1) || !tst.match.newBlockMarker))
149
- || (bestMatch && !opts.greedy && bestMatch.match.optionalQuantifier && !tst.match.optionalQuantifier)) {
150
- closest = distance;
151
- bestMatch = tst;
152
- }
153
- }
154
- return bestMatch;
155
- }
156
-
157
- function determineOptionalityLevel(pos, tests) {
158
- let optionalityLevel = 0, differentOptionalLevels = false;
159
- tests.forEach(test => {
160
- if (test.match.optionality) {
161
- if (optionalityLevel !== 0 && optionalityLevel !== test.match.optionality)
162
- differentOptionalLevels = true;
163
- if (optionalityLevel === 0 || optionalityLevel > test.match.optionality) {
164
- optionalityLevel = test.match.optionality;
165
- }
166
- }
167
- });
168
- if (optionalityLevel) {
169
- if (pos == 0) optionalityLevel = 0;
170
- else if (tests.length == 1) optionalityLevel = 0;
171
- else if (!differentOptionalLevels) optionalityLevel = 0;
172
- }
173
- return optionalityLevel;
174
- }
175
-
176
- //tobe put on prototype?
177
- function getTest(pos, tests) {
178
- var inputmask = this,
179
- maskset = this.maskset;
180
-
181
- if (maskset.validPositions[pos]) {
182
- return maskset.validPositions[pos];
183
- }
184
- return (tests || getTests.call(inputmask, pos))[0];
185
- }
186
-
187
- function isSubsetOf(source, target, opts) {
188
- function expand(pattern) {
189
- var expanded = [], start = -1, end;
190
- for (var i = 0, l = pattern.length; i < l; i++) {
191
- if (pattern.charAt(i) === "-") {
192
- end = pattern.charCodeAt(i + 1);
193
- while (++start < end) expanded.push(String.fromCharCode(start));
194
- } else {
195
- start = pattern.charCodeAt(i);
196
- expanded.push(pattern.charAt(i));
197
- }
198
- }
199
- return expanded.join("");
200
- }
201
-
202
- if (source.match.def === target.match.nativeDef) return true;
203
- if ((opts.regex || (source.match.fn instanceof RegExp && target.match.fn instanceof RegExp)) && source.match.static !== true && target.match.static !== true) { //is regex a subset
204
- return expand(target.match.fn.toString().replace(/[[\]/]/g, "")).indexOf(expand(source.match.fn.toString().replace(/[[\]/]/g, ""))) !== -1;
205
- }
206
- return false;
207
- }
208
-
209
- //tobe put on prototype?
210
- function getTests(pos, ndxIntlzr, tstPs) {
211
- var inputmask = this,
212
- $ = this.dependencyLib,
213
- maskset = this.maskset,
214
- opts = this.opts,
215
- el = this.el,
216
- maskTokens = maskset.maskToken,
217
- testPos = ndxIntlzr ? tstPs : 0,
218
- ndxInitializer = ndxIntlzr ? ndxIntlzr.slice() : [0],
219
- matches = [],
220
- insertStop = false,
221
- latestMatch,
222
- cacheDependency = ndxIntlzr ? ndxIntlzr.join("") : "";
223
-
224
- function resolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { //ndxInitializer contains a set of indexes to speedup searches in the mtokens
225
- function handleMatch(match, loopNdx, quantifierRecurse) {
226
- function isFirstMatch(latestMatch, tokenGroup) {
227
- var firstMatch = tokenGroup.matches.indexOf(latestMatch) === 0;
228
- if (!firstMatch) {
229
- tokenGroup.matches.every(function (match, ndx) {
230
- if (match.isQuantifier === true) {
231
- firstMatch = isFirstMatch(latestMatch, tokenGroup.matches[ndx - 1]);
232
- } else if (Object.prototype.hasOwnProperty.call(match, "matches")) firstMatch = isFirstMatch(latestMatch, match);
233
- if (firstMatch) return false;
234
-
235
- return true;
236
- });
237
- }
238
- return firstMatch;
239
- }
240
-
241
- function resolveNdxInitializer(pos, alternateNdx, targetAlternation) {
242
- var bestMatch, indexPos;
243
-
244
- if (maskset.tests[pos] || maskset.validPositions[pos]) {
245
- (maskset.tests[pos] || [maskset.validPositions[pos]]).every(function (lmnt, ndx) {
246
- if (lmnt.mloc[alternateNdx]) {
247
- bestMatch = lmnt;
248
- return false; //break
249
- }
250
- var alternation = targetAlternation !== undefined ? targetAlternation : lmnt.alternation,
251
- ndxPos = lmnt.locator[alternation] !== undefined ? lmnt.locator[alternation].toString().indexOf(alternateNdx) : -1;
252
- if ((indexPos === undefined || ndxPos < indexPos) && ndxPos !== -1) {
253
- bestMatch = lmnt;
254
- indexPos = ndxPos;
255
- }
256
-
257
- return true;
258
- });
259
- }
260
- if (bestMatch) {
261
- var bestMatchAltIndex = bestMatch.locator[bestMatch.alternation];
262
- var locator = bestMatch.mloc[alternateNdx] || bestMatch.mloc[bestMatchAltIndex] || bestMatch.locator;
263
- return locator.slice((targetAlternation !== undefined ? targetAlternation : bestMatch.alternation) + 1);
264
- } else {
265
- return targetAlternation !== undefined ? resolveNdxInitializer(pos, alternateNdx) : undefined;
266
- }
267
- }
268
-
269
- function staticCanMatchDefinition(source, target) {
270
- return source.match.static === true && target.match.static !== true ? target.match.fn.test(source.match.def, maskset, pos, false, opts, false) : false;
271
- }
272
-
273
- //mergelocators for retrieving the correct locator match when merging
274
- function setMergeLocators(targetMatch, altMatch) {
275
- var alternationNdx = targetMatch.alternation,
276
- shouldMerge = altMatch === undefined || (alternationNdx === altMatch.alternation &&
277
- targetMatch.locator[alternationNdx].toString().indexOf(altMatch.locator[alternationNdx]) === -1);
278
- if (!shouldMerge && alternationNdx > altMatch.alternation) {
279
- for (var i = altMatch.alternation; i < alternationNdx; i++) {
280
- if (targetMatch.locator[i] !== altMatch.locator[i]) {
281
- alternationNdx = i;
282
- shouldMerge = true;
283
- break;
284
- }
285
- }
286
- }
287
-
288
- if (shouldMerge) {
289
- targetMatch.mloc = targetMatch.mloc || {};
290
- var locNdx = targetMatch.locator[alternationNdx];
291
- if (locNdx === undefined) {
292
- targetMatch.alternation = undefined;
293
- } else {
294
- if (typeof locNdx === "string") locNdx = locNdx.split(",")[0];
295
- if (targetMatch.mloc[locNdx] === undefined) targetMatch.mloc[locNdx] = targetMatch.locator.slice();
296
- if (altMatch !== undefined) {
297
- for (var ndx in altMatch.mloc) {
298
- if (typeof ndx === "string") ndx = ndx.split(",")[0];
299
- if (targetMatch.mloc[ndx] === undefined) targetMatch.mloc[ndx] = altMatch.mloc[ndx];
300
- }
301
- targetMatch.locator[alternationNdx] = Object.keys(targetMatch.mloc).join(",");
302
- }
303
- return true;
304
- }
305
- }
306
- return false;
307
- }
308
-
309
- function isSameLevel(targetMatch, altMatch) {
310
- if (targetMatch.locator.length !== altMatch.locator.length) {
311
- return false;
312
- }
313
- for (let locNdx = targetMatch.alternation + 1; locNdx < targetMatch.locator.length; locNdx++) {
314
- if (targetMatch.locator[locNdx] !== altMatch.locator[locNdx]) {
315
- return false;
316
- }
317
- }
318
- return true;
319
- }
320
-
321
- if (testPos > (pos + opts._maxTestPos)) {
322
- throw "Inputmask: There is probably an error in your mask definition or in the code. Create an issue on github with an example of the mask you are using. " + maskset.mask;
323
- }
324
- if (testPos === pos && match.matches === undefined) {
325
- matches.push({
326
- "match": match,
327
- "locator": loopNdx.reverse(),
328
- "cd": cacheDependency,
329
- "mloc": {}
330
- });
331
- if (match.optionality && quantifierRecurse === undefined &&
332
- ((opts.definitions && opts.definitions[match.nativeDef] && opts.definitions[match.nativeDef].optional) ||
333
- (Inputmask.prototype.definitions[match.nativeDef] && Inputmask.prototype.definitions[match.nativeDef].optional))) { //prevent loop see #698
334
- insertStop = true; //insert a stop
335
- testPos = pos; //match the position after the group
336
- } else {
337
- return true;
338
- }
339
- } else if (match.matches !== undefined) {
340
- if (match.isGroup && quantifierRecurse !== match) { //when a group pass along to the quantifier
341
- match = handleMatch(maskToken.matches[maskToken.matches.indexOf(match) + 1], loopNdx, quantifierRecurse);
342
- if (match) return true;
343
- } else if (match.isOptional) {
344
- var optionalToken = match, mtchsNdx = matches.length;
345
- match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse);
346
- if (match) {
347
- //mark optionality in matches
348
- matches.forEach(function (mtch, ndx) {
349
- if (ndx >= mtchsNdx) {
350
- mtch.match.optionality = mtch.match.optionality ? mtch.match.optionality + 1 : 1;
351
- }
352
- });
353
- latestMatch = matches[matches.length - 1].match;
354
-
355
- if (quantifierRecurse === undefined && isFirstMatch(latestMatch, optionalToken)) { //prevent loop see #698
356
- insertStop = true; //insert a stop
357
- testPos = pos; //match the position after the group
358
- } else {
359
- return true;
360
- }
361
- }
362
- } else if (match.isAlternator) {
363
- var alternateToken = match,
364
- malternateMatches = [],
365
- maltMatches,
366
- currentMatches = matches.slice(),
367
- loopNdxCnt = loopNdx.length,
368
- unMatchedAlternation = false;
369
- var altIndex = ndxInitializer.length > 0 ? ndxInitializer.shift() : -1;
370
- if (altIndex === -1 || typeof altIndex === "string") {
371
- var currentPos = testPos,
372
- ndxInitializerClone = ndxInitializer.slice(),
373
- altIndexArr = [],
374
- amndx;
375
- if (typeof altIndex == "string") {
376
- altIndexArr = altIndex.split(",");
377
- } else {
378
- for (amndx = 0; amndx < alternateToken.matches.length; amndx++) {
379
- altIndexArr.push(amndx.toString());
380
- }
381
- }
382
-
383
- if (maskset.excludes[pos] !== undefined) {
384
- var altIndexArrClone = altIndexArr.slice();
385
- for (var i = 0, exl = maskset.excludes[pos].length; i < exl; i++) {
386
- var excludeSet = maskset.excludes[pos][i].toString().split(":");
387
- if (loopNdx.length == excludeSet[1]) {
388
- altIndexArr.splice(altIndexArr.indexOf(excludeSet[0]), 1);
389
- }
390
- }
391
- if (altIndexArr.length === 0) { //fully alternated => reset
392
- delete maskset.excludes[pos];
393
- altIndexArr = altIndexArrClone;
394
- }
395
- }
396
- if (opts.keepStatic === true || (isFinite(parseInt(opts.keepStatic)) && currentPos >= opts.keepStatic)) altIndexArr = altIndexArr.slice(0, 1);
397
- for (var ndx = 0; ndx < altIndexArr.length; ndx++) {
398
- amndx = parseInt(altIndexArr[ndx]);
399
- matches = [];
400
- //set the correct ndxInitializer
401
- ndxInitializer = typeof altIndex === "string" ? resolveNdxInitializer(testPos, amndx, loopNdxCnt) || ndxInitializerClone.slice() : ndxInitializerClone.slice();
402
- var tokenMatch = alternateToken.matches[amndx];
403
- if (tokenMatch && handleMatch(tokenMatch, [amndx].concat(loopNdx), quantifierRecurse)) {
404
- match = true;
405
- } else {
406
- if (ndx === 0) {
407
- unMatchedAlternation = true;
408
- }
409
- if (tokenMatch && tokenMatch.matches && tokenMatch.matches.length > alternateToken.matches[0].matches.length) {
410
- break;
411
- }
412
- }
413
-
414
- maltMatches = matches.slice();
415
- testPos = currentPos;
416
- matches = [];
417
-
418
- //fuzzy merge matches
419
- for (var ndx1 = 0; ndx1 < maltMatches.length; ndx1++) {
420
- var altMatch = maltMatches[ndx1],
421
- dropMatch = false;
422
- altMatch.match.jit = altMatch.match.jit || unMatchedAlternation; //mark jit when there are unmatched alternations ex: mask: "(a|aa)"
423
- altMatch.alternation = altMatch.alternation || loopNdxCnt;
424
- setMergeLocators(altMatch);
425
- for (var ndx2 = 0; ndx2 < malternateMatches.length; ndx2++) {
426
- var altMatch2 = malternateMatches[ndx2];
427
- if (typeof altIndex !== "string" || (altMatch.alternation !== undefined && altIndexArr.includes(altMatch.locator[altMatch.alternation].toString()))) {
428
- if (altMatch.match.nativeDef === altMatch2.match.nativeDef) {
429
- dropMatch = true;
430
- setMergeLocators(altMatch2, altMatch);
431
- break;
432
- } else if (isSubsetOf(altMatch, altMatch2, opts)) {
433
- if (setMergeLocators(altMatch, altMatch2)) {
434
- dropMatch = true;
435
- malternateMatches.splice(malternateMatches.indexOf(altMatch2), 0, altMatch);
436
- }
437
- break;
438
- } else if (isSubsetOf(altMatch2, altMatch, opts)) {
439
- setMergeLocators(altMatch2, altMatch);
440
- break;
441
- } else if (staticCanMatchDefinition(altMatch, altMatch2)) {
442
- if (!isSameLevel(altMatch, altMatch2) && el.inputmask.userOptions.keepStatic === undefined) {
443
- opts.keepStatic = true;
444
- } else if (setMergeLocators(altMatch, altMatch2)) {
445
- //insert match above general match
446
- dropMatch = true;
447
- malternateMatches.splice(malternateMatches.indexOf(altMatch2), 0, altMatch);
448
- }
449
- break;
450
- }
451
- }
452
- }
453
- if (!dropMatch) {
454
- malternateMatches.push(altMatch);
455
- }
456
- }
457
- }
458
-
459
- matches = currentMatches.concat(malternateMatches);
460
- testPos = pos;
461
- insertStop = matches.length > 0; //insert a stopelemnt when there is an alternate - needed for non-greedy option
462
- match = malternateMatches.length > 0; //set correct match state
463
-
464
- //cloneback
465
- ndxInitializer = ndxInitializerClone.slice();
466
- } else {
467
- match = handleMatch(alternateToken.matches[altIndex] || maskToken.matches[altIndex], [altIndex].concat(loopNdx), quantifierRecurse);
468
- }
469
- if (match) return true;
470
- } else if (match.isQuantifier && quantifierRecurse !== maskToken.matches[maskToken.matches.indexOf(match) - 1]) {
471
- var qt = match;
472
- for (var qndx = (ndxInitializer.length > 0) ? ndxInitializer.shift() : 0; (qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max)) && testPos <= pos; qndx++) {
473
- var tokenGroup = maskToken.matches[maskToken.matches.indexOf(qt) - 1];
474
- match = handleMatch(tokenGroup, [qndx].concat(loopNdx), tokenGroup); //set the tokenGroup as quantifierRecurse marker
475
- if (match) {
476
- //get latest match
477
- latestMatch = matches[matches.length - 1].match;
478
- //mark optionality
479
- //TODO FIX RECURSIVE QUANTIFIERS
480
- latestMatch.optionalQuantifier = qndx >= qt.quantifier.min;
481
- // console.log(pos + " " + qt.quantifier.min + " " + latestMatch.optionalQuantifier);
482
- //qndx + 1 as the index starts from 0
483
- latestMatch.jit = (qndx + 1) * (tokenGroup.matches.indexOf(latestMatch) + 1) > qt.quantifier.jit;
484
- if (latestMatch.optionalQuantifier && isFirstMatch(latestMatch, tokenGroup)) {
485
- insertStop = true;
486
- testPos = pos; //match the position after the group
487
- break; //stop quantifierloop && search for next possible match
488
- }
489
- if (latestMatch.jit /*&& !latestMatch.optionalQuantifier*/) {
490
- //always set jitOffset, isvalid checks when to apply
491
- maskset.jitOffset[pos] = tokenGroup.matches.length - tokenGroup.matches.indexOf(latestMatch);
492
- }
493
- return true;
494
- }
495
- }
496
- } else {
497
- match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse);
498
- if (match) return true;
499
- }
500
- } else {
501
- testPos++;
502
- }
503
- }
504
-
505
- //the offset is set in the quantifierloop when git masking is used
506
- for (var tndx = (ndxInitializer.length > 0 ? ndxInitializer.shift() : 0); tndx < maskToken.matches.length; tndx++) {
507
- if (maskToken.matches[tndx].isQuantifier !== true) {
508
- var match = handleMatch(maskToken.matches[tndx], [tndx].concat(loopNdx), quantifierRecurse);
509
- if (match && testPos === pos) {
510
- return match;
511
- } else if (testPos > pos) {
512
- break;
513
- }
514
- }
515
- }
516
- }
517
-
518
- function mergeLocators(pos, tests) {
519
- let locator = [], alternation;
520
- if (!Array.isArray(tests)) tests = [tests];
521
-
522
- if (tests.length > 0) {
523
- if (tests[0].alternation === undefined || opts.keepStatic === true) {
524
- locator = determineTestTemplate.call(inputmask, pos, tests.slice()).locator.slice();
525
- if (locator.length === 0) locator = tests[0].locator.slice();
526
- } else {
527
- tests.forEach(function (tst) {
528
- if (tst.def !== "") {
529
- if (locator.length === 0) {
530
- alternation = tst.alternation;
531
- locator = tst.locator.slice();
532
- } else {
533
- if (tst.locator[alternation] && locator[alternation].toString().indexOf(tst.locator[alternation]) === -1) {
534
- locator[alternation] += "," + tst.locator[alternation];
535
- }
536
- }
537
- }
538
- });
539
- }
540
- }
541
- return locator;
542
- }
543
-
544
- if (pos > -1) {
545
- if (ndxIntlzr === undefined) { //determine index initializer
546
- var previousPos = pos - 1,
547
- test;
548
- while ((test = maskset.validPositions[previousPos] || maskset.tests[previousPos]) === undefined && previousPos > -1) {
549
- previousPos--;
550
- }
551
- if (test !== undefined && previousPos > -1) {
552
- ndxInitializer = mergeLocators(previousPos, test);
553
- cacheDependency = ndxInitializer.join("");
554
- testPos = previousPos;
555
- }
556
- }
557
- if (maskset.tests[pos] && maskset.tests[pos][0].cd === cacheDependency) { //cacheDependency is set on all tests, just check on the first
558
- return maskset.tests[pos];
559
- }
560
- for (var mtndx = ndxInitializer.shift(); mtndx < maskTokens.length; mtndx++) {
561
- var match = resolveTestFromToken(maskTokens[mtndx], ndxInitializer, [mtndx]);
562
- if ((match && testPos === pos) || testPos > pos) {
563
- break;
564
- }
565
- }
566
- }
567
- if (matches.length === 0 || insertStop) {
568
- matches.push({
569
- match: {
570
- fn: null,
571
- static: true,
572
- optionality: false,
573
- casing: null,
574
- def: "",
575
- placeholder: ""
576
- },
577
- locator: [],
578
- mloc: {},
579
- cd: cacheDependency
580
- });
581
- }
582
- var result;
583
- if (ndxIntlzr !== undefined && maskset.tests[pos]) { //prioritize full tests for caching
584
- result = $.extend(true, [], matches);
585
- } else {
586
- maskset.tests[pos] = $.extend(true, [], matches); //set a clone to prevent overwriting some props
587
- result = maskset.tests[pos];
588
- }
589
-
590
- // console.log(pos + " - " + JSON.stringify(matches));
591
- //cleanup optionality marking
592
- matches.forEach(t => {
593
- t.match.optionality = false;
594
- });
595
-
596
- return result;
597
- }