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