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.
- package/dist/example/App.example.d.ts +3 -0
- package/dist/{useMaskInput.test.d.ts → example/index.d.ts} +0 -0
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +1 -2
- package/dist/index.modern.js.map +1 -1
- package/dist/useMaskInput.d.ts +3 -3
- package/node_modules/inputmask/README.md +94 -61
- package/node_modules/inputmask/dist/inputmask.es6.js +5 -0
- package/node_modules/inputmask/dist/inputmask.js +2900 -2868
- package/node_modules/inputmask/dist/inputmask.min.js +3 -3
- package/node_modules/inputmask/dist/jquery.inputmask.js +2840 -2807
- package/node_modules/inputmask/dist/jquery.inputmask.min.js +3 -3
- package/node_modules/inputmask/lib/bindings/inputmask.es6.js +5 -0
- package/node_modules/inputmask/lib/canUseDOM.js +7 -0
- package/node_modules/inputmask/lib/defaults.js +36 -2
- package/node_modules/inputmask/lib/definitions.js +1 -1
- package/node_modules/inputmask/lib/dependencyLibs/events.js +19 -9
- package/node_modules/inputmask/lib/environment.js +2 -0
- package/node_modules/inputmask/lib/eventhandlers.js +55 -44
- package/node_modules/inputmask/lib/eventruler.js +10 -9
- package/node_modules/inputmask/lib/extensions/inputmask.date.extensions.js +543 -430
- package/node_modules/inputmask/lib/extensions/inputmask.extensions.js +117 -99
- package/node_modules/inputmask/lib/extensions/inputmask.numeric.extensions.js +590 -574
- package/node_modules/inputmask/lib/global/window.js +2 -1
- package/node_modules/inputmask/lib/inputHandling.js +30 -18
- package/node_modules/inputmask/lib/inputmask.js +9 -2
- package/node_modules/inputmask/lib/inputmaskElement.js +2 -1
- package/node_modules/inputmask/lib/keycode.json +4 -0
- package/node_modules/inputmask/lib/mask-lexer.js +434 -436
- package/node_modules/inputmask/lib/mask.js +4 -4
- package/node_modules/inputmask/lib/masktoken.js +13 -0
- package/node_modules/inputmask/lib/polyfills/Array.includes.js +48 -0
- package/node_modules/inputmask/lib/{getPrototypeOf.js → polyfills/Object.getPrototypeOf.js} +0 -0
- package/node_modules/inputmask/lib/positioning.js +5 -5
- package/node_modules/inputmask/lib/validation-tests.js +108 -46
- package/node_modules/inputmask/lib/validation.js +82 -73
- package/node_modules/inputmask/package.json +41 -69
- package/package.json +40 -38
- package/node_modules/inputmask/CHANGELOG.md +0 -744
- package/node_modules/inputmask/index.js +0 -1
- 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
|
-
|
|
8
|
+
var ms;
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
+
return masksetDefinition;
|
|
59
|
+
}
|
|
58
60
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
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
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
|
|
260
|
-
|
|
226
|
+
return st;
|
|
227
|
+
}
|
|
261
228
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
|
|
270
|
-
|
|
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
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
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
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
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
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
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
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
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
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
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
|
-
|
|
414
|
-
|
|
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
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
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
|
-
|
|
451
|
+
if (closeRegexGroup) closeGroup();
|
|
454
452
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
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
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
462
|
+
if (opts.numericInput || opts.isRTL) {
|
|
463
|
+
reverseTokens(maskTokens[0]);
|
|
464
|
+
}
|
|
465
|
+
// console.log(JSON.stringify(maskTokens));
|
|
466
|
+
return maskTokens;
|
|
469
467
|
}
|