use-mask-input 1.0.1 → 2.0.0

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