use-mask-input 3.0.6 → 3.1.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 (65) hide show
  1. package/dist/index.cjs +178 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.ts +34 -3
  4. package/dist/index.js +171 -1
  5. package/dist/index.js.map +1 -1
  6. package/package.json +43 -43
  7. package/src/index.tsx +3 -2
  8. package/src/types.ts +6 -0
  9. package/src/useMaskInput.ts +12 -9
  10. package/src/utils.spec.ts +13 -0
  11. package/src/utils.ts +27 -0
  12. package/src/withHookFormMask.ts +9 -16
  13. package/src/withMask.ts +5 -6
  14. package/dist/example/App.example.d.ts +0 -3
  15. package/dist/example/index.d.ts +0 -1
  16. package/dist/index.modern.js +0 -2
  17. package/dist/index.modern.js.map +0 -1
  18. package/dist/index.umd.js +0 -2
  19. package/dist/index.umd.js.map +0 -1
  20. package/dist/useMaskInput.d.ts +0 -9
  21. package/dist/withHookFormMask.d.ts +0 -16
  22. package/dist/withMask.d.ts +0 -3
  23. package/node_modules/inputmask/LICENSE.txt +0 -7
  24. package/node_modules/inputmask/README.md +0 -1279
  25. package/node_modules/inputmask/bundle.js +0 -6
  26. package/node_modules/inputmask/dist/bindings/inputmask.binding.js +0 -26
  27. package/node_modules/inputmask/dist/inputmask.es6.js +0 -5
  28. package/node_modules/inputmask/dist/inputmask.js +0 -3031
  29. package/node_modules/inputmask/dist/inputmask.min.js +0 -8
  30. package/node_modules/inputmask/dist/jquery.inputmask.js +0 -2985
  31. package/node_modules/inputmask/dist/jquery.inputmask.min.js +0 -8
  32. package/node_modules/inputmask/lib/bindings/inputmask.binding.js +0 -26
  33. package/node_modules/inputmask/lib/bindings/inputmask.es6.js +0 -5
  34. package/node_modules/inputmask/lib/canUseDOM.js +0 -7
  35. package/node_modules/inputmask/lib/defaults.js +0 -101
  36. package/node_modules/inputmask/lib/definitions.js +0 -13
  37. package/node_modules/inputmask/lib/dependencyLibs/data.js +0 -8
  38. package/node_modules/inputmask/lib/dependencyLibs/events.js +0 -199
  39. package/node_modules/inputmask/lib/dependencyLibs/extend.js +0 -58
  40. package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.jquery.js +0 -13
  41. package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.js +0 -41
  42. package/node_modules/inputmask/lib/environment.js +0 -9
  43. package/node_modules/inputmask/lib/escapeRegex.js +0 -4
  44. package/node_modules/inputmask/lib/eventhandlers.js +0 -513
  45. package/node_modules/inputmask/lib/eventruler.js +0 -124
  46. package/node_modules/inputmask/lib/extensions/inputmask.date.extensions.js +0 -588
  47. package/node_modules/inputmask/lib/extensions/inputmask.extensions.js +0 -133
  48. package/node_modules/inputmask/lib/extensions/inputmask.numeric.extensions.js +0 -631
  49. package/node_modules/inputmask/lib/global/window.js +0 -3
  50. package/node_modules/inputmask/lib/inputHandling.js +0 -252
  51. package/node_modules/inputmask/lib/inputmask.js +0 -355
  52. package/node_modules/inputmask/lib/inputmaskElement.js +0 -33
  53. package/node_modules/inputmask/lib/jquery.inputmask.js +0 -81
  54. package/node_modules/inputmask/lib/keycode.json +0 -25
  55. package/node_modules/inputmask/lib/mask-lexer.js +0 -467
  56. package/node_modules/inputmask/lib/mask.js +0 -244
  57. package/node_modules/inputmask/lib/masktoken.js +0 -13
  58. package/node_modules/inputmask/lib/polyfills/Array.includes.js +0 -48
  59. package/node_modules/inputmask/lib/polyfills/Object.getPrototypeOf.js +0 -7
  60. package/node_modules/inputmask/lib/positioning.js +0 -348
  61. package/node_modules/inputmask/lib/validation-tests.js +0 -597
  62. package/node_modules/inputmask/lib/validation.js +0 -664
  63. package/node_modules/inputmask/package.json +0 -60
  64. package/src/example/App.example.tsx +0 -68
  65. package/src/example/index.tsx +0 -5
@@ -1,81 +0,0 @@
1
- /*
2
- * Input Mask plugin for jquery
3
- * http://github.com/RobinHerbots/jquery.inputmask
4
- * Copyright (c) Robin Herbots
5
- * Licensed under the MIT license
6
- */
7
- import $ from "jquery";
8
- import Inputmask from "./inputmask";
9
-
10
- if ($.fn.inputmask === undefined) {
11
- //jquery plugin
12
- $.fn.inputmask = function (fn, options) {
13
- var nptmask, input = this[0];
14
- if (options === undefined) options = {};
15
- if (typeof fn === "string") {
16
- switch (fn) {
17
- case "unmaskedvalue":
18
- return input && input.inputmask ? input.inputmask.unmaskedvalue() : $(input).val();
19
- case "remove":
20
- return this.each(function () {
21
- if (this.inputmask) this.inputmask.remove();
22
- });
23
- case "getemptymask":
24
- return input && input.inputmask ? input.inputmask.getemptymask() : "";
25
- case "hasMaskedValue": //check whether the returned value is masked or not; currently only works reliable when using jquery.val fn to retrieve the value
26
- return input && input.inputmask ? input.inputmask.hasMaskedValue() : false;
27
- case "isComplete":
28
- return input && input.inputmask ? input.inputmask.isComplete() : true;
29
- case "getmetadata": //return mask metadata if exists
30
- return input && input.inputmask ? input.inputmask.getmetadata() : undefined;
31
- case "setvalue":
32
- Inputmask.setValue(input, options);
33
- break;
34
- case "option":
35
- if (typeof options === "string") {
36
- if (input && input.inputmask !== undefined) {
37
- return input.inputmask.option(options);
38
- }
39
- } else {
40
- return this.each(function () {
41
- if (this.inputmask !== undefined) {
42
- return this.inputmask.option(options);
43
- }
44
- });
45
- }
46
- break;
47
- default:
48
- options.alias = fn;
49
- nptmask = new Inputmask(options);
50
- return this.each(function () {
51
- nptmask.mask(this);
52
- });
53
- }
54
- } else if (Array.isArray(fn)) {
55
- options.alias = fn;
56
- nptmask = new Inputmask(options);
57
- return this.each(function () {
58
- nptmask.mask(this);
59
- });
60
- } else if (typeof fn == "object") {
61
- nptmask = new Inputmask(fn);
62
- if (fn.mask === undefined && fn.alias === undefined) {
63
- return this.each(function () {
64
- if (this.inputmask !== undefined) {
65
- return this.inputmask.option(fn);
66
- } else nptmask.mask(this);
67
- });
68
- } else {
69
- return this.each(function () {
70
- nptmask.mask(this);
71
- });
72
- }
73
- } else if (fn === undefined) {
74
- //look for data-inputmask atributes
75
- return this.each(function () {
76
- nptmask = new Inputmask(options);
77
- nptmask.mask(this);
78
- });
79
- }
80
- };
81
- }
@@ -1,25 +0,0 @@
1
- {
2
- "BACKSPACE": 8,
3
- "BACKSPACE_SAFARI": 127,
4
- "DELETE": 46,
5
- "DOWN": 40,
6
- "END": 35,
7
- "ENTER": 13,
8
- "ESCAPE": 27,
9
- "HOME": 36,
10
- "INSERT": 45,
11
- "LEFT": 37,
12
- "PAGE_DOWN": 34,
13
- "PAGE_UP": 33,
14
- "RIGHT": 39,
15
- "SPACE": 32,
16
- "TAB": 9,
17
- "UP": 38,
18
- "X": 88,
19
- "Z": 90,
20
- "CONTROL": 17,
21
- "PAUSE/BREAK": 19,
22
- "WINDOWS_LEFT": 91,
23
- "WINDOWS_RIGHT": 92,
24
- "KEY_229": 229
25
- }
@@ -1,467 +0,0 @@
1
- import $ from "./dependencyLibs/inputmask.dependencyLib";
2
- import MaskToken from "./masktoken";
3
- import Inputmask from "./inputmask";
4
-
5
- export {generateMaskSet, analyseMask};
6
-
7
- function generateMaskSet(opts, nocache) {
8
- var ms;
9
-
10
- function generateMask(mask, metadata, opts) {
11
- var regexMask = false;
12
- if (mask === null || mask === "") {
13
- regexMask = opts.regex !== null;
14
- if (regexMask) {
15
- mask = opts.regex;
16
- mask = mask.replace(/^(\^)(.*)(\$)$/, "$2");
17
- } else {
18
- regexMask = true;
19
- mask = ".*";
20
- }
21
- }
22
- if (mask.length === 1 && opts.greedy === false && opts.repeat !== 0) {
23
- opts.placeholder = "";
24
- } //hide placeholder with single non-greedy mask
25
- if (opts.repeat > 0 || opts.repeat === "*" || opts.repeat === "+") {
26
- var repeatStart = opts.repeat === "*" ? 0 : (opts.repeat === "+" ? 1 : opts.repeat);
27
- mask = opts.groupmarker[0] + mask + opts.groupmarker[1] + opts.quantifiermarker[0] + repeatStart + "," + opts.repeat + opts.quantifiermarker[1];
28
- }
29
-
30
- // console.log(mask);
31
- var masksetDefinition, maskdefKey;
32
- maskdefKey = regexMask ? "regex_" + opts.regex : opts.numericInput ? mask.split("").reverse().join("") : mask;
33
- if (opts.keepStatic !== null) { //keepstatic modifies the output from the testdefinitions ~ so differentiate in the maskcache
34
- maskdefKey = "ks_" + opts.keepStatic + maskdefKey;
35
- }
36
-
37
- if (Inputmask.prototype.masksCache[maskdefKey] === undefined || nocache === true) {
38
- masksetDefinition = {
39
- "mask": mask,
40
- "maskToken": Inputmask.prototype.analyseMask(mask, regexMask, opts),
41
- "validPositions": {},
42
- "_buffer": undefined,
43
- "buffer": undefined,
44
- "tests": {},
45
- "excludes": {}, //excluded alternations
46
- "metadata": metadata,
47
- "maskLength": undefined,
48
- "jitOffset": {}
49
- };
50
- if (nocache !== true) {
51
- Inputmask.prototype.masksCache[maskdefKey] = masksetDefinition;
52
- masksetDefinition = $.extend(true, {}, Inputmask.prototype.masksCache[maskdefKey]);
53
- }
54
- } else {
55
- masksetDefinition = $.extend(true, {}, Inputmask.prototype.masksCache[maskdefKey]);
56
- }
57
-
58
- return masksetDefinition;
59
- }
60
-
61
- if (typeof opts.mask === "function") { //allow mask to be a preprocessing fn - should return a valid mask
62
- opts.mask = opts.mask(opts);
63
- }
64
- if (Array.isArray(opts.mask)) {
65
- if (opts.mask.length > 1) {
66
- if (opts.keepStatic === null) { //enable by default when passing multiple masks when the option is not explicitly specified
67
- opts.keepStatic = true;
68
- }
69
- var altMask = opts.groupmarker[0];
70
- (opts.isRTL ? opts.mask.reverse() : opts.mask).forEach(function (msk) {
71
- if (altMask.length > 1) {
72
- altMask += opts.alternatormarker;
73
- }
74
- if (msk.mask !== undefined && typeof msk.mask !== "function") {
75
- altMask += msk.mask;
76
- } else {
77
- altMask += msk;
78
- }
79
- });
80
- altMask += opts.groupmarker[1];
81
- // console.log(altMask);
82
- return generateMask(altMask, opts.mask, opts);
83
- } else {
84
- opts.mask = opts.mask.pop();
85
- }
86
- }
87
- if (opts.mask && opts.mask.mask !== undefined && typeof opts.mask.mask !== "function") {
88
- ms = generateMask(opts.mask.mask, opts.mask, opts);
89
- } else {
90
- ms = generateMask(opts.mask, opts.mask, opts);
91
- }
92
- if (opts.keepStatic === null) opts.keepStatic = false;
93
- return ms;
94
- }
95
-
96
- function analyseMask(mask, regexMask, opts) {
97
- const tokenizer = /(?:[?*+]|\{[0-9+*]+(?:,[0-9+*]*)?(?:\|[0-9+*]*)?\})|[^.?*+^${[]()|\\]+|./g,
98
- //Thx to https://github.com/slevithan/regex-colorizer for the regexTokenizer regex
99
- regexTokenizer = /\[\^?]?(?:[^\\\]]+|\\[\S\s]?)*]?|\\(?:0(?:[0-3][0-7]{0,2}|[4-7][0-7]?)?|[1-9][0-9]*|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|c[A-Za-z]|[\S\s]?)|\((?:\?[:=!]?)?|(?:[?*+]|\{[0-9]+(?:,[0-9]*)?\})\??|[^.?*+^${[()|\\]+|./g;
100
- var escaped = false,
101
- currentToken = new MaskToken(),
102
- match,
103
- m,
104
- openenings = [],
105
- maskTokens = [],
106
- openingToken,
107
- currentOpeningToken,
108
- alternator,
109
- lastMatch,
110
- closeRegexGroup = false;
111
-
112
- //test definition => {fn: RegExp/function, static: true/false optionality: bool, newBlockMarker: bool, casing: null/upper/lower, def: definitionSymbol, placeholder: placeholder, mask: real maskDefinition}
113
- function insertTestDefinition(mtoken, element, position) {
114
- position = position !== undefined ? position : mtoken.matches.length;
115
- var prevMatch = mtoken.matches[position - 1];
116
- if (regexMask) {
117
- if (element.indexOf("[") === 0 || (escaped && /\\d|\\s|\\w/i.test(element)) || element === ".") {
118
- mtoken.matches.splice(position++, 0, {
119
- fn: new RegExp(element, opts.casing ? "i" : ""),
120
- static: false,
121
- optionality: false,
122
- newBlockMarker: prevMatch === undefined ? "master" : prevMatch.def !== element,
123
- casing: null,
124
- def: element,
125
- placeholder: undefined,
126
- nativeDef: element
127
- });
128
- } else {
129
- if (escaped) element = element[element.length - 1];
130
- element.split("").forEach(function (lmnt, ndx) {
131
- prevMatch = mtoken.matches[position - 1];
132
- mtoken.matches.splice(position++, 0, {
133
- fn: /[a-z]/i.test((opts.staticDefinitionSymbol || lmnt)) ? new RegExp("[" + (opts.staticDefinitionSymbol || lmnt) + "]", opts.casing ? "i" : "") : null,
134
- static: true,
135
- optionality: false,
136
- newBlockMarker: prevMatch === undefined ? "master" : (prevMatch.def !== lmnt && prevMatch.static !== true),
137
- casing: null,
138
- def: opts.staticDefinitionSymbol || lmnt,
139
- placeholder: opts.staticDefinitionSymbol !== undefined ? lmnt : undefined,
140
- nativeDef: (escaped ? "'" : "") + lmnt
141
- });
142
- });
143
- }
144
- escaped = false;
145
- } else {
146
- var maskdef = (opts.definitions && opts.definitions[element]) || (opts.usePrototypeDefinitions && Inputmask.prototype.definitions[element]);
147
- if (maskdef && !escaped) {
148
- mtoken.matches.splice(position++, 0, {
149
- fn: maskdef.validator ? typeof maskdef.validator == "string" ? new RegExp(maskdef.validator, opts.casing ? "i" : "") : new function () {
150
- this.test = maskdef.validator;
151
- } : new RegExp("."),
152
- static: maskdef.static || false,
153
- optionality: maskdef.optional || false,
154
- newBlockMarker: (prevMatch === undefined || maskdef.optional) ? "master" : prevMatch.def !== (maskdef.definitionSymbol || element),
155
- casing: maskdef.casing,
156
- def: maskdef.definitionSymbol || element,
157
- placeholder: maskdef.placeholder,
158
- nativeDef: element,
159
- generated: maskdef.generated
160
- });
161
- } else {
162
- mtoken.matches.splice(position++, 0, {
163
- fn: /[a-z]/i.test((opts.staticDefinitionSymbol || element)) ? new RegExp("[" + (opts.staticDefinitionSymbol || element) + "]", opts.casing ? "i" : "") : null,
164
- static: true,
165
- optionality: false,
166
- newBlockMarker: prevMatch === undefined ? "master" : (prevMatch.def !== element && prevMatch.static !== true),
167
- casing: null,
168
- def: opts.staticDefinitionSymbol || element,
169
- placeholder: opts.staticDefinitionSymbol !== undefined ? element : undefined,
170
- nativeDef: (escaped ? "'" : "") + element
171
- });
172
- escaped = false;
173
- }
174
- }
175
- }
176
-
177
- function verifyGroupMarker(maskToken) {
178
- if (maskToken && maskToken.matches) {
179
- maskToken.matches.forEach(function (token, ndx) {
180
- var nextToken = maskToken.matches[ndx + 1];
181
- if ((nextToken === undefined || (nextToken.matches === undefined || nextToken.isQuantifier === false)) && token && token.isGroup) { //this is not a group but a normal mask => convert
182
- token.isGroup = false;
183
- if (!regexMask) {
184
- insertTestDefinition(token, opts.groupmarker[0], 0);
185
- if (token.openGroup !== true) {
186
- insertTestDefinition(token, opts.groupmarker[1]);
187
- }
188
- }
189
- }
190
- verifyGroupMarker(token);
191
- });
192
- }
193
- }
194
-
195
- function defaultCase() {
196
- if (openenings.length > 0) {
197
- currentOpeningToken = openenings[openenings.length - 1];
198
- insertTestDefinition(currentOpeningToken, m);
199
- if (currentOpeningToken.isAlternator) { //handle alternator a | b case
200
- alternator = openenings.pop();
201
- for (var mndx = 0; mndx < alternator.matches.length; mndx++) {
202
- if (alternator.matches[mndx].isGroup) alternator.matches[mndx].isGroup = false; //don't mark alternate groups as group
203
- }
204
- if (openenings.length > 0) {
205
- currentOpeningToken = openenings[openenings.length - 1];
206
- currentOpeningToken.matches.push(alternator);
207
- } else {
208
- currentToken.matches.push(alternator);
209
- }
210
- }
211
- } else {
212
- insertTestDefinition(currentToken, m);
213
- }
214
- }
215
-
216
- function reverseTokens(maskToken) {
217
- function reverseStatic(st) {
218
- if (st === opts.optionalmarker[0]) {
219
- st = opts.optionalmarker[1];
220
- } else if (st === opts.optionalmarker[1]) {
221
- st = opts.optionalmarker[0];
222
- } else if (st === opts.groupmarker[0]) {
223
- st = opts.groupmarker[1];
224
- } else if (st === opts.groupmarker[1]) st = opts.groupmarker[0];
225
-
226
- return st;
227
- }
228
-
229
- maskToken.matches = maskToken.matches.reverse();
230
- for (var match in maskToken.matches) {
231
- if (Object.prototype.hasOwnProperty.call(maskToken.matches, match)) {
232
- var intMatch = parseInt(match);
233
- if (maskToken.matches[match].isQuantifier && maskToken.matches[intMatch + 1] && maskToken.matches[intMatch + 1].isGroup) { //reposition quantifier
234
- var qt = maskToken.matches[match];
235
- maskToken.matches.splice(match, 1);
236
- maskToken.matches.splice(intMatch + 1, 0, qt);
237
- }
238
- if (maskToken.matches[match].matches !== undefined) {
239
- maskToken.matches[match] = reverseTokens(maskToken.matches[match]);
240
- } else {
241
- maskToken.matches[match] = reverseStatic(maskToken.matches[match]);
242
- }
243
- }
244
- }
245
-
246
- return maskToken;
247
- }
248
-
249
- function groupify(matches) {
250
- var groupToken = new MaskToken(true);
251
- groupToken.openGroup = false;
252
- groupToken.matches = matches;
253
- return groupToken;
254
- }
255
-
256
- function closeGroup() {
257
- // Group closing
258
- openingToken = openenings.pop();
259
- openingToken.openGroup = false; //mark group as complete
260
- if (openingToken !== undefined) {
261
- if (openenings.length > 0) {
262
- currentOpeningToken = openenings[openenings.length - 1];
263
- currentOpeningToken.matches.push(openingToken);
264
- if (currentOpeningToken.isAlternator) { //handle alternator (a) | (b) case
265
- alternator = openenings.pop();
266
- let altMatchesLength = alternator.matches[0].matches ? alternator.matches[0].matches.length : 1;
267
- for (var mndx = 0; mndx < alternator.matches.length; mndx++) {
268
- alternator.matches[mndx].isGroup = false; //don't mark alternate groups as group
269
- alternator.matches[mndx].alternatorGroup = false;
270
- if (opts.keepStatic === null && altMatchesLength < (alternator.matches[mndx].matches ? alternator.matches[mndx].matches.length : 1)) { //enable by default when passing multiple masks when the option is not explicitly specified
271
- opts.keepStatic = true;
272
- }
273
- altMatchesLength = alternator.matches[mndx].matches ? alternator.matches[mndx].matches.length : 1;
274
- }
275
- if (openenings.length > 0) {
276
- currentOpeningToken = openenings[openenings.length - 1];
277
- currentOpeningToken.matches.push(alternator);
278
- } else {
279
- currentToken.matches.push(alternator);
280
- }
281
- }
282
- } else {
283
- currentToken.matches.push(openingToken);
284
- }
285
- } else {
286
- defaultCase();
287
- }
288
- }
289
-
290
- function groupQuantifier(matches) {
291
- var lastMatch = matches.pop();
292
- if (lastMatch.isQuantifier) {
293
- lastMatch = groupify([matches.pop(), lastMatch]);
294
- }
295
- return lastMatch;
296
- }
297
-
298
- if (regexMask) {
299
- opts.optionalmarker[0] = undefined;
300
- opts.optionalmarker[1] = undefined;
301
- }
302
- while ((match = regexMask ? regexTokenizer.exec(mask) : tokenizer.exec(mask))) {
303
- m = match[0];
304
-
305
- if (regexMask) {
306
- switch (m.charAt(0)) {
307
- //Quantifier
308
- case "?":
309
- m = "{0,1}";
310
- break;
311
- case "+":
312
- case "*":
313
- m = "{" + m + "}";
314
- break;
315
- case "|":
316
- //regex mask alternator ex: [01][0-9]|2[0-3] => ([01][0-9]|2[0-3])
317
- if (openenings.length === 0) { //wrap the mask in a group to form a regex alternator ([01][0-9]|2[0-3])
318
- var altRegexGroup = groupify(currentToken.matches);
319
- altRegexGroup.openGroup = true;
320
- openenings.push(altRegexGroup);
321
- currentToken.matches = [];
322
- closeRegexGroup = true;
323
- }
324
- break;
325
- }
326
- switch (m) {
327
- case "\\d":
328
- m = "[0-9]";
329
- break;
330
- case "(?=": //lookahead
331
- // openenings.push(new MaskToken(true));
332
- break;
333
- case "(?!": //negative lookahead
334
- // openenings.push(new MaskToken(true));
335
- break;
336
- case "(?<=": //lookbehind
337
- // openenings.push(new MaskToken(true));
338
- break;
339
- case "(?<!": //negative lookbehind
340
- // openenings.push(new MaskToken(true));
341
- break;
342
- }
343
- }
344
-
345
- if (escaped) {
346
- defaultCase();
347
- continue;
348
- }
349
- switch (m.charAt(0)) {
350
- case "$":
351
- case "^":
352
- //ignore beginswith and endswith as in masking this makes no point
353
- if (!regexMask) {
354
- defaultCase();
355
- }
356
- break;
357
- case opts.escapeChar:
358
- escaped = true;
359
- if (regexMask) defaultCase();
360
- break;
361
- // optional closing
362
- case opts.optionalmarker[1]:
363
- case opts.groupmarker[1]:
364
- closeGroup();
365
- break;
366
- case opts.optionalmarker[0]:
367
- // optional opening
368
- openenings.push(new MaskToken(false, true));
369
- break;
370
- case opts.groupmarker[0]:
371
- // Group opening
372
- openenings.push(new MaskToken(true));
373
- break;
374
- case opts.quantifiermarker[0]:
375
- //Quantifier
376
- var quantifier = new MaskToken(false, false, true);
377
-
378
- m = m.replace(/[{}?]/g, ""); //? matches lazy quantifiers
379
- var mqj = m.split("|"),
380
- mq = mqj[0].split(","),
381
- mq0 = isNaN(mq[0]) ? mq[0] : parseInt(mq[0]),
382
- mq1 = mq.length === 1 ? mq0 : (isNaN(mq[1]) ? mq[1] : parseInt(mq[1])),
383
- mqJit = isNaN(mqj[1]) ? mqj[1] : parseInt(mqj[1]);
384
- if (mq0 === "*" || mq0 === "+") {
385
- mq0 = mq1 === "*" ? 0 : 1;
386
- }
387
- quantifier.quantifier = {
388
- min: mq0,
389
- max: mq1,
390
- jit: mqJit
391
- };
392
- var matches = openenings.length > 0 ? openenings[openenings.length - 1].matches : currentToken.matches;
393
- match = matches.pop();
394
- if (match.isAlternator) { //handle quantifier in an alternation [0-9]{2}|[0-9]{3}
395
- matches.push(match); //push back alternator
396
- matches = match.matches; //remap target matches
397
- var groupToken = new MaskToken(true);
398
- var tmpMatch = matches.pop();
399
- matches.push(groupToken); //push the group
400
- matches = groupToken.matches;
401
- match = tmpMatch;
402
- }
403
- if (!match.isGroup) {
404
- // if (regexMask && match.fn === null) { //why is this needed???
405
- // if (match.def === ".") match.fn = new RegExp(match.def, opts.casing ? "i" : "");
406
- // }
407
-
408
- match = groupify([match]);
409
- }
410
- matches.push(match);
411
- matches.push(quantifier);
412
-
413
- break;
414
- case opts.alternatormarker:
415
- if (openenings.length > 0) {
416
- currentOpeningToken = openenings[openenings.length - 1];
417
- var subToken = currentOpeningToken.matches[currentOpeningToken.matches.length - 1];
418
- if (currentOpeningToken.openGroup && //regexp alt syntax
419
- (subToken.matches === undefined || (subToken.isGroup === false && subToken.isAlternator === false))) { //alternations within group
420
- lastMatch = openenings.pop();
421
- } else {
422
- lastMatch = groupQuantifier(currentOpeningToken.matches);
423
- }
424
- } else {
425
- lastMatch = groupQuantifier(currentToken.matches);
426
- }
427
- if (lastMatch.isAlternator) {
428
- openenings.push(lastMatch);
429
- } else {
430
- if (lastMatch.alternatorGroup) {
431
- alternator = openenings.pop();
432
- lastMatch.alternatorGroup = false;
433
- } else {
434
- alternator = new MaskToken(false, false, false, true);
435
- }
436
- alternator.matches.push(lastMatch);
437
- openenings.push(alternator);
438
- if (lastMatch.openGroup) { //regexp alt syntax
439
- lastMatch.openGroup = false;
440
- var alternatorGroup = new MaskToken(true);
441
- alternatorGroup.alternatorGroup = true;
442
- openenings.push(alternatorGroup);
443
- }
444
- }
445
- break;
446
- default:
447
- defaultCase();
448
- }
449
- }
450
-
451
- if (closeRegexGroup) closeGroup();
452
-
453
- while (openenings.length > 0) {
454
- openingToken = openenings.pop();
455
- currentToken.matches.push(openingToken);
456
- }
457
- if (currentToken.matches.length > 0) {
458
- verifyGroupMarker(currentToken);
459
- maskTokens.push(currentToken);
460
- }
461
-
462
- if (opts.numericInput || opts.isRTL) {
463
- reverseTokens(maskTokens[0]);
464
- }
465
- // console.log(JSON.stringify(maskTokens));
466
- return maskTokens;
467
- }