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
@@ -7,609 +7,625 @@
7
7
  import Inputmask from "../inputmask";
8
8
  import keyCode from "../keycode.json";
9
9
  import escapeRegex from "../escapeRegex";
10
+ import {seekNext} from "../positioning";
10
11
 
11
12
  const $ = Inputmask.dependencyLib;
12
13
 
13
14
  function autoEscape(txt, opts) {
14
- var escapedTxt = "";
15
- for (var i = 0; i < txt.length; i++) {
16
- if (Inputmask.prototype.definitions[txt.charAt(i)] ||
17
- opts.definitions[txt.charAt(i)] ||
18
- opts.optionalmarker[0] === txt.charAt(i) ||
19
- opts.optionalmarker[1] === txt.charAt(i) ||
20
- opts.quantifiermarker[0] === txt.charAt(i) ||
21
- opts.quantifiermarker[1] === txt.charAt(i) ||
22
- opts.groupmarker[0] === txt.charAt(i) ||
23
- opts.groupmarker[1] === txt.charAt(i) ||
24
- opts.alternatormarker === txt.charAt(i)) {
25
- escapedTxt += "\\" + txt.charAt(i);
26
- } else {
27
- escapedTxt += txt.charAt(i);
28
- }
29
- }
30
- return escapedTxt;
15
+ var escapedTxt = "";
16
+ for (var i = 0; i < txt.length; i++) {
17
+ if (Inputmask.prototype.definitions[txt.charAt(i)] ||
18
+ opts.definitions[txt.charAt(i)] ||
19
+ opts.optionalmarker[0] === txt.charAt(i) ||
20
+ opts.optionalmarker[1] === txt.charAt(i) ||
21
+ opts.quantifiermarker[0] === txt.charAt(i) ||
22
+ opts.quantifiermarker[1] === txt.charAt(i) ||
23
+ opts.groupmarker[0] === txt.charAt(i) ||
24
+ opts.groupmarker[1] === txt.charAt(i) ||
25
+ opts.alternatormarker === txt.charAt(i)) {
26
+ escapedTxt += "\\" + txt.charAt(i);
27
+ } else {
28
+ escapedTxt += txt.charAt(i);
29
+ }
30
+ }
31
+ return escapedTxt;
31
32
  }
32
33
 
33
34
  function alignDigits(buffer, digits, opts, force) {
34
- if (buffer.length > 0 && digits > 0 && (!opts.digitsOptional || force)) {
35
- var radixPosition = buffer.indexOf(opts.radixPoint), negationBack = false;
36
- if (opts.negationSymbol.back === buffer[buffer.length - 1]) {
37
- negationBack = true;
38
- buffer.length--;
39
- }
40
-
41
- if (radixPosition === -1) {
42
- buffer.push(opts.radixPoint);
43
- radixPosition = buffer.length - 1;
44
- }
45
- for (var i = 1; i <= digits; i++) {
46
- if (!isFinite(buffer[radixPosition + i])) {
47
- buffer[radixPosition + i] = "0";
48
- }
49
- }
50
- }
51
-
52
- if (negationBack)
53
- buffer.push(opts.negationSymbol.back);
54
- return buffer;
35
+ if (buffer.length > 0 && digits > 0 && (!opts.digitsOptional || force)) {
36
+ var radixPosition = buffer.indexOf(opts.radixPoint), negationBack = false;
37
+ if (opts.negationSymbol.back === buffer[buffer.length - 1]) {
38
+ negationBack = true;
39
+ buffer.length--;
40
+ }
41
+
42
+ if (radixPosition === -1) {
43
+ buffer.push(opts.radixPoint);
44
+ radixPosition = buffer.length - 1;
45
+ }
46
+ for (var i = 1; i <= digits; i++) {
47
+ if (!isFinite(buffer[radixPosition + i])) {
48
+ buffer[radixPosition + i] = "0";
49
+ }
50
+ }
51
+ }
52
+
53
+ if (negationBack)
54
+ buffer.push(opts.negationSymbol.back);
55
+ return buffer;
55
56
  }
56
57
 
57
58
  function findValidator(symbol, maskset) {
58
- var posNdx = 0;
59
- if (symbol === "+") {
60
- for (posNdx in maskset.validPositions) ;
61
- posNdx = parseInt(posNdx);
62
- }
63
- for (var tstNdx in maskset.tests) {
64
- tstNdx = parseInt(tstNdx);
65
- if (tstNdx >= posNdx) {
66
- for (var ndx = 0, ndxl = maskset.tests[tstNdx].length; ndx < ndxl; ndx++) {
67
- if ((maskset.validPositions[tstNdx] === undefined || symbol === "-") && maskset.tests[tstNdx][ndx].match.def === symbol) {
68
- return tstNdx + ((maskset.validPositions[tstNdx] !== undefined && symbol !== "-") ? 1 : 0);
69
- }
70
- }
71
- }
72
- }
73
- return posNdx;
59
+ var posNdx = 0;
60
+ if (symbol === "+") {
61
+ for (posNdx in maskset.validPositions) ;
62
+ posNdx = seekNext.call(this, parseInt(posNdx));
63
+ }
64
+ for (var tstNdx in maskset.tests) {
65
+ tstNdx = parseInt(tstNdx);
66
+ if (tstNdx >= posNdx) {
67
+ for (var ndx = 0, ndxl = maskset.tests[tstNdx].length; ndx < ndxl; ndx++) {
68
+ if ((maskset.validPositions[tstNdx] === undefined || symbol === "-") && maskset.tests[tstNdx][ndx].match.def === symbol) {
69
+ return tstNdx + ((maskset.validPositions[tstNdx] !== undefined && symbol !== "-") ? 1 : 0);
70
+ }
71
+ }
72
+ }
73
+ }
74
+ return posNdx;
74
75
  }
75
76
 
76
77
  function findValid(symbol, maskset) {
77
- var ret = -1;
78
- for (let ndx in maskset.validPositions) {
79
- let tst = maskset.validPositions[ndx];
80
- if (tst && tst.match.def === symbol) {
81
- ret = parseInt(ndx);
82
- break;
83
- }
84
- }
85
- return ret;
78
+ var ret = -1;
79
+ for (let ndx in maskset.validPositions) {
80
+ let tst = maskset.validPositions[ndx];
81
+ if (tst && tst.match.def === symbol) {
82
+ ret = parseInt(ndx);
83
+ break;
84
+ }
85
+ }
86
+ return ret;
86
87
  }
87
88
 
88
89
  function parseMinMaxOptions(opts) {
89
- if (opts.parseMinMaxOptions === undefined) {
90
- // convert min and max options
91
- if (opts.min !== null) {
92
- opts.min = opts.min.toString().replace(new RegExp(escapeRegex(opts.groupSeparator), "g"), "");
93
- if (opts.radixPoint === ",") opts.min = opts.min.replace(opts.radixPoint, ".");
94
- opts.min = isFinite(opts.min) ? parseFloat(opts.min) : NaN;
95
- if (isNaN(opts.min)) opts.min = Number.MIN_VALUE;
96
- }
97
- if (opts.max !== null) {
98
- opts.max = opts.max.toString().replace(new RegExp(escapeRegex(opts.groupSeparator), "g"), "");
99
- if (opts.radixPoint === ",") opts.max = opts.max.replace(opts.radixPoint, ".");
100
- opts.max = isFinite(opts.max) ? parseFloat(opts.max) : NaN;
101
- if (isNaN(opts.max)) opts.max = Number.MAX_VALUE;
102
- }
103
- opts.parseMinMaxOptions = "done";
104
- }
90
+ if (opts.parseMinMaxOptions === undefined) {
91
+ // convert min and max options
92
+ if (opts.min !== null) {
93
+ opts.min = opts.min.toString().replace(new RegExp(escapeRegex(opts.groupSeparator), "g"), "");
94
+ if (opts.radixPoint === ",") opts.min = opts.min.replace(opts.radixPoint, ".");
95
+ opts.min = isFinite(opts.min) ? parseFloat(opts.min) : NaN;
96
+ if (isNaN(opts.min)) opts.min = Number.MIN_VALUE;
97
+ }
98
+ if (opts.max !== null) {
99
+ opts.max = opts.max.toString().replace(new RegExp(escapeRegex(opts.groupSeparator), "g"), "");
100
+ if (opts.radixPoint === ",") opts.max = opts.max.replace(opts.radixPoint, ".");
101
+ opts.max = isFinite(opts.max) ? parseFloat(opts.max) : NaN;
102
+ if (isNaN(opts.max)) opts.max = Number.MAX_VALUE;
103
+ }
104
+ opts.parseMinMaxOptions = "done";
105
+ }
105
106
  }
106
107
 
107
108
  function genMask(opts) {
108
- opts.repeat = 0;
109
- //treat equal separator and radixpoint
110
- if (opts.groupSeparator === opts.radixPoint && opts.digits && opts.digits !== "0") {
111
- if (opts.radixPoint === ".") {
112
- opts.groupSeparator = ",";
113
- } else if (opts.radixPoint === ",") {
114
- opts.groupSeparator = ".";
115
- } else {
116
- opts.groupSeparator = "";
117
- }
118
- }
119
- //prevent conflict with default skipOptionalPartCharacter
120
- if (opts.groupSeparator === " ") {
121
- opts.skipOptionalPartCharacter = undefined;
122
- }
123
-
124
- //enforce placeholder to single
125
- if (opts.placeholder.length > 1) {
126
- opts.placeholder = opts.placeholder.charAt(0);
127
- }
128
- //only allow radixfocus when placeholder = 0
129
- if (opts.positionCaretOnClick === "radixFocus" && opts.placeholder === "") {
130
- opts.positionCaretOnClick = "lvp";
131
- }
132
-
133
- var decimalDef = "0", radixPointDef = opts.radixPoint;
134
- if (opts.numericInput === true && opts.__financeInput === undefined) { //finance people input style
135
- decimalDef = "1";
136
- opts.positionCaretOnClick = opts.positionCaretOnClick === "radixFocus" ? "lvp" : opts.positionCaretOnClick;
137
- opts.digitsOptional = false;
138
- if (isNaN(opts.digits)) opts.digits = 2;
139
- opts._radixDance = false;
140
- radixPointDef = (opts.radixPoint === "," ? "?" : "!");
141
- if (opts.radixPoint !== "" && opts.definitions[radixPointDef] === undefined) {
142
- //update separator definition
143
- opts.definitions[radixPointDef] = {};
144
- opts.definitions[radixPointDef].validator = "[" + opts.radixPoint + "]";
145
- opts.definitions[radixPointDef].placeholder = opts.radixPoint;
146
- opts.definitions[radixPointDef].static = true;
147
- opts.definitions[radixPointDef].generated = true; //forced marker as generated input
148
- }
149
- } else {
150
- opts.__financeInput = false; //needed to keep original selection when remasking
151
- opts.numericInput = true;
152
- }
153
-
154
- var mask = "[+]", altMask;
155
- mask += autoEscape(opts.prefix, opts);
156
- if (opts.groupSeparator !== "") {
157
- if (opts.definitions[opts.groupSeparator] === undefined) {
158
- //update separatot definition
159
- opts.definitions[opts.groupSeparator] = {};
160
- opts.definitions[opts.groupSeparator].validator = "[" + opts.groupSeparator + "]";
161
- opts.definitions[opts.groupSeparator].placeholder = opts.groupSeparator;
162
- opts.definitions[opts.groupSeparator].static = true;
163
- opts.definitions[opts.groupSeparator].generated = true; //forced marker as generated input
164
- }
165
- mask += opts._mask(opts);
166
- } else {
167
- mask += "9{+}";
168
- }
169
- if (opts.digits !== undefined && opts.digits !== 0) {
170
- var dq = opts.digits.toString().split(",");
171
- if (isFinite(dq[0]) && dq[1] && isFinite(dq[1])) {
172
- mask += radixPointDef + decimalDef + "{" + opts.digits + "}";
173
- } else if (isNaN(opts.digits) || parseInt(opts.digits) > 0) {
174
- if (opts.digitsOptional) {
175
- altMask = mask + radixPointDef + decimalDef + "{0," + opts.digits + "}";
176
- // mask += "[" + opts.radixPoint + "]";
177
- opts.keepStatic = true;
178
- } else {
179
- mask += radixPointDef + decimalDef + "{" + opts.digits + "}";
180
- }
181
- }
182
- }
183
- mask += autoEscape(opts.suffix, opts);
184
- mask += "[-]";
185
-
186
- if (altMask) {
187
- mask = [(altMask + autoEscape(opts.suffix, opts) + "[-]"), mask];
188
- }
189
-
190
-
191
- opts.greedy = false; //enforce greedy false
192
-
193
- parseMinMaxOptions(opts);
194
-
195
- // console.log(mask);
196
- return mask;
109
+ opts.repeat = 0;
110
+ //treat equal separator and radixpoint
111
+ if (opts.groupSeparator === opts.radixPoint && opts.digits && opts.digits !== "0") {
112
+ if (opts.radixPoint === ".") {
113
+ opts.groupSeparator = ",";
114
+ } else if (opts.radixPoint === ",") {
115
+ opts.groupSeparator = ".";
116
+ } else {
117
+ opts.groupSeparator = "";
118
+ }
119
+ }
120
+ //prevent conflict with default skipOptionalPartCharacter
121
+ if (opts.groupSeparator === " ") {
122
+ opts.skipOptionalPartCharacter = undefined;
123
+ }
124
+
125
+ //enforce placeholder to single
126
+ if (opts.placeholder.length > 1) {
127
+ opts.placeholder = opts.placeholder.charAt(0);
128
+ }
129
+ //only allow radixfocus when placeholder = 0
130
+ if (opts.positionCaretOnClick === "radixFocus" && opts.placeholder === "") {
131
+ opts.positionCaretOnClick = "lvp";
132
+ }
133
+
134
+ var decimalDef = "0", radixPointDef = opts.radixPoint;
135
+ if (opts.numericInput === true && opts.__financeInput === undefined) { //finance people input style
136
+ decimalDef = "1";
137
+ opts.positionCaretOnClick = opts.positionCaretOnClick === "radixFocus" ? "lvp" : opts.positionCaretOnClick;
138
+ opts.digitsOptional = false;
139
+ if (isNaN(opts.digits)) opts.digits = 2;
140
+ opts._radixDance = false;
141
+ radixPointDef = (opts.radixPoint === "," ? "?" : "!");
142
+ if (opts.radixPoint !== "" && opts.definitions[radixPointDef] === undefined) {
143
+ //update separator definition
144
+ opts.definitions[radixPointDef] = {};
145
+ opts.definitions[radixPointDef].validator = "[" + opts.radixPoint + "]";
146
+ opts.definitions[radixPointDef].placeholder = opts.radixPoint;
147
+ opts.definitions[radixPointDef].static = true;
148
+ opts.definitions[radixPointDef].generated = true; //forced marker as generated input
149
+ }
150
+ } else {
151
+ opts.__financeInput = false; //needed to keep original selection when remasking
152
+ opts.numericInput = true;
153
+ }
154
+
155
+ var mask = "[+]", altMask;
156
+ mask += autoEscape(opts.prefix, opts);
157
+ if (opts.groupSeparator !== "") {
158
+ if (opts.definitions[opts.groupSeparator] === undefined) {
159
+ //update separatot definition
160
+ opts.definitions[opts.groupSeparator] = {};
161
+ opts.definitions[opts.groupSeparator].validator = "[" + opts.groupSeparator + "]";
162
+ opts.definitions[opts.groupSeparator].placeholder = opts.groupSeparator;
163
+ opts.definitions[opts.groupSeparator].static = true;
164
+ opts.definitions[opts.groupSeparator].generated = true; //forced marker as generated input
165
+ }
166
+ mask += opts._mask(opts);
167
+ } else {
168
+ mask += "9{+}";
169
+ }
170
+ if (opts.digits !== undefined && opts.digits !== 0) {
171
+ var dq = opts.digits.toString().split(",");
172
+ if (isFinite(dq[0]) && dq[1] && isFinite(dq[1])) {
173
+ mask += radixPointDef + decimalDef + "{" + opts.digits + "}";
174
+ } else if (isNaN(opts.digits) || parseInt(opts.digits) > 0) {
175
+ if (opts.digitsOptional || opts.jitMasking) {
176
+ altMask = mask + radixPointDef + decimalDef + "{0," + opts.digits + "}";
177
+ // mask += "[" + opts.radixPoint + "]";
178
+ opts.keepStatic = true;
179
+ } else {
180
+ mask += radixPointDef + decimalDef + "{" + opts.digits + "}";
181
+ }
182
+ }
183
+ } else {
184
+ opts.inputmode = "numeric";
185
+ }
186
+ mask += autoEscape(opts.suffix, opts);
187
+ mask += "[-]";
188
+
189
+ if (altMask) {
190
+ mask = [(altMask + autoEscape(opts.suffix, opts) + "[-]"), mask];
191
+ }
192
+
193
+
194
+ opts.greedy = false; //enforce greedy false
195
+
196
+ parseMinMaxOptions(opts);
197
+ if (opts.radixPoint !== "")
198
+ opts.substitutes[opts.radixPoint == "." ? "," : "."] = opts.radixPoint;
199
+ // console.log(mask);
200
+ return mask;
197
201
  }
198
202
 
199
203
  function hanndleRadixDance(pos, c, radixPos, maskset, opts) {
200
- if (opts._radixDance && opts.numericInput && c !== opts.negationSymbol.back) {
201
- if (pos <= radixPos && (radixPos > 0 || c == opts.radixPoint) && (maskset.validPositions[pos - 1] === undefined || maskset.validPositions[pos - 1].input !== opts.negationSymbol.back)) {
202
- pos -= 1;
203
- }
204
- }
205
- return pos;
204
+ if (opts._radixDance && opts.numericInput && c !== opts.negationSymbol.back) {
205
+ if (pos <= radixPos && (radixPos > 0 || c == opts.radixPoint) && (maskset.validPositions[pos - 1] === undefined || maskset.validPositions[pos - 1].input !== opts.negationSymbol.back)) {
206
+ pos -= 1;
207
+ }
208
+ }
209
+ return pos;
206
210
  }
207
211
 
208
212
  function decimalValidator(chrs, maskset, pos, strict, opts) {
209
- var radixPos = maskset.buffer ? maskset.buffer.indexOf(opts.radixPoint) : -1,
210
- result = radixPos !== -1 && new RegExp("[0-9\uFF11-\uFF19]").test(chrs);
211
- if (opts._radixDance && result && maskset.validPositions[radixPos] == undefined) {
212
- return {
213
- insert: {
214
- pos: radixPos === pos ? radixPos + 1 : radixPos,
215
- c: opts.radixPoint
216
- },
217
- pos: pos
218
- };
219
- }
220
-
221
- return result;
213
+ var radixPos = maskset.buffer ? maskset.buffer.indexOf(opts.radixPoint) : -1,
214
+ result = (radixPos !== -1 || (strict && opts.jitMasking)) && new RegExp(opts.definitions["9"].validator).test(chrs);
215
+ if (opts._radixDance && radixPos !== -1 && result && maskset.validPositions[radixPos] == undefined) {
216
+ return {
217
+ insert: {
218
+ pos: radixPos === pos ? radixPos + 1 : radixPos,
219
+ c: opts.radixPoint
220
+ },
221
+ pos: pos
222
+ };
223
+ }
224
+
225
+ return result;
222
226
  }
223
227
 
224
228
  function checkForLeadingZeroes(buffer, opts) {
225
- //check leading zeros
226
- var numberMatches = new RegExp("(^" + (opts.negationSymbol.front !== "" ? escapeRegex(opts.negationSymbol.front) + "?" : "") + escapeRegex(opts.prefix) + ")(.*)(" + escapeRegex(opts.suffix) + (opts.negationSymbol.back != "" ? escapeRegex(opts.negationSymbol.back) + "?" : "") + "$)").exec(buffer.slice().reverse().join("")),
227
- number = numberMatches ? numberMatches[2] : "", leadingzeroes = false;
228
- if (number) {
229
- number = number.split(opts.radixPoint.charAt(0))[0];
230
- leadingzeroes = new RegExp("^[0" + opts.groupSeparator + "]*").exec(number);
231
- }
232
- return leadingzeroes && (leadingzeroes[0].length > 1 || leadingzeroes[0].length > 0 && leadingzeroes[0].length < number.length) ? leadingzeroes : false;
229
+ //check leading zeros
230
+ var numberMatches = new RegExp("(^" + (opts.negationSymbol.front !== "" ? escapeRegex(opts.negationSymbol.front) + "?" : "") + escapeRegex(opts.prefix) + ")(.*)(" + escapeRegex(opts.suffix) + (opts.negationSymbol.back != "" ? escapeRegex(opts.negationSymbol.back) + "?" : "") + "$)").exec(buffer.slice().reverse().join("")),
231
+ number = numberMatches ? numberMatches[2] : "", leadingzeroes = false;
232
+ if (number) {
233
+ number = number.split(opts.radixPoint.charAt(0))[0];
234
+ leadingzeroes = new RegExp("^[0" + opts.groupSeparator + "]*").exec(number);
235
+ }
236
+ return leadingzeroes && (leadingzeroes[0].length > 1 || leadingzeroes[0].length > 0 && leadingzeroes[0].length < number.length) ? leadingzeroes : false;
233
237
  }
234
238
 
235
239
  //number aliases
236
240
  Inputmask.extendAliases({
237
- "numeric": {
238
- mask: genMask,
239
- _mask: function (opts) {
240
- return "(" + opts.groupSeparator + "999){+|1}";
241
- },
242
- digits: "*", //number of fractionalDigits
243
- digitsOptional: true,
244
- enforceDigitsOnBlur: false,
245
- radixPoint: ".",
246
- positionCaretOnClick: "radixFocus",
247
- _radixDance: true,
248
- groupSeparator: "",
249
- allowMinus: true,
250
- negationSymbol: {
251
- front: "-", //"("
252
- back: "" //")"
253
- },
254
- prefix: "",
255
- suffix: "",
256
- min: null, //minimum value
257
- max: null, //maximum value
258
- SetMaxOnOverflow: false,
259
- step: 1,
260
- inputType: "text", //number ~ specify that values which are set are in textform (radix point is same as in the options) or in numberform (radixpoint = .)
261
- unmaskAsNumber: false,
262
- roundingFN: Math.round, //Math.floor , fn(x)
263
- inputmode: "numeric",
264
- shortcuts: {k: "000", m: "000000"},
265
- //global options
266
- placeholder: "0",
267
- greedy: false,
268
- rightAlign: true,
269
- insertMode: true,
270
- autoUnmask: false,
271
- skipOptionalPartCharacter: "",
272
- definitions: {
273
- "0": {
274
- validator: decimalValidator
275
- },
276
- "1": {
277
- validator: decimalValidator,
278
- definitionSymbol: "9"
279
- },
280
- "+": {
281
- validator: function (chrs, maskset, pos, strict, opts) {
282
- return (opts.allowMinus && (chrs === "-" || chrs === opts.negationSymbol.front));
283
-
284
- }
285
- },
286
- "-": {
287
- validator: function (chrs, maskset, pos, strict, opts) {
288
- return (opts.allowMinus && chrs === opts.negationSymbol.back);
289
- }
290
- }
291
- },
292
- preValidation: function (buffer, pos, c, isSelection, opts, maskset, caretPos, strict) {
293
- if (opts.__financeInput !== false && c === opts.radixPoint) return false;
294
-
295
- var pattern;
296
- if ((pattern = (opts.shortcuts && opts.shortcuts[c]))) {
297
- if (pattern.length > 1) {
298
- var inserts = [];
299
- for (var i = 0; i < pattern.length; i++) {
300
- inserts.push({pos: pos + i, c: pattern[i], strict: false});
301
- }
302
- }
303
- return {
304
- insert: inserts
305
- };
306
- }
307
-
308
- var radixPos = buffer.indexOf(opts.radixPoint), initPos = pos;
309
- pos = hanndleRadixDance(pos, c, radixPos, maskset, opts);
310
- if (c === "-" || c === opts.negationSymbol.front) {
311
- if (opts.allowMinus !== true) return false;
312
- var isNegative = false,
313
- front = findValid("+", maskset), back = findValid("-", maskset);
314
- if (front !== -1) {
315
- isNegative = [front, back];
316
- }
317
-
318
- return isNegative !== false ? {
319
- remove: isNegative,
320
- caret: initPos - opts.negationSymbol.front.length
321
- } : {
322
- insert: [
323
- {pos: findValidator("+", maskset), c: opts.negationSymbol.front, fromIsValid: true},
324
- {pos: findValidator("-", maskset), c: opts.negationSymbol.back, fromIsValid: undefined}],
325
- caret: initPos + opts.negationSymbol.back.length
326
- };
327
- }
328
-
329
- if (c === opts.groupSeparator) {
330
- return {caret: initPos};
331
- }
332
-
333
- if (strict) return true;
334
- if (radixPos !== -1 && (opts._radixDance === true && isSelection === false && c === opts.radixPoint && (opts.digits !== undefined && (isNaN(opts.digits) || parseInt(opts.digits) > 0)) && radixPos !== pos)) {
335
- return {
336
- "caret": opts._radixDance && pos === radixPos - 1 ? radixPos + 1 : radixPos
337
- };
338
- }
339
- if (opts.__financeInput === false) {
340
- if (isSelection) {
341
- if (opts.digitsOptional) {
342
- return {rewritePosition: caretPos.end};
343
- } else if (!opts.digitsOptional) {
344
- if (caretPos.begin > radixPos && caretPos.end <= radixPos) {
345
- if (c === opts.radixPoint) {
346
- return {
347
- insert: {pos: radixPos + 1, c: "0", fromIsValid: true},
348
- rewritePosition: radixPos
349
- };
350
- } else {
351
- return {rewritePosition: radixPos + 1};
352
- }
353
- } else if (caretPos.begin < radixPos) {
354
- return {rewritePosition: caretPos.begin - 1};
355
- }
356
- }
357
- } else if (!opts.showMaskOnHover && !opts.showMaskOnFocus && !opts.digitsOptional && opts.digits > 0 && this.inputmask.__valueGet.call(this) === "") {
358
- return {rewritePosition: radixPos};
359
- }
360
- }
361
- return {rewritePosition: pos};
362
- },
363
- postValidation: function (buffer, pos, c, currentResult, opts, maskset, strict) {
364
- if (currentResult === false) return currentResult;
365
- if (strict) return true;
366
- if (opts.min !== null || opts.max !== null) {
367
- var unmasked = opts.onUnMask(buffer.slice().reverse().join(""), undefined, $.extend({}, opts, {
368
- unmaskAsNumber: true
369
- }));
370
- if (opts.min !== null && unmasked < opts.min && (unmasked.toString().length > opts.min.toString().length || unmasked < 0)) {
371
- return false;
372
- // return {
373
- // refreshFromBuffer: true,
374
- // buffer: alignDigits(opts.min.toString().replace(".", opts.radixPoint).split(""), opts.digits, opts).reverse()
375
- // };
376
- }
377
-
378
- if (opts.max !== null && unmasked > opts.max) {
379
- return opts.SetMaxOnOverflow ? {
380
- refreshFromBuffer: true,
381
- buffer: alignDigits(opts.max.toString().replace(".", opts.radixPoint).split(""), opts.digits, opts).reverse()
382
- } : false;
383
- }
384
- }
385
-
386
- return currentResult;
387
- },
388
- onUnMask: function (maskedValue, unmaskedValue, opts) {
389
- if (unmaskedValue === "" && opts.nullable === true) {
390
- return unmaskedValue;
391
- }
392
- var processValue = maskedValue.replace(opts.prefix, "");
393
- processValue = processValue.replace(opts.suffix, "");
394
- processValue = processValue.replace(new RegExp(escapeRegex(opts.groupSeparator), "g"), "");
395
- if (opts.placeholder.charAt(0) !== "") {
396
- processValue = processValue.replace(new RegExp(opts.placeholder.charAt(0), "g"), "0");
397
- }
398
- if (opts.unmaskAsNumber) {
399
- if (opts.radixPoint !== "" && processValue.indexOf(opts.radixPoint) !== -1) processValue = processValue.replace(escapeRegex.call(this, opts.radixPoint), ".");
400
- processValue = processValue.replace(new RegExp("^" + escapeRegex(opts.negationSymbol.front)), "-");
401
- processValue = processValue.replace(new RegExp(escapeRegex(opts.negationSymbol.back) + "$"), "");
402
- return Number(processValue);
403
- }
404
- return processValue;
405
- }
406
- ,
407
- isComplete: function (buffer, opts) {
408
- var maskedValue = (opts.numericInput ? buffer.slice().reverse() : buffer).join("");
409
- maskedValue = maskedValue.replace(new RegExp("^" + escapeRegex(opts.negationSymbol.front)), "-");
410
- maskedValue = maskedValue.replace(new RegExp(escapeRegex(opts.negationSymbol.back) + "$"), "");
411
- maskedValue = maskedValue.replace(opts.prefix, "");
412
- maskedValue = maskedValue.replace(opts.suffix, "");
413
- maskedValue = maskedValue.replace(new RegExp(escapeRegex(opts.groupSeparator) + "([0-9]{3})", "g"), "$1");
414
- if (opts.radixPoint === ",") maskedValue = maskedValue.replace(escapeRegex(opts.radixPoint), ".");
415
- return isFinite(maskedValue);
416
- },
417
- onBeforeMask: function (initialValue, opts) {
418
- var radixPoint = opts.radixPoint || ",";
419
- if (isFinite(opts.digits)) opts.digits = parseInt(opts.digits);
420
-
421
- if ((typeof initialValue == "number" || opts.inputType === "number") && radixPoint !== "") {
422
- initialValue = initialValue.toString().replace(".", radixPoint);
423
- }
424
- var isNagtive = initialValue.charAt(0) === "-" || initialValue.charAt(0) === opts.negationSymbol.front;
425
- var valueParts = initialValue.split(radixPoint),
426
- integerPart = valueParts[0].replace(/[^\-0-9]/g, ""),
427
- decimalPart = valueParts.length > 1 ? valueParts[1].replace(/[^0-9]/g, "") : "",
428
- forceDigits = valueParts.length > 1;
429
-
430
- initialValue = integerPart + (decimalPart !== "" ? radixPoint + decimalPart : decimalPart);
431
-
432
- var digits = 0;
433
- if (radixPoint !== "") {
434
- digits = !opts.digitsOptional ? opts.digits : (opts.digits < decimalPart.length ? opts.digits : decimalPart.length);
435
- if (decimalPart !== "" || !opts.digitsOptional) {
436
- var digitsFactor = Math.pow(10, digits || 1);
437
-
438
- //make the initialValue a valid javascript number for the parsefloat
439
- initialValue = initialValue.replace(escapeRegex(radixPoint), ".");
440
- if (!isNaN(parseFloat(initialValue))) {
441
- initialValue = (opts.roundingFN(parseFloat(initialValue) * digitsFactor) / digitsFactor).toFixed(digits);
442
- }
443
- initialValue = initialValue.toString().replace(".", radixPoint);
444
- }
445
- }
446
- //this needs to be in a separate part and not directly in decimalPart to allow rounding
447
- if (opts.digits === 0 && initialValue.indexOf(radixPoint) !== -1) {
448
- initialValue = initialValue.substring(0, initialValue.indexOf(radixPoint));
449
- }
450
-
451
- if (opts.min !== null || opts.max !== null) {
452
- var numberValue = initialValue.toString().replace(radixPoint, ".");
453
- if (opts.min !== null && numberValue < opts.min) {
454
- initialValue = opts.min.toString().replace(".", radixPoint);
455
- } else if (opts.max !== null && numberValue > opts.max) {
456
- initialValue = opts.max.toString().replace(".", radixPoint);
457
- }
458
- }
459
-
460
- if (isNagtive && initialValue.charAt(0) !== "-") {
461
- initialValue = "-" + initialValue;
462
- }
463
- return alignDigits(initialValue.toString().split(""), digits, opts, forceDigits).join("");
464
- }
465
- ,
466
- onBeforeWrite: function (e, buffer, caretPos, opts) {
467
- function stripBuffer(buffer, stripRadix) {
468
- if (opts.__financeInput !== false || stripRadix) {
469
- var position = buffer.indexOf(opts.radixPoint);
470
- if (position !== -1) {
471
- buffer.splice(position, 1);
472
- }
473
- }
474
- if (opts.groupSeparator !== "") {
475
- while ((position = buffer.indexOf(opts.groupSeparator)) !== -1) {
476
- buffer.splice(position, 1);
477
- }
478
- }
479
-
480
- return buffer;
481
- }
482
-
483
- var result,
484
- leadingzeroes = checkForLeadingZeroes(buffer, opts);
485
-
486
- if (leadingzeroes) {
487
- const caretNdx = buffer.join("").lastIndexOf(leadingzeroes[0].split("").reverse().join("")) - (leadingzeroes[0] == leadingzeroes.input ? 0 : 1),
488
- offset = (leadingzeroes[0] == leadingzeroes.input ? 1 : 0);
489
- for (let i = leadingzeroes[0].length - offset; i > 0; i--) {
490
- delete this.maskset.validPositions[caretNdx + i];
491
- delete buffer[caretNdx + i];
492
- }
493
- }
494
-
495
- if (e) {
496
- switch (e.type) {
497
- case "blur":
498
- case "checkval":
499
- if (opts.min !== null) {
500
- var unmasked = opts.onUnMask(buffer.slice().reverse().join(""), undefined, $.extend({}, opts, {
501
- unmaskAsNumber: true
502
- }));
503
- if (opts.min !== null && unmasked < opts.min) {
504
- return {
505
- refreshFromBuffer: true,
506
- buffer: alignDigits(opts.min.toString().replace(".", opts.radixPoint).split(""), opts.digits, opts).reverse()
507
- };
508
- }
509
- }
510
- if (buffer[buffer.length - 1] === opts.negationSymbol.front) { //strip negation symbol on blur when value is 0
511
- var nmbrMtchs = new RegExp("(^" + (opts.negationSymbol.front != "" ? escapeRegex(opts.negationSymbol.front) + "?" : "") + escapeRegex(opts.prefix) + ")(.*)(" + escapeRegex(opts.suffix) + (opts.negationSymbol.back != "" ? escapeRegex(opts.negationSymbol.back) + "?" : "") + "$)").exec(stripBuffer(buffer.slice(), true).reverse().join("")),
512
- number = nmbrMtchs ? nmbrMtchs[2] : "";
513
- if (number == 0) {
514
- result = {refreshFromBuffer: true, buffer: [0]};
515
- }
516
- } else if (opts.radixPoint !== "" && buffer[0] === opts.radixPoint) { //strip radixpoint on blur when it is the latest char
517
- if (result && result.buffer) {
518
- result.buffer.shift();
519
- } else {
520
- buffer.shift();
521
- result =
522
- {refreshFromBuffer: true, buffer: stripBuffer(buffer)};
523
- }
524
- }
525
-
526
- if (opts.enforceDigitsOnBlur) {
527
- result = result || {};
528
- var bffr = (result && result.buffer) || buffer.slice().reverse();
529
- result.refreshFromBuffer = true;
530
- result.buffer = alignDigits(bffr, opts.digits, opts, true).reverse();
531
- }
532
- }
533
- }
534
-
535
- return result;
536
- },
537
- onKeyDown: function (e, buffer, caretPos, opts) {
538
- var $input = $(this), bffr;
539
- if (e.ctrlKey) {
540
- switch (e.keyCode) {
541
- case keyCode.UP:
542
- this.inputmask.__valueSet.call(this, parseFloat(this.inputmask.unmaskedvalue()) + parseInt(opts.step));
543
- $input.trigger("setvalue");
544
- return false;
545
- case keyCode.DOWN:
546
- this.inputmask.__valueSet.call(this, parseFloat(this.inputmask.unmaskedvalue()) - parseInt(opts.step));
547
- $input.trigger("setvalue");
548
- return false;
549
- }
550
- }
551
- if (!e.shiftKey && (e.keyCode === keyCode.DELETE || e.keyCode === keyCode.BACKSPACE || e.keyCode === keyCode.BACKSPACE_SAFARI) && caretPos.begin !== buffer.length) {
552
- if (buffer[e.keyCode === keyCode.DELETE ? caretPos.begin - 1 : caretPos.end] === opts.negationSymbol.front) {
553
- bffr = buffer.slice().reverse();
554
- if (opts.negationSymbol.front !== "") bffr.shift();
555
- if (opts.negationSymbol.back !== "") bffr.pop();
556
- $input.trigger("setvalue", [bffr.join(""), caretPos.begin]);
557
- return false;
558
- } else if (opts._radixDance === true) {
559
- var radixPos = buffer.indexOf(opts.radixPoint);
560
- if (!opts.digitsOptional) {
561
- if (radixPos !== -1 && (caretPos.begin < radixPos || caretPos.end < radixPos || (e.keyCode === keyCode.DELETE && caretPos.begin === radixPos))) {
562
- if (caretPos.begin === caretPos.end && (e.keyCode === keyCode.BACKSPACE || e.keyCode === keyCode.BACKSPACE_SAFARI)) { //only adjust when not a selection
563
- caretPos.begin++;
564
- }
565
- bffr = buffer.slice().reverse();
566
- bffr.splice(bffr.length - caretPos.begin, caretPos.begin - caretPos.end + 1);
567
- // console.log(caretPos);
568
- bffr = alignDigits(bffr, opts.digits, opts).join("");
569
- $input.trigger("setvalue", [bffr, caretPos.begin >= bffr.length ? radixPos + 1 : caretPos.begin]);
570
- return false;
571
- }
572
- } else if (radixPos === 0) {
573
- bffr = buffer.slice().reverse();
574
- bffr.pop();
575
- $input.trigger("setvalue", [bffr.join(""), caretPos.begin >= bffr.length ? bffr.length : caretPos.begin]);
576
- return false;
577
- }
578
- }
579
- }
580
- }
581
- },
582
- "currency": {
583
- prefix: "", //"$ ",
584
- groupSeparator: ",",
585
- alias: "numeric",
586
- digits: 2,
587
- digitsOptional: false
588
- },
589
- "decimal": {
590
- alias: "numeric"
591
- },
592
- "integer": {
593
- alias: "numeric",
594
- digits: 0
595
- },
596
- "percentage": {
597
- alias: "numeric",
598
- min: 0,
599
- max: 100,
600
- suffix: " %",
601
- digits: 0,
602
- allowMinus: false
603
- },
604
- "indianns": { //indian numbering system
605
- alias: "numeric",
606
- _mask: function (opts) {
607
- return "(" + opts.groupSeparator + "99){*|1}(" + opts.groupSeparator + "999){1|1}";
608
- },
609
- groupSeparator: ",",
610
- radixPoint: ".",
611
- placeholder: "0",
612
- digits: 2,
613
- digitsOptional: false
614
- }
615
- });
241
+ "numeric": {
242
+ mask: genMask,
243
+ _mask: function (opts) {
244
+ return "(" + opts.groupSeparator + "999){+|1}";
245
+ },
246
+ digits: "*", //number of fractionalDigits
247
+ digitsOptional: true,
248
+ enforceDigitsOnBlur: false,
249
+ radixPoint: ".",
250
+ positionCaretOnClick: "radixFocus",
251
+ _radixDance: true,
252
+ groupSeparator: "",
253
+ allowMinus: true,
254
+ negationSymbol: {
255
+ front: "-", //"("
256
+ back: "" //")"
257
+ },
258
+ prefix: "",
259
+ suffix: "",
260
+ min: null, //minimum value
261
+ max: null, //maximum value
262
+ SetMaxOnOverflow: false,
263
+ step: 1,
264
+ inputType: "text", //number ~ specify that values which are set are in textform (radix point is same as in the options) or in numberform (radixpoint = .)
265
+ unmaskAsNumber: false,
266
+ roundingFN: Math.round, //Math.floor , fn(x)
267
+ inputmode: "decimal",
268
+ shortcuts: {k: "1000", m: "1000000"},
269
+ //global options
270
+ placeholder: "0",
271
+ greedy: false,
272
+ rightAlign: true,
273
+ insertMode: true,
274
+ autoUnmask: false,
275
+ skipOptionalPartCharacter: "",
276
+ usePrototypeDefinitions: false,
277
+ stripLeadingZeroes: true,
278
+ definitions: {
279
+ "0": {
280
+ validator: decimalValidator
281
+ },
282
+ "1": {
283
+ validator: decimalValidator,
284
+ definitionSymbol: "9"
285
+ },
286
+ "9": { //\uFF11-\uFF19 #1606
287
+ validator: "[0-9\uFF10-\uFF19\u0660-\u0669\u06F0-\u06F9]",
288
+ definitionSymbol: "*"
289
+ },
290
+ "+": {
291
+ validator: function (chrs, maskset, pos, strict, opts) {
292
+ return (opts.allowMinus && (chrs === "-" || chrs === opts.negationSymbol.front));
293
+
294
+ }
295
+ },
296
+ "-": {
297
+ validator: function (chrs, maskset, pos, strict, opts) {
298
+ return (opts.allowMinus && chrs === opts.negationSymbol.back);
299
+ }
300
+ }
301
+ },
302
+ preValidation: function (buffer, pos, c, isSelection, opts, maskset, caretPos, strict) {
303
+ const inputmask = this;
304
+
305
+ if (opts.__financeInput !== false && c === opts.radixPoint) return false;
306
+ var radixPos = buffer.indexOf(opts.radixPoint), initPos = pos;
307
+ pos = hanndleRadixDance(pos, c, radixPos, maskset, opts);
308
+ if (c === "-" || c === opts.negationSymbol.front) {
309
+ if (opts.allowMinus !== true) return false;
310
+ var isNegative = false,
311
+ front = findValid("+", maskset), back = findValid("-", maskset);
312
+ if (front !== -1) {
313
+ isNegative = [front, back];
314
+ }
315
+
316
+ return isNegative !== false ? {
317
+ remove: isNegative,
318
+ caret: initPos - opts.negationSymbol.back.length
319
+ } : {
320
+ insert: [
321
+ {
322
+ pos: findValidator.call(inputmask, "+", maskset),
323
+ c: opts.negationSymbol.front,
324
+ fromIsValid: true
325
+ },
326
+ {
327
+ pos: findValidator.call(inputmask, "-", maskset),
328
+ c: opts.negationSymbol.back,
329
+ fromIsValid: undefined
330
+ }],
331
+ caret: initPos + opts.negationSymbol.back.length
332
+ };
333
+ }
334
+
335
+ if (c === opts.groupSeparator) {
336
+ return {caret: initPos};
337
+ }
338
+
339
+ if (strict) return true;
340
+ if (radixPos !== -1 && (opts._radixDance === true && isSelection === false && c === opts.radixPoint && (opts.digits !== undefined && (isNaN(opts.digits) || parseInt(opts.digits) > 0)) && radixPos !== pos)) {
341
+ return {
342
+ "caret": opts._radixDance && pos === radixPos - 1 ? radixPos + 1 : radixPos
343
+ };
344
+ }
345
+ if (opts.__financeInput === false) {
346
+ if (isSelection) {
347
+ if (opts.digitsOptional) {
348
+ return {rewritePosition: caretPos.end};
349
+ } else if (!opts.digitsOptional) {
350
+ if (caretPos.begin > radixPos && caretPos.end <= radixPos) {
351
+ if (c === opts.radixPoint) {
352
+ return {
353
+ insert: {pos: radixPos + 1, c: "0", fromIsValid: true},
354
+ rewritePosition: radixPos
355
+ };
356
+ } else {
357
+ return {rewritePosition: radixPos + 1};
358
+ }
359
+ } else if (caretPos.begin < radixPos) {
360
+ return {rewritePosition: caretPos.begin - 1};
361
+ }
362
+ }
363
+ } else if (!opts.showMaskOnHover && !opts.showMaskOnFocus && !opts.digitsOptional && opts.digits > 0 && this.__valueGet.call(this.el) === "") {
364
+ return {rewritePosition: radixPos};
365
+ }
366
+ }
367
+ return {rewritePosition: pos};
368
+ },
369
+ postValidation: function (buffer, pos, c, currentResult, opts, maskset, strict) {
370
+ if (currentResult === false) return currentResult;
371
+ if (strict) return true;
372
+ if (opts.min !== null || opts.max !== null) {
373
+ var unmasked = opts.onUnMask(buffer.slice().reverse().join(""), undefined, $.extend({}, opts, {
374
+ unmaskAsNumber: true
375
+ }));
376
+ if (opts.min !== null && unmasked < opts.min && (unmasked.toString().length > opts.min.toString().length || unmasked < 0)) {
377
+ return false;
378
+ // return {
379
+ // refreshFromBuffer: true,
380
+ // buffer: alignDigits(opts.min.toString().replace(".", opts.radixPoint).split(""), opts.digits, opts).reverse()
381
+ // };
382
+ }
383
+
384
+ if (opts.max !== null && unmasked > opts.max) {
385
+ return opts.SetMaxOnOverflow ? {
386
+ refreshFromBuffer: true,
387
+ buffer: alignDigits(opts.max.toString().replace(".", opts.radixPoint).split(""), opts.digits, opts).reverse()
388
+ } : false;
389
+ }
390
+ }
391
+
392
+ return currentResult;
393
+ },
394
+ onUnMask: function (maskedValue, unmaskedValue, opts) {
395
+ if (unmaskedValue === "" && opts.nullable === true) {
396
+ return unmaskedValue;
397
+ }
398
+ var processValue = maskedValue.replace(opts.prefix, "");
399
+ processValue = processValue.replace(opts.suffix, "");
400
+ processValue = processValue.replace(new RegExp(escapeRegex(opts.groupSeparator), "g"), "");
401
+ if (opts.placeholder.charAt(0) !== "") {
402
+ processValue = processValue.replace(new RegExp(opts.placeholder.charAt(0), "g"), "0");
403
+ }
404
+ if (opts.unmaskAsNumber) {
405
+ if (opts.radixPoint !== "" && processValue.indexOf(opts.radixPoint) !== -1) processValue = processValue.replace(escapeRegex.call(this, opts.radixPoint), ".");
406
+ processValue = processValue.replace(new RegExp("^" + escapeRegex(opts.negationSymbol.front)), "-");
407
+ processValue = processValue.replace(new RegExp(escapeRegex(opts.negationSymbol.back) + "$"), "");
408
+ return Number(processValue);
409
+ }
410
+ return processValue;
411
+ }
412
+ ,
413
+ isComplete: function (buffer, opts) {
414
+ var maskedValue = (opts.numericInput ? buffer.slice().reverse() : buffer).join("");
415
+ maskedValue = maskedValue.replace(new RegExp("^" + escapeRegex(opts.negationSymbol.front)), "-");
416
+ maskedValue = maskedValue.replace(new RegExp(escapeRegex(opts.negationSymbol.back) + "$"), "");
417
+ maskedValue = maskedValue.replace(opts.prefix, "");
418
+ maskedValue = maskedValue.replace(opts.suffix, "");
419
+ maskedValue = maskedValue.replace(new RegExp(escapeRegex(opts.groupSeparator) + "([0-9]{3})", "g"), "$1");
420
+ if (opts.radixPoint === ",") maskedValue = maskedValue.replace(escapeRegex(opts.radixPoint), ".");
421
+ return isFinite(maskedValue);
422
+ },
423
+ onBeforeMask: function (initialValue, opts) {
424
+ var radixPoint = opts.radixPoint || ",";
425
+ if (isFinite(opts.digits)) opts.digits = parseInt(opts.digits);
426
+
427
+ if ((typeof initialValue == "number" || opts.inputType === "number") && radixPoint !== "") {
428
+ initialValue = initialValue.toString().replace(".", radixPoint);
429
+ }
430
+ var isNagtive = initialValue.charAt(0) === "-" || initialValue.charAt(0) === opts.negationSymbol.front;
431
+ var valueParts = initialValue.split(radixPoint),
432
+ integerPart = valueParts[0].replace(/[^\-0-9]/g, ""),
433
+ decimalPart = valueParts.length > 1 ? valueParts[1].replace(/[^0-9]/g, "") : "",
434
+ forceDigits = valueParts.length > 1;
435
+
436
+ initialValue = integerPart + (decimalPart !== "" ? radixPoint + decimalPart : decimalPart);
437
+
438
+ var digits = 0;
439
+ if (radixPoint !== "") {
440
+ digits = !opts.digitsOptional ? opts.digits : (opts.digits < decimalPart.length ? opts.digits : decimalPart.length);
441
+ if (decimalPart !== "" || !opts.digitsOptional) {
442
+ var digitsFactor = Math.pow(10, digits || 1);
443
+
444
+ //make the initialValue a valid javascript number for the parsefloat
445
+ initialValue = initialValue.replace(escapeRegex(radixPoint), ".");
446
+ if (!isNaN(parseFloat(initialValue))) {
447
+ initialValue = (opts.roundingFN(parseFloat(initialValue) * digitsFactor) / digitsFactor).toFixed(digits);
448
+ }
449
+ initialValue = initialValue.toString().replace(".", radixPoint);
450
+ }
451
+ }
452
+ //this needs to be in a separate part and not directly in decimalPart to allow rounding
453
+ if (opts.digits === 0 && initialValue.indexOf(radixPoint) !== -1) {
454
+ initialValue = initialValue.substring(0, initialValue.indexOf(radixPoint));
455
+ }
456
+
457
+ if (opts.min !== null || opts.max !== null) {
458
+ var numberValue = initialValue.toString().replace(radixPoint, ".");
459
+ if (opts.min !== null && numberValue < opts.min) {
460
+ initialValue = opts.min.toString().replace(".", radixPoint);
461
+ } else if (opts.max !== null && numberValue > opts.max) {
462
+ initialValue = opts.max.toString().replace(".", radixPoint);
463
+ }
464
+ }
465
+
466
+ if (isNagtive && initialValue.charAt(0) !== "-") {
467
+ initialValue = "-" + initialValue;
468
+ }
469
+ return alignDigits(initialValue.toString().split(""), digits, opts, forceDigits).join("");
470
+ }
471
+ ,
472
+ onBeforeWrite: function (e, buffer, caretPos, opts) {
473
+ function stripBuffer(buffer, stripRadix) {
474
+ if (opts.__financeInput !== false || stripRadix) {
475
+ var position = buffer.indexOf(opts.radixPoint);
476
+ if (position !== -1) {
477
+ buffer.splice(position, 1);
478
+ }
479
+ }
480
+ if (opts.groupSeparator !== "") {
481
+ while ((position = buffer.indexOf(opts.groupSeparator)) !== -1) {
482
+ buffer.splice(position, 1);
483
+ }
484
+ }
485
+
486
+ return buffer;
487
+ }
488
+
489
+ let result, leadingzeroes;
490
+ if (opts.stripLeadingZeroes && (leadingzeroes = checkForLeadingZeroes(buffer, opts))) {
491
+ const caretNdx = buffer.join("").lastIndexOf(leadingzeroes[0].split("").reverse().join("")) - (leadingzeroes[0] == leadingzeroes.input ? 0 : 1),
492
+ offset = (leadingzeroes[0] == leadingzeroes.input ? 1 : 0);
493
+ for (let i = leadingzeroes[0].length - offset; i > 0; i--) {
494
+ delete this.maskset.validPositions[caretNdx + i];
495
+ delete buffer[caretNdx + i];
496
+ }
497
+ }
498
+
499
+ if (e) {
500
+ switch (e.type) {
501
+ case "blur":
502
+ case "checkval":
503
+ if (opts.min !== null) {
504
+ var unmasked = opts.onUnMask(buffer.slice().reverse().join(""), undefined, $.extend({}, opts, {
505
+ unmaskAsNumber: true
506
+ }));
507
+ if (opts.min !== null && unmasked < opts.min) {
508
+ return {
509
+ refreshFromBuffer: true,
510
+ buffer: alignDigits(opts.min.toString().replace(".", opts.radixPoint).split(""), opts.digits, opts).reverse()
511
+ };
512
+ }
513
+ }
514
+ if (buffer[buffer.length - 1] === opts.negationSymbol.front) { //strip negation symbol on blur when value is 0
515
+ var nmbrMtchs = new RegExp("(^" + (opts.negationSymbol.front != "" ? escapeRegex(opts.negationSymbol.front) + "?" : "") + escapeRegex(opts.prefix) + ")(.*)(" + escapeRegex(opts.suffix) + (opts.negationSymbol.back != "" ? escapeRegex(opts.negationSymbol.back) + "?" : "") + "$)").exec(stripBuffer(buffer.slice(), true).reverse().join("")),
516
+ number = nmbrMtchs ? nmbrMtchs[2] : "";
517
+ if (number == 0) {
518
+ result = {refreshFromBuffer: true, buffer: [0]};
519
+ }
520
+ } else if (opts.radixPoint !== "") { //strip radixpoint on blur when it is the latest char
521
+ var radixNDX = buffer.indexOf(opts.radixPoint);
522
+ if (radixNDX === opts.suffix.length) {
523
+ if (result && result.buffer) {
524
+ result.buffer.splice(0, 1 + opts.suffix.length);
525
+ } else {
526
+ buffer.splice(0, 1 + opts.suffix.length);
527
+ result =
528
+ {refreshFromBuffer: true, buffer: stripBuffer(buffer)};
529
+ }
530
+ }
531
+ }
532
+
533
+ if (opts.enforceDigitsOnBlur) {
534
+ result = result || {};
535
+ var bffr = (result && result.buffer) || buffer.slice().reverse();
536
+ result.refreshFromBuffer = true;
537
+ result.buffer = alignDigits(bffr, opts.digits, opts, true).reverse();
538
+ }
539
+ }
540
+ }
541
+
542
+ return result;
543
+ },
544
+ onKeyDown: function (e, buffer, caretPos, opts) {
545
+ var $input = $(this), bffr;
546
+ var pattern, c = String.fromCharCode(e.keyCode).toLowerCase();
547
+ if ((pattern = (opts.shortcuts && opts.shortcuts[c]))) {
548
+ if (pattern.length > 1) {
549
+ this.inputmask.__valueSet.call(this, parseFloat(this.inputmask.unmaskedvalue()) * parseInt(pattern));
550
+ $input.trigger("setvalue");
551
+ return false;
552
+ }
553
+ }
554
+ if (e.ctrlKey) {
555
+ switch (e.keyCode) {
556
+ case keyCode.UP:
557
+ this.inputmask.__valueSet.call(this, parseFloat(this.inputmask.unmaskedvalue()) + parseInt(opts.step));
558
+ $input.trigger("setvalue");
559
+ return false;
560
+ case keyCode.DOWN:
561
+ this.inputmask.__valueSet.call(this, parseFloat(this.inputmask.unmaskedvalue()) - parseInt(opts.step));
562
+ $input.trigger("setvalue");
563
+ return false;
564
+ }
565
+ }
566
+ if (!e.shiftKey && (e.keyCode === keyCode.DELETE || e.keyCode === keyCode.BACKSPACE || e.keyCode === keyCode.BACKSPACE_SAFARI) && caretPos.begin !== buffer.length) {
567
+ if (buffer[e.keyCode === keyCode.DELETE ? caretPos.begin - 1 : caretPos.end] === opts.negationSymbol.front) {
568
+ bffr = buffer.slice().reverse();
569
+ if (opts.negationSymbol.front !== "") bffr.shift();
570
+ if (opts.negationSymbol.back !== "") bffr.pop();
571
+ $input.trigger("setvalue", [bffr.join(""), caretPos.begin]);
572
+ return false;
573
+ } else if (opts._radixDance === true) {
574
+ var radixPos = buffer.indexOf(opts.radixPoint);
575
+ if (!opts.digitsOptional) {
576
+ if (radixPos !== -1 && (caretPos.begin < radixPos || caretPos.end < radixPos || (e.keyCode === keyCode.DELETE && caretPos.begin === radixPos))) {
577
+ if (caretPos.begin === caretPos.end && (e.keyCode === keyCode.BACKSPACE || e.keyCode === keyCode.BACKSPACE_SAFARI)) { //only adjust when not a selection
578
+ caretPos.begin++;
579
+ }
580
+ bffr = buffer.slice().reverse();
581
+ bffr.splice(bffr.length - caretPos.begin, caretPos.begin - caretPos.end + 1);
582
+ // console.log(caretPos);
583
+ bffr = alignDigits(bffr, opts.digits, opts).join("");
584
+ $input.trigger("setvalue", [bffr, caretPos.begin >= bffr.length ? radixPos + 1 : caretPos.begin]);
585
+ return false;
586
+ }
587
+ } else if (radixPos === 0) {
588
+ bffr = buffer.slice().reverse();
589
+ bffr.pop();
590
+ $input.trigger("setvalue", [bffr.join(""), caretPos.begin >= bffr.length ? bffr.length : caretPos.begin]);
591
+ return false;
592
+ }
593
+ }
594
+ }
595
+ }
596
+ },
597
+ "currency": {
598
+ prefix: "", //"$ ",
599
+ groupSeparator: ",",
600
+ alias: "numeric",
601
+ digits: 2,
602
+ digitsOptional: false
603
+ },
604
+ "decimal": {
605
+ alias: "numeric"
606
+ },
607
+ "integer": {
608
+ alias: "numeric",
609
+ inputmode: "numeric",
610
+ digits: 0
611
+ },
612
+ "percentage": {
613
+ alias: "numeric",
614
+ min: 0,
615
+ max: 100,
616
+ suffix: " %",
617
+ digits: 0,
618
+ allowMinus: false
619
+ },
620
+ "indianns": { //indian numbering system
621
+ alias: "numeric",
622
+ _mask: function (opts) {
623
+ return "(" + opts.groupSeparator + "99){*|1}(" + opts.groupSeparator + "999){1|1}";
624
+ },
625
+ groupSeparator: ",",
626
+ radixPoint: ".",
627
+ placeholder: "0",
628
+ digits: 2,
629
+ digitsOptional: false
630
+ }
631
+ });