use-mask-input 3.0.6 → 3.1.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 (66) hide show
  1. package/README.md +13 -19
  2. package/dist/index.cjs +191 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.ts +34 -3
  5. package/dist/index.js +184 -1
  6. package/dist/index.js.map +1 -1
  7. package/package.json +49 -48
  8. package/src/index.tsx +3 -2
  9. package/src/types.ts +6 -0
  10. package/src/useMaskInput.ts +12 -9
  11. package/src/utils.spec.ts +14 -0
  12. package/src/utils.ts +23 -0
  13. package/src/withHookFormMask.ts +8 -17
  14. package/src/withMask.ts +5 -6
  15. package/dist/example/App.example.d.ts +0 -3
  16. package/dist/example/index.d.ts +0 -1
  17. package/dist/index.modern.js +0 -2
  18. package/dist/index.modern.js.map +0 -1
  19. package/dist/index.umd.js +0 -2
  20. package/dist/index.umd.js.map +0 -1
  21. package/dist/useMaskInput.d.ts +0 -9
  22. package/dist/withHookFormMask.d.ts +0 -16
  23. package/dist/withMask.d.ts +0 -3
  24. package/node_modules/inputmask/LICENSE.txt +0 -7
  25. package/node_modules/inputmask/README.md +0 -1279
  26. package/node_modules/inputmask/bundle.js +0 -6
  27. package/node_modules/inputmask/dist/bindings/inputmask.binding.js +0 -26
  28. package/node_modules/inputmask/dist/inputmask.es6.js +0 -5
  29. package/node_modules/inputmask/dist/inputmask.js +0 -3031
  30. package/node_modules/inputmask/dist/inputmask.min.js +0 -8
  31. package/node_modules/inputmask/dist/jquery.inputmask.js +0 -2985
  32. package/node_modules/inputmask/dist/jquery.inputmask.min.js +0 -8
  33. package/node_modules/inputmask/lib/bindings/inputmask.binding.js +0 -26
  34. package/node_modules/inputmask/lib/bindings/inputmask.es6.js +0 -5
  35. package/node_modules/inputmask/lib/canUseDOM.js +0 -7
  36. package/node_modules/inputmask/lib/defaults.js +0 -101
  37. package/node_modules/inputmask/lib/definitions.js +0 -13
  38. package/node_modules/inputmask/lib/dependencyLibs/data.js +0 -8
  39. package/node_modules/inputmask/lib/dependencyLibs/events.js +0 -199
  40. package/node_modules/inputmask/lib/dependencyLibs/extend.js +0 -58
  41. package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.jquery.js +0 -13
  42. package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.js +0 -41
  43. package/node_modules/inputmask/lib/environment.js +0 -9
  44. package/node_modules/inputmask/lib/escapeRegex.js +0 -4
  45. package/node_modules/inputmask/lib/eventhandlers.js +0 -513
  46. package/node_modules/inputmask/lib/eventruler.js +0 -124
  47. package/node_modules/inputmask/lib/extensions/inputmask.date.extensions.js +0 -588
  48. package/node_modules/inputmask/lib/extensions/inputmask.extensions.js +0 -133
  49. package/node_modules/inputmask/lib/extensions/inputmask.numeric.extensions.js +0 -631
  50. package/node_modules/inputmask/lib/global/window.js +0 -3
  51. package/node_modules/inputmask/lib/inputHandling.js +0 -252
  52. package/node_modules/inputmask/lib/inputmask.js +0 -355
  53. package/node_modules/inputmask/lib/inputmaskElement.js +0 -33
  54. package/node_modules/inputmask/lib/jquery.inputmask.js +0 -81
  55. package/node_modules/inputmask/lib/keycode.json +0 -25
  56. package/node_modules/inputmask/lib/mask-lexer.js +0 -467
  57. package/node_modules/inputmask/lib/mask.js +0 -244
  58. package/node_modules/inputmask/lib/masktoken.js +0 -13
  59. package/node_modules/inputmask/lib/polyfills/Array.includes.js +0 -48
  60. package/node_modules/inputmask/lib/polyfills/Object.getPrototypeOf.js +0 -7
  61. package/node_modules/inputmask/lib/positioning.js +0 -348
  62. package/node_modules/inputmask/lib/validation-tests.js +0 -597
  63. package/node_modules/inputmask/lib/validation.js +0 -664
  64. package/node_modules/inputmask/package.json +0 -60
  65. package/src/example/App.example.tsx +0 -68
  66. package/src/example/index.tsx +0 -5
@@ -1,631 +0,0 @@
1
- /*
2
- Input Mask plugin extensions
3
- http://github.com/RobinHerbots/jquery.inputmask
4
- Copyright (c) Robin Herbots
5
- Licensed under the MIT license
6
- */
7
- import Inputmask from "../inputmask";
8
- import keyCode from "../keycode.json";
9
- import escapeRegex from "../escapeRegex";
10
- import {seekNext} from "../positioning";
11
-
12
- const $ = Inputmask.dependencyLib;
13
-
14
- function autoEscape(txt, opts) {
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;
32
- }
33
-
34
- function alignDigits(buffer, digits, opts, force) {
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;
56
- }
57
-
58
- function findValidator(symbol, maskset) {
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;
75
- }
76
-
77
- function findValid(symbol, maskset) {
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;
87
- }
88
-
89
- function parseMinMaxOptions(opts) {
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
- }
106
- }
107
-
108
- function genMask(opts) {
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;
201
- }
202
-
203
- function hanndleRadixDance(pos, c, radixPos, maskset, opts) {
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;
210
- }
211
-
212
- function decimalValidator(chrs, maskset, pos, strict, opts) {
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;
226
- }
227
-
228
- function checkForLeadingZeroes(buffer, opts) {
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;
237
- }
238
-
239
- //number aliases
240
- Inputmask.extendAliases({
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
- });
@@ -1,3 +0,0 @@
1
- import canUseDOM from "../canUseDOM";
2
-
3
- export default canUseDOM ? window : {};