inputmask
Advanced tools
Comparing version 5.0.7-beta.29 to 5.0.7
@@ -11,8 +11,8 @@ import { | ||
import keyCode from "./keycode.json"; | ||
import {iemobile, iphone} from "./environment"; | ||
import {handleRemove, isComplete, isValid} from "./validation"; | ||
import {applyInputValue, checkVal, clearOptionalTail, HandleNativePlaceholder, writeBuffer} from "./inputHandling"; | ||
import {getPlaceholder, getTest} from "./validation-tests"; | ||
import { iemobile, iphone } from "./environment"; | ||
import { handleRemove, isComplete, isSelection, isValid } from "./validation"; | ||
import { applyInputValue, checkVal, clearOptionalTail, HandleNativePlaceholder, writeBuffer } from "./inputHandling"; | ||
import { getPlaceholder, getTest } from "./validation-tests"; | ||
export {EventHandlers}; | ||
export { EventHandlers }; | ||
@@ -47,5 +47,7 @@ var EventHandlers = { | ||
$input.trigger("click"); | ||
// } else if (k === keyCode.INSERT && !(e.shiftKey || e.ctrlKey) && inputmask.userOptions.insertMode === undefined) { //insert | ||
// opts.insertMode = !opts.insertMode; | ||
// caret(input, pos.begin, pos.end); | ||
} else if (k === keyCode.INSERT && !(e.shiftKey || e.ctrlKey) && inputmask.userOptions.insertMode === undefined) { //insert | ||
if (!isSelection.call(inputmask, pos)) { | ||
opts.insertMode = !opts.insertMode; | ||
caret.call(inputmask, input, pos.begin, pos.begin); | ||
} else opts.insertMode = !opts.insertMode; | ||
} else if (opts.tabThrough === true && k === keyCode.TAB) { | ||
@@ -118,5 +120,5 @@ if (e.shiftKey === true) { | ||
var pos = checkval ? { | ||
begin: ndx, | ||
end: ndx | ||
} : caret.call(inputmask, input), | ||
begin: ndx, | ||
end: ndx | ||
} : caret.call(inputmask, input), | ||
forwardPosition, c = String.fromCharCode(k); | ||
@@ -313,3 +315,2 @@ | ||
if (buffer !== inputValue) { | ||
// inputValue = radixPointHandler(input, inputValue, caretPos); | ||
inputValue = ieMobileHandler(input, inputValue, caretPos); | ||
@@ -316,0 +317,0 @@ |
@@ -16,315 +16,328 @@ /* | ||
class DateObject { | ||
constructor(mask, format, opts) { | ||
this.mask = mask; | ||
this.format = format; | ||
this.opts = opts; | ||
this._date = new Date(1, 0, 1); | ||
this.initDateObject(mask, this.opts); | ||
} | ||
constructor(mask, format, opts) { | ||
this.mask = mask; | ||
this.format = format; | ||
this.opts = opts; | ||
this._date = new Date(1, 0, 1); | ||
this.initDateObject(mask, this.opts); | ||
} | ||
get date() { | ||
if (this._date === undefined) { | ||
this._date = new Date(1, 0, 1); | ||
this.initDateObject(undefined, this.opts); | ||
} | ||
return this._date; | ||
} | ||
get date() { | ||
if (this._date === undefined) { | ||
this._date = new Date(1, 0, 1); | ||
this.initDateObject(undefined, this.opts); | ||
} | ||
return this._date; | ||
} | ||
initDateObject(mask, opts) { | ||
let match; | ||
getTokenizer(opts).lastIndex = 0; | ||
while ((match = getTokenizer(opts).exec(this.format))) { | ||
let dynMatches = new RegExp("\\d+$").exec(match[0]), | ||
fcode = dynMatches ? (match[0][0] + "x") : match[0], | ||
value; | ||
if (mask !== undefined) { | ||
if (dynMatches) { | ||
let lastIndex = getTokenizer(opts).lastIndex, | ||
tokanMatch = getTokenMatch(match.index, opts); | ||
getTokenizer(opts).lastIndex = lastIndex; | ||
value = mask.slice(0, mask.indexOf(tokanMatch.nextMatch[0])); | ||
} else { | ||
value = mask.slice(0, fcode.length); | ||
} | ||
mask = mask.slice(value.length); | ||
} | ||
initDateObject(mask, opts) { | ||
let match; | ||
getTokenizer(opts).lastIndex = 0; | ||
while ((match = getTokenizer(opts).exec(this.format))) { | ||
let dynMatches = new RegExp("\\d+$").exec(match[0]), | ||
fcode = dynMatches ? (match[0][0] + "x") : match[0], | ||
value; | ||
if (mask !== undefined) { | ||
if (dynMatches) { | ||
let lastIndex = getTokenizer(opts).lastIndex, | ||
tokanMatch = getTokenMatch(match.index, opts); | ||
getTokenizer(opts).lastIndex = lastIndex; | ||
value = mask.slice(0, mask.indexOf(tokanMatch.nextMatch[0])); | ||
} else { | ||
value = mask.slice(0, fcode.length); | ||
} | ||
mask = mask.slice(value.length); | ||
} | ||
if (Object.prototype.hasOwnProperty.call(formatCode, fcode)) { | ||
this.setValue(this, value, fcode, formatCode[fcode][2], formatCode[fcode][1]); | ||
} | ||
} | ||
} | ||
if (Object.prototype.hasOwnProperty.call(formatCode, fcode)) { | ||
this.setValue(this, value, fcode, formatCode[fcode][2], formatCode[fcode][1]); | ||
} | ||
} | ||
} | ||
setValue(dateObj, value, fcode, targetProp, dateOperation) { | ||
if (value !== undefined) { | ||
dateObj[targetProp] = targetProp === "ampm" ? value : value.replace(/[^0-9]/g, "0"); | ||
dateObj["raw" + targetProp] = value.replace(/\s/g, "_"); | ||
} | ||
if (dateOperation !== undefined) { | ||
let datavalue = dateObj[targetProp]; | ||
if ((targetProp === "day" && parseInt(datavalue) === 29) || (targetProp === "month" && parseInt(datavalue) === 2)) { | ||
if (parseInt(dateObj.day) === 29 && parseInt(dateObj.month) === 2 && (dateObj.year === "" || dateObj.year === undefined)) { | ||
//set temporary leap year in dateObj | ||
dateObj._date.setFullYear(2012, 1, 29); | ||
} | ||
} | ||
if (targetProp === "day") { | ||
useDateObject = true; | ||
if (parseInt(datavalue) === 0) | ||
datavalue = 1; | ||
} | ||
if (targetProp === "month") | ||
useDateObject = true; | ||
if (targetProp === "year") { | ||
useDateObject = true; | ||
if (datavalue.length < 4) | ||
datavalue = pad(datavalue, 4, true); | ||
} | ||
if (datavalue !== "" && !isNaN(datavalue)) dateOperation.call(dateObj._date, datavalue); | ||
if (targetProp === "ampm") | ||
dateOperation.call(dateObj._date, datavalue); | ||
} | ||
} | ||
setValue(dateObj, value, fcode, targetProp, dateOperation) { | ||
if (value !== undefined) { | ||
dateObj[targetProp] = targetProp === "ampm" ? value : value.replace(/[^0-9]/g, "0"); | ||
dateObj["raw" + targetProp] = value.replace(/\s/g, "_"); | ||
} | ||
if (dateOperation !== undefined) { | ||
let datavalue = dateObj[targetProp]; | ||
if ((targetProp === "day" && parseInt(datavalue) === 29) || (targetProp === "month" && parseInt(datavalue) === 2)) { | ||
if (parseInt(dateObj.day) === 29 && parseInt(dateObj.month) === 2 && (dateObj.year === "" || dateObj.year === undefined)) { | ||
//set temporary leap year in dateObj | ||
dateObj._date.setFullYear(2012, 1, 29); | ||
} | ||
} | ||
if (targetProp === "day") { | ||
useDateObject = true; | ||
if (parseInt(datavalue) === 0) | ||
datavalue = 1; | ||
} | ||
if (targetProp === "month") | ||
useDateObject = true; | ||
if (targetProp === "year") { | ||
useDateObject = true; | ||
if (datavalue.length < 4) | ||
datavalue = pad(datavalue, 4, true); | ||
} | ||
if (datavalue !== "" && !isNaN(datavalue)) dateOperation.call(dateObj._date, datavalue); | ||
if (targetProp === "ampm") | ||
dateOperation.call(dateObj._date, datavalue); | ||
} | ||
} | ||
reset() { | ||
this._date = new Date(1, 0, 1); | ||
} | ||
reset() { | ||
this._date = new Date(1, 0, 1); | ||
} | ||
reInit() { | ||
this._date = undefined; | ||
this.date; | ||
} | ||
reInit() { | ||
this._date = undefined; | ||
this.date; | ||
} | ||
} | ||
let currentYear = new Date().getFullYear(), | ||
useDateObject = false, | ||
//supported codes for formatting | ||
//http://blog.stevenlevithan.com/archives/date-time-format | ||
//https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings?view=netframework-4.7 | ||
formatCode = { //regex, valueSetter, type, displayformatter | ||
d: ["[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", Date.prototype.getDate], //Day of the month as digits; no leading zero for single-digit days. | ||
dd: ["0[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", function () { | ||
return pad(Date.prototype.getDate.call(this), 2); | ||
}], //Day of the month as digits; leading zero for single-digit days. | ||
ddd: [""], //Day of the week as a three-letter abbreviation. | ||
dddd: [""], //Day of the week as its full name. | ||
m: ["[1-9]|1[012]", function (val) { | ||
let mval = val ? parseInt(val) : 0; | ||
if (mval > 0) mval--; | ||
return Date.prototype.setMonth.call(this, mval); | ||
}, "month", function () { | ||
return Date.prototype.getMonth.call(this) + 1; | ||
}], //Month as digits; no leading zero for single-digit months. | ||
mm: ["0[1-9]|1[012]", function (val) { | ||
let mval = val ? parseInt(val) : 0; | ||
if (mval > 0) mval--; | ||
return Date.prototype.setMonth.call(this, mval); | ||
}, "month", function () { | ||
return pad(Date.prototype.getMonth.call(this) + 1, 2); | ||
}], //Month as digits; leading zero for single-digit months. | ||
mmm: [""], //Month as a three-letter abbreviation. | ||
mmmm: [""], //Month as its full name. | ||
yy: ["[0-9]{2}", Date.prototype.setFullYear, "year", function () { | ||
return pad(Date.prototype.getFullYear.call(this), 2); | ||
}], //Year as last two digits; leading zero for years less than 10. | ||
yyyy: ["[0-9]{4}", Date.prototype.setFullYear, "year", function () { | ||
return pad(Date.prototype.getFullYear.call(this), 4); | ||
}], | ||
h: ["[1-9]|1[0-2]", Date.prototype.setHours, "hours", Date.prototype.getHours], //Hours; no leading zero for single-digit hours (12-hour clock). | ||
hh: ["0[1-9]|1[0-2]", Date.prototype.setHours, "hours", function () { | ||
return pad(Date.prototype.getHours.call(this), 2); | ||
}], //Hours; leading zero for single-digit hours (12-hour clock). | ||
hx: [function (x) { | ||
return `[0-9]{${x}}`; | ||
}, Date.prototype.setHours, "hours", function (x) { | ||
return Date.prototype.getHours; | ||
}], //Hours; no limit; set maximum digits | ||
H: ["1?[0-9]|2[0-3]", Date.prototype.setHours, "hours", Date.prototype.getHours], //Hours; no leading zero for single-digit hours (24-hour clock). | ||
HH: ["0[0-9]|1[0-9]|2[0-3]", Date.prototype.setHours, "hours", function () { | ||
return pad(Date.prototype.getHours.call(this), 2); | ||
}], //Hours; leading zero for single-digit hours (24-hour clock). | ||
Hx: [function (x) { | ||
return `[0-9]{${x}}`; | ||
}, Date.prototype.setHours, "hours", function (x) { | ||
return function () { | ||
return pad(Date.prototype.getHours.call(this), x); | ||
}; | ||
}], //Hours; no limit; set maximum digits | ||
M: ["[1-5]?[0-9]", Date.prototype.setMinutes, "minutes", Date.prototype.getMinutes], //Minutes; no leading zero for single-digit minutes. Uppercase M unlike CF timeFormat's m to avoid conflict with months. | ||
MM: ["0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]", Date.prototype.setMinutes, "minutes", function () { | ||
return pad(Date.prototype.getMinutes.call(this), 2); | ||
}], //Minutes; leading zero for single-digit minutes. Uppercase MM unlike CF timeFormat's mm to avoid conflict with months. | ||
s: ["[1-5]?[0-9]", Date.prototype.setSeconds, "seconds", Date.prototype.getSeconds], //Seconds; no leading zero for single-digit seconds. | ||
ss: ["0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]", Date.prototype.setSeconds, "seconds", function () { | ||
return pad(Date.prototype.getSeconds.call(this), 2); | ||
}], //Seconds; leading zero for single-digit seconds. | ||
l: ["[0-9]{3}", Date.prototype.setMilliseconds, "milliseconds", function () { | ||
return pad(Date.prototype.getMilliseconds.call(this), 3); | ||
}], //Milliseconds. 3 digits. | ||
L: ["[0-9]{2}", Date.prototype.setMilliseconds, "milliseconds", function () { | ||
return pad(Date.prototype.getMilliseconds.call(this), 2); | ||
}], //Milliseconds. 2 digits. | ||
t: ["[ap]", setAMPM, "ampm", getAMPM, 1], //Lowercase, single-character time marker string: a or p. | ||
tt: ["[ap]m", setAMPM, "ampm", getAMPM, 2], //two-character time marker string: am or pm. | ||
T: ["[AP]", setAMPM, "ampm", getAMPM, 1], //single-character time marker string: A or P. | ||
TT: ["[AP]M", setAMPM, "ampm", getAMPM, 2], //two-character time marker string: AM or PM. | ||
Z: [""], //US timezone abbreviation, e.g. EST or MDT. With non-US timezones or in the Opera browser, the GMT/UTC offset is returned, e.g. GMT-0500 | ||
o: [""], //GMT/UTC timezone offset, e.g. -0500 or +0230. | ||
S: [""] //The date's ordinal suffix (st, nd, rd, or th). | ||
}, | ||
formatAlias = { | ||
isoDate: "yyyy-mm-dd", //2007-06-09 | ||
isoTime: "HH:MM:ss", //17:46:21 | ||
isoDateTime: "yyyy-mm-dd'T'HH:MM:ss", //2007-06-09T17:46:21 | ||
isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'" //2007-06-09T22:46:21Z | ||
}; | ||
useDateObject = false, | ||
//supported codes for formatting | ||
//http://blog.stevenlevithan.com/archives/date-time-format | ||
//https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings?view=netframework-4.7 | ||
formatCode = { //regex, valueSetter, type, displayformatter | ||
d: ["[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", Date.prototype.getDate], //Day of the month as digits; no leading zero for single-digit days. | ||
dd: ["0[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", function () { | ||
return pad(Date.prototype.getDate.call(this), 2); | ||
}], //Day of the month as digits; leading zero for single-digit days. | ||
ddd: [""], //Day of the week as a three-letter abbreviation. | ||
dddd: [""], //Day of the week as its full name. | ||
m: ["[1-9]|1[012]", function (val) { | ||
let mval = val ? parseInt(val) : 0; | ||
if (mval > 0) mval--; | ||
return Date.prototype.setMonth.call(this, mval); | ||
}, "month", function () { | ||
return Date.prototype.getMonth.call(this) + 1; | ||
}], //Month as digits; no leading zero for single-digit months. | ||
mm: ["0[1-9]|1[012]", function (val) { | ||
let mval = val ? parseInt(val) : 0; | ||
if (mval > 0) mval--; | ||
return Date.prototype.setMonth.call(this, mval); | ||
}, "month", function () { | ||
return pad(Date.prototype.getMonth.call(this) + 1, 2); | ||
}], //Month as digits; leading zero for single-digit months. | ||
mmm: [""], //Month as a three-letter abbreviation. | ||
mmmm: [""], //Month as its full name. | ||
yy: ["[0-9]{2}", Date.prototype.setFullYear, "year", function () { | ||
return pad(Date.prototype.getFullYear.call(this), 2); | ||
}], //Year as last two digits; leading zero for years less than 10. | ||
yyyy: ["[0-9]{4}", Date.prototype.setFullYear, "year", function () { | ||
return pad(Date.prototype.getFullYear.call(this), 4); | ||
}], | ||
h: ["[1-9]|1[0-2]", Date.prototype.setHours, "hours", Date.prototype.getHours], //Hours; no leading zero for single-digit hours (12-hour clock). | ||
hh: ["0[1-9]|1[0-2]", Date.prototype.setHours, "hours", function () { | ||
return pad(Date.prototype.getHours.call(this), 2); | ||
}], //Hours; leading zero for single-digit hours (12-hour clock). | ||
hx: [function (x) { | ||
return `[0-9]{${x}}`; | ||
}, Date.prototype.setHours, "hours", function (x) { | ||
return Date.prototype.getHours; | ||
}], //Hours; no limit; set maximum digits | ||
H: ["1?[0-9]|2[0-3]", Date.prototype.setHours, "hours", Date.prototype.getHours], //Hours; no leading zero for single-digit hours (24-hour clock). | ||
HH: ["0[0-9]|1[0-9]|2[0-3]", Date.prototype.setHours, "hours", function () { | ||
return pad(Date.prototype.getHours.call(this), 2); | ||
}], //Hours; leading zero for single-digit hours (24-hour clock). | ||
Hx: [function (x) { | ||
return `[0-9]{${x}}`; | ||
}, Date.prototype.setHours, "hours", function (x) { | ||
return function () { | ||
return pad(Date.prototype.getHours.call(this), x); | ||
}; | ||
}], //Hours; no limit; set maximum digits | ||
M: ["[1-5]?[0-9]", Date.prototype.setMinutes, "minutes", Date.prototype.getMinutes], //Minutes; no leading zero for single-digit minutes. Uppercase M unlike CF timeFormat's m to avoid conflict with months. | ||
MM: ["0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]", Date.prototype.setMinutes, "minutes", function () { | ||
return pad(Date.prototype.getMinutes.call(this), 2); | ||
}], //Minutes; leading zero for single-digit minutes. Uppercase MM unlike CF timeFormat's mm to avoid conflict with months. | ||
s: ["[1-5]?[0-9]", Date.prototype.setSeconds, "seconds", Date.prototype.getSeconds], //Seconds; no leading zero for single-digit seconds. | ||
ss: ["0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]", Date.prototype.setSeconds, "seconds", function () { | ||
return pad(Date.prototype.getSeconds.call(this), 2); | ||
}], //Seconds; leading zero for single-digit seconds. | ||
l: ["[0-9]{3}", Date.prototype.setMilliseconds, "milliseconds", function () { | ||
return pad(Date.prototype.getMilliseconds.call(this), 3); | ||
}], //Milliseconds. 3 digits. | ||
L: ["[0-9]{2}", Date.prototype.setMilliseconds, "milliseconds", function () { | ||
return pad(Date.prototype.getMilliseconds.call(this), 2); | ||
}], //Milliseconds. 2 digits. | ||
t: ["[ap]", setAMPM, "ampm", getAMPM, 1], //Lowercase, single-character time marker string: a or p. | ||
tt: ["[ap]m", setAMPM, "ampm", getAMPM, 2], //two-character time marker string: am or pm. | ||
T: ["[AP]", setAMPM, "ampm", getAMPM, 1], //single-character time marker string: A or P. | ||
TT: ["[AP]M", setAMPM, "ampm", getAMPM, 2], //two-character time marker string: AM or PM. | ||
Z: [".*", undefined, "Z", getTimeZoneAbbreviated], //US timezone abbreviation, e.g. EST or MDT. With non-US timezones or in the Opera browser, the GMT/UTC offset is returned, e.g. GMT-0500 | ||
o: [""], //GMT/UTC timezone offset, e.g. -0500 or +0230. | ||
S: [""] //The date's ordinal suffix (st, nd, rd, or th). | ||
}, | ||
formatAlias = { | ||
isoDate: "yyyy-mm-dd", //2007-06-09 | ||
isoTime: "HH:MM:ss", //17:46:21 | ||
isoDateTime: "yyyy-mm-dd'T'HH:MM:ss", //2007-06-09T17:46:21 | ||
isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'" //2007-06-09T22:46:21Z | ||
}; | ||
function setAMPM(value) { | ||
const hours = this.getHours(); | ||
if (value.toLowerCase().includes("p")) { | ||
this.setHours(hours + 12); | ||
// console.log("setAMPM + 12"); | ||
} else if (value.toLowerCase().includes("a") && hours >= 12) { | ||
this.setHours(hours - 12); | ||
} | ||
const hours = this.getHours(); | ||
if (value.toLowerCase().includes("p")) { | ||
this.setHours(hours + 12); | ||
// console.log("setAMPM + 12"); | ||
} else if (value.toLowerCase().includes("a") && hours >= 12) { | ||
this.setHours(hours - 12); | ||
} | ||
} | ||
function getAMPM() { | ||
// console.log("getAMPM"); | ||
let date = this, | ||
hours = date.getHours(); | ||
hours = hours || 12; | ||
return hours >= 12 ? "PM" : "AM"; | ||
} | ||
function getTimeZoneAbbreviated() { | ||
//not perfect, but ok for now | ||
let date = this, {1: tz} = date.toString().match(/\((.+)\)/); | ||
if (tz.includes(" ")) { | ||
tz = tz.replace("-", " ").toUpperCase(); | ||
tz = tz.split(" ").map(([first]) => first).join(""); | ||
} | ||
return tz; | ||
} | ||
function formatcode(match) { | ||
var dynMatches = new RegExp("\\d+$").exec(match[0]); | ||
if (dynMatches && dynMatches[0] !== undefined) { | ||
var fcode = formatCode[match[0][0] + "x"].slice(""); | ||
fcode[0] = fcode[0](dynMatches[0]); | ||
fcode[3] = fcode[3](dynMatches[0]); | ||
var dynMatches = new RegExp("\\d+$").exec(match[0]); | ||
if (dynMatches && dynMatches[0] !== undefined) { | ||
var fcode = formatCode[match[0][0] + "x"].slice(""); | ||
fcode[0] = fcode[0](dynMatches[0]); | ||
fcode[3] = fcode[3](dynMatches[0]); | ||
return fcode; | ||
} else if (formatCode[match[0]]) { | ||
return formatCode[match[0]]; | ||
} | ||
return fcode; | ||
} else if (formatCode[match[0]]) { | ||
return formatCode[match[0]]; | ||
} | ||
} | ||
function getTokenizer(opts) { | ||
if (!opts.tokenizer) { | ||
var tokens = [], dyntokens = []; | ||
for (var ndx in formatCode) { | ||
if (/\.*x$/.test(ndx)) { | ||
var dynToken = ndx[0] + "\\d+"; | ||
if (dyntokens.indexOf(dynToken) === -1) { | ||
dyntokens.push(dynToken); | ||
} | ||
} else if (tokens.indexOf(ndx[0]) === -1) { | ||
tokens.push(ndx[0]); | ||
} | ||
} | ||
opts.tokenizer = "(" + (dyntokens.length > 0 ? dyntokens.join("|") + "|" : "") + tokens.join("+|") + ")+?|."; | ||
opts.tokenizer = new RegExp(opts.tokenizer, "g"); | ||
} | ||
if (!opts.tokenizer) { | ||
var tokens = [], dyntokens = []; | ||
for (var ndx in formatCode) { | ||
if (/\.*x$/.test(ndx)) { | ||
var dynToken = ndx[0] + "\\d+"; | ||
if (dyntokens.indexOf(dynToken) === -1) { | ||
dyntokens.push(dynToken); | ||
} | ||
} else if (tokens.indexOf(ndx[0]) === -1) { | ||
tokens.push(ndx[0]); | ||
} | ||
} | ||
opts.tokenizer = "(" + (dyntokens.length > 0 ? dyntokens.join("|") + "|" : "") + tokens.join("+|") + ")+?|."; | ||
opts.tokenizer = new RegExp(opts.tokenizer, "g"); | ||
} | ||
return opts.tokenizer; | ||
return opts.tokenizer; | ||
} | ||
function prefillYear(dateParts, currentResult, opts) { | ||
if (dateParts.year !== dateParts.rawyear) { | ||
var crrntyear = currentYear.toString(), | ||
enteredPart = dateParts.rawyear.replace(/[^0-9]/g, ""), | ||
currentYearPart = crrntyear.slice(0, enteredPart.length), | ||
currentYearNextPart = crrntyear.slice(enteredPart.length); | ||
if (enteredPart.length === 2 && enteredPart === currentYearPart) { | ||
const entryCurrentYear = new Date(currentYear, dateParts.month - 1, dateParts.day); | ||
if (dateParts.day == entryCurrentYear.getDate() && (!opts.max || opts.max.date.getTime() >= entryCurrentYear.getTime())) { | ||
//update dateParts | ||
dateParts.date.setFullYear(currentYear); | ||
dateParts.year = crrntyear; | ||
//update result | ||
currentResult.insert = [{ | ||
pos: currentResult.pos + 1, | ||
c: currentYearNextPart[0] | ||
}, { | ||
pos: currentResult.pos + 2, | ||
c: currentYearNextPart[1] | ||
}]; | ||
} | ||
} | ||
} | ||
if (dateParts.year !== dateParts.rawyear) { | ||
var crrntyear = currentYear.toString(), | ||
enteredPart = dateParts.rawyear.replace(/[^0-9]/g, ""), | ||
currentYearPart = crrntyear.slice(0, enteredPart.length), | ||
currentYearNextPart = crrntyear.slice(enteredPart.length); | ||
if (enteredPart.length === 2 && enteredPart === currentYearPart) { | ||
const entryCurrentYear = new Date(currentYear, dateParts.month - 1, dateParts.day); | ||
if (dateParts.day == entryCurrentYear.getDate() && (!opts.max || opts.max.date.getTime() >= entryCurrentYear.getTime())) { | ||
//update dateParts | ||
dateParts.date.setFullYear(currentYear); | ||
dateParts.year = crrntyear; | ||
//update result | ||
currentResult.insert = [{ | ||
pos: currentResult.pos + 1, | ||
c: currentYearNextPart[0] | ||
}, { | ||
pos: currentResult.pos + 2, | ||
c: currentYearNextPart[1] | ||
}]; | ||
} | ||
} | ||
} | ||
return currentResult; | ||
return currentResult; | ||
} | ||
function isValidDate(dateParts, currentResult, opts) { | ||
if (!useDateObject) return true; | ||
if (dateParts.rawday === undefined | ||
|| (!isFinite(dateParts.rawday) && new Date(dateParts.date.getFullYear(), isFinite(dateParts.rawmonth) ? dateParts.month : dateParts.date.getMonth() + 1, 0).getDate() >= dateParts.day) | ||
|| (dateParts.day == "29" && (!isFinite(dateParts.rawyear) || dateParts.rawyear === undefined || dateParts.rawyear === "")) | ||
|| new Date(dateParts.date.getFullYear(), isFinite(dateParts.rawmonth) ? dateParts.month : dateParts.date.getMonth() + 1, 0).getDate() >= dateParts.day) { | ||
return currentResult; | ||
} else { //take corrective action if possible | ||
if (dateParts.day == "29") { | ||
var tokenMatch = getTokenMatch(currentResult.pos, opts); | ||
if (tokenMatch.targetMatch[0] === "yyyy" && currentResult.pos - tokenMatch.targetMatchIndex === 2) { | ||
currentResult.remove = currentResult.pos + 1; | ||
return currentResult; | ||
} | ||
} else if (dateParts.month == "02" && dateParts.day == "30" && currentResult.c !== undefined) { | ||
dateParts.day = "03"; | ||
dateParts.date.setDate(3); | ||
dateParts.date.setMonth(1); | ||
currentResult.insert = [{pos: currentResult.pos, c: "0"}, {pos: currentResult.pos + 1, c: currentResult.c}]; | ||
currentResult.caret = seekNext.call(this, currentResult.pos + 1); | ||
return currentResult; | ||
} | ||
return false; | ||
} | ||
if (!useDateObject) return true; | ||
if (dateParts.rawday === undefined | ||
|| (!isFinite(dateParts.rawday) && new Date(dateParts.date.getFullYear(), isFinite(dateParts.rawmonth) ? dateParts.month : dateParts.date.getMonth() + 1, 0).getDate() >= dateParts.day) | ||
|| (dateParts.day == "29" && (!isFinite(dateParts.rawyear) || dateParts.rawyear === undefined || dateParts.rawyear === "")) | ||
|| new Date(dateParts.date.getFullYear(), isFinite(dateParts.rawmonth) ? dateParts.month : dateParts.date.getMonth() + 1, 0).getDate() >= dateParts.day) { | ||
return currentResult; | ||
} else { //take corrective action if possible | ||
if (dateParts.day == "29") { | ||
var tokenMatch = getTokenMatch(currentResult.pos, opts); | ||
if (tokenMatch.targetMatch[0] === "yyyy" && currentResult.pos - tokenMatch.targetMatchIndex === 2) { | ||
currentResult.remove = currentResult.pos + 1; | ||
return currentResult; | ||
} | ||
} else if (dateParts.month == "02" && dateParts.day == "30" && currentResult.c !== undefined) { | ||
dateParts.day = "03"; | ||
dateParts.date.setDate(3); | ||
dateParts.date.setMonth(1); | ||
currentResult.insert = [{pos: currentResult.pos, c: "0"}, {pos: currentResult.pos + 1, c: currentResult.c}]; | ||
currentResult.caret = seekNext.call(this, currentResult.pos + 1); | ||
return currentResult; | ||
} | ||
return false; | ||
} | ||
} | ||
function isDateInRange(dateParts, result, opts, maskset, fromCheckval) { | ||
if (!result) return result; | ||
if (result && opts.min) { | ||
if (/*useDateObject && (dateParts["year"] === undefined || dateParts["yearSet"]) && */opts.min.date.getTime() === opts.min.date.getTime()) { | ||
let match; | ||
dateParts.reset(); | ||
getTokenizer(opts).lastIndex = 0; | ||
while ((match = getTokenizer(opts).exec(opts.inputFormat))) { | ||
var fcode; | ||
if ((fcode = formatcode(match))) { | ||
if (fcode[3]) { | ||
var setFn = fcode[1]; | ||
var current = dateParts[fcode[2]], | ||
minVal = opts.min[fcode[2]], | ||
maxVal = opts.max ? opts.max[fcode[2]] : minVal, | ||
curVal = []; | ||
if (!result) return result; | ||
if (result && opts.min) { | ||
if (/*useDateObject && (dateParts["year"] === undefined || dateParts["yearSet"]) && */opts.min.date.getTime() === opts.min.date.getTime()) { | ||
let match; | ||
dateParts.reset(); | ||
getTokenizer(opts).lastIndex = 0; | ||
while ((match = getTokenizer(opts).exec(opts.inputFormat))) { | ||
var fcode; | ||
if ((fcode = formatcode(match))) { | ||
if (fcode[3]) { | ||
var setFn = fcode[1]; | ||
var current = dateParts[fcode[2]], | ||
minVal = opts.min[fcode[2]], | ||
maxVal = opts.max ? opts.max[fcode[2]] : minVal, | ||
curVal = []; | ||
let forceCurrentValue = false; | ||
for (let i = 0; i < minVal.length; i++) { | ||
if (maskset.validPositions[i + match.index] === undefined && !forceCurrentValue) { | ||
curVal[i] = minVal[i]; | ||
// ADD +1 to whoile | ||
if (fcode[2] === "year" && current.length - 1 == i && minVal != maxVal) | ||
curVal = (parseInt(curVal.join("")) + 1).toString().split(""); | ||
if (fcode[2] === "ampm" && minVal != maxVal && opts.min.date.getTime() > dateParts.date.getTime()) | ||
curVal[i] = maxVal[i]; | ||
} else { | ||
curVal[i] = current[i]; | ||
forceCurrentValue = forceCurrentValue || current[i] > minVal[i]; | ||
} | ||
} | ||
let forceCurrentValue = false; | ||
for (let i = 0; i < minVal.length; i++) { | ||
if (maskset.validPositions[i + match.index] === undefined && !forceCurrentValue) { | ||
curVal[i] = minVal[i]; | ||
// ADD +1 to whoile | ||
if (fcode[2] === "year" && current.length - 1 == i && minVal != maxVal) | ||
curVal = (parseInt(curVal.join("")) + 1).toString().split(""); | ||
if (fcode[2] === "ampm" && minVal != maxVal && opts.min.date.getTime() > dateParts.date.getTime()) | ||
curVal[i] = maxVal[i]; | ||
} else { | ||
curVal[i] = current[i]; | ||
forceCurrentValue = forceCurrentValue || current[i] > minVal[i]; | ||
} | ||
} | ||
setFn.call(dateParts._date, curVal.join("")); | ||
} | ||
} | ||
} | ||
setFn.call(dateParts._date, curVal.join("")); | ||
} | ||
} | ||
} | ||
result = opts.min.date.getTime() <= dateParts.date.getTime(); | ||
dateParts.reInit(); | ||
} | ||
} | ||
result = opts.min.date.getTime() <= dateParts.date.getTime(); | ||
dateParts.reInit(); | ||
} | ||
} | ||
if (result && opts.max) { | ||
if (opts.max.date.getTime() === opts.max.date.getTime()) { | ||
result = opts.max.date.getTime() >= dateParts.date.getTime(); | ||
} | ||
} | ||
return result; | ||
if (result && opts.max) { | ||
if (opts.max.date.getTime() === opts.max.date.getTime()) { | ||
result = opts.max.date.getTime() >= dateParts.date.getTime(); | ||
} | ||
} | ||
return result; | ||
} | ||
@@ -335,37 +348,37 @@ | ||
function parse(format, dateObjValue, opts, raw) { | ||
//parse format to regex string | ||
var mask = "", match, fcode; | ||
getTokenizer(opts).lastIndex = 0; | ||
while ((match = getTokenizer(opts).exec(format))) { | ||
if (dateObjValue === undefined) { | ||
if ((fcode = formatcode(match))) { | ||
mask += "(" + fcode[0] + ")"; | ||
} else { | ||
switch (match[0]) { | ||
case "[": | ||
mask += "("; | ||
break; | ||
case "]": | ||
mask += ")?"; | ||
break; | ||
default: | ||
mask += escapeRegex(match[0]); | ||
} | ||
} | ||
} else { | ||
if ((fcode = formatcode(match))) { | ||
if (raw !== true && fcode[3]) { | ||
var getFn = fcode[3]; | ||
mask += getFn.call(dateObjValue.date); | ||
} else if (fcode[2]) { | ||
mask += dateObjValue["raw" + fcode[2]]; | ||
} else { | ||
mask += match[0]; | ||
} | ||
} else { | ||
mask += match[0]; | ||
} | ||
} | ||
} | ||
return mask; | ||
//parse format to regex string | ||
var mask = "", match, fcode; | ||
getTokenizer(opts).lastIndex = 0; | ||
while ((match = getTokenizer(opts).exec(format))) { | ||
if (dateObjValue === undefined) { | ||
if ((fcode = formatcode(match))) { | ||
mask += "(" + fcode[0] + ")"; | ||
} else { | ||
switch (match[0]) { | ||
case "[": | ||
mask += "("; | ||
break; | ||
case "]": | ||
mask += ")?"; | ||
break; | ||
default: | ||
mask += escapeRegex(match[0]); | ||
} | ||
} | ||
} else { | ||
if ((fcode = formatcode(match))) { | ||
if (raw !== true && fcode[3]) { | ||
var getFn = fcode[3]; | ||
mask += getFn.call(dateObjValue.date); | ||
} else if (fcode[2]) { | ||
mask += dateObjValue["raw" + fcode[2]]; | ||
} else { | ||
mask += match[0]; | ||
} | ||
} else { | ||
mask += match[0]; | ||
} | ||
} | ||
} | ||
return mask; | ||
} | ||
@@ -375,39 +388,39 @@ | ||
function pad(val, len, right) { | ||
val = String(val); | ||
len = len || 2; | ||
while (val.length < len) val = right ? val + "0" : "0" + val; | ||
return val; | ||
val = String(val); | ||
len = len || 2; | ||
while (val.length < len) val = right ? val + "0" : "0" + val; | ||
return val; | ||
} | ||
function analyseMask(mask, format, opts) { | ||
if (typeof mask === "string") { | ||
return new DateObject(mask, format, opts); | ||
} else if (mask && typeof mask === "object" && Object.prototype.hasOwnProperty.call(mask, "date")) { | ||
return mask; | ||
} | ||
return undefined; | ||
if (typeof mask === "string") { | ||
return new DateObject(mask, format, opts); | ||
} else if (mask && typeof mask === "object" && Object.prototype.hasOwnProperty.call(mask, "date")) { | ||
return mask; | ||
} | ||
return undefined; | ||
} | ||
function importDate(dateObj, opts) { | ||
return parse(opts.inputFormat, {date: dateObj}, opts); | ||
return parse(opts.inputFormat, {date: dateObj}, opts); | ||
} | ||
function getTokenMatch(pos, opts) { | ||
var calcPos = 0, targetMatch, match, matchLength = 0; | ||
getTokenizer(opts).lastIndex = 0; | ||
while ((match = getTokenizer(opts).exec(opts.inputFormat))) { | ||
var dynMatches = new RegExp("\\d+$").exec(match[0]); | ||
matchLength = dynMatches ? parseInt(dynMatches[0]) : match[0].length; | ||
calcPos += matchLength; | ||
if (calcPos >= pos + 1) { | ||
targetMatch = match; | ||
match = getTokenizer(opts).exec(opts.inputFormat); | ||
break; | ||
} | ||
} | ||
return { | ||
targetMatchIndex: calcPos - matchLength, | ||
nextMatch: match, | ||
targetMatch: targetMatch | ||
}; | ||
var calcPos = 0, targetMatch, match, matchLength = 0; | ||
getTokenizer(opts).lastIndex = 0; | ||
while ((match = getTokenizer(opts).exec(opts.inputFormat))) { | ||
var dynMatches = new RegExp("\\d+$").exec(match[0]); | ||
matchLength = dynMatches ? parseInt(dynMatches[0]) : match[0].length; | ||
calcPos += matchLength; | ||
if (calcPos >= pos + 1) { | ||
targetMatch = match; | ||
match = getTokenizer(opts).exec(opts.inputFormat); | ||
break; | ||
} | ||
} | ||
return { | ||
targetMatchIndex: calcPos - matchLength, | ||
nextMatch: match, | ||
targetMatch: targetMatch | ||
}; | ||
} | ||
@@ -417,163 +430,163 @@ | ||
Inputmask.extendAliases({ | ||
"datetime": { | ||
mask: function (opts) { | ||
//do not allow numeric input in datetime alias | ||
opts.numericInput = false; | ||
"datetime": { | ||
mask: function (opts) { | ||
//do not allow numeric input in datetime alias | ||
opts.numericInput = false; | ||
//localize | ||
formatCode.S = opts.i18n.ordinalSuffix.join("|"); | ||
//localize | ||
formatCode.S = opts.i18n.ordinalSuffix.join("|"); | ||
opts.inputFormat = formatAlias[opts.inputFormat] || opts.inputFormat; //resolve possible formatAlias | ||
opts.displayFormat = formatAlias[opts.displayFormat] || opts.displayFormat || opts.inputFormat; //resolve possible formatAlias | ||
opts.outputFormat = formatAlias[opts.outputFormat] || opts.outputFormat || opts.inputFormat; //resolve possible formatAlias | ||
opts.placeholder = opts.placeholder !== "" ? opts.placeholder : opts.inputFormat.replace(/[[\]]/, ""); | ||
opts.regex = parse(opts.inputFormat, undefined, opts); | ||
opts.min = analyseMask(opts.min, opts.inputFormat, opts); | ||
opts.max = analyseMask(opts.max, opts.inputFormat, opts); | ||
return null; //migrate to regex mask | ||
}, | ||
placeholder: "", //set default as none (~ auto); when a custom placeholder is passed it will be used | ||
inputFormat: "isoDateTime", //format used to input the date | ||
displayFormat: undefined, //visual format when the input looses focus | ||
outputFormat: undefined, //unmasking format | ||
min: null, //needs to be in the same format as the inputfornat | ||
max: null, //needs to be in the same format as the inputfornat, | ||
skipOptionalPartCharacter: "", | ||
// Internationalization strings | ||
i18n: { | ||
dayNames: [ | ||
"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", | ||
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" | ||
], | ||
monthNames: [ | ||
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", | ||
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" | ||
], | ||
ordinalSuffix: ["st", "nd", "rd", "th"] | ||
}, | ||
preValidation: function (buffer, pos, c, isSelection, opts, maskset, caretPos, strict) { | ||
if (strict) return true; | ||
if (isNaN(c) && buffer[pos] !== c) { | ||
var tokenMatch = getTokenMatch(pos, opts); | ||
if (tokenMatch.nextMatch && tokenMatch.nextMatch[0] === c && tokenMatch.targetMatch[0].length > 1) { | ||
var validator = formatCode[tokenMatch.targetMatch[0]][0]; | ||
if (new RegExp(validator).test("0" + buffer[pos - 1])) { | ||
buffer[pos] = buffer[pos - 1]; | ||
buffer[pos - 1] = "0"; | ||
return { | ||
fuzzy: true, | ||
buffer: buffer, | ||
refreshFromBuffer: {start: pos - 1, end: pos + 1}, | ||
pos: pos + 1 | ||
}; | ||
} | ||
} | ||
} | ||
return true; | ||
}, | ||
postValidation: function (buffer, pos, c, currentResult, opts, maskset, strict, fromCheckval) { | ||
const inputmask = this; | ||
opts.inputFormat = formatAlias[opts.inputFormat] || opts.inputFormat; //resolve possible formatAlias | ||
opts.displayFormat = formatAlias[opts.displayFormat] || opts.displayFormat || opts.inputFormat; //resolve possible formatAlias | ||
opts.outputFormat = formatAlias[opts.outputFormat] || opts.outputFormat || opts.inputFormat; //resolve possible formatAlias | ||
opts.placeholder = opts.placeholder !== "" ? opts.placeholder : opts.inputFormat.replace(/[[\]]/, ""); | ||
opts.regex = parse(opts.inputFormat, undefined, opts); | ||
opts.min = analyseMask(opts.min, opts.inputFormat, opts); | ||
opts.max = analyseMask(opts.max, opts.inputFormat, opts); | ||
return null; //migrate to regex mask | ||
}, | ||
placeholder: "", //set default as none (~ auto); when a custom placeholder is passed it will be used | ||
inputFormat: "isoDateTime", //format used to input the date | ||
displayFormat: null, //visual format when the input looses focus | ||
outputFormat: null, //unmasking format | ||
min: null, //needs to be in the same format as the inputfornat | ||
max: null, //needs to be in the same format as the inputfornat, | ||
skipOptionalPartCharacter: "", | ||
// Internationalization strings | ||
i18n: { | ||
dayNames: [ | ||
"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", | ||
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" | ||
], | ||
monthNames: [ | ||
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", | ||
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" | ||
], | ||
ordinalSuffix: ["st", "nd", "rd", "th"] | ||
}, | ||
preValidation: function (buffer, pos, c, isSelection, opts, maskset, caretPos, strict) { | ||
if (strict) return true; | ||
if (isNaN(c) && buffer[pos] !== c) { | ||
var tokenMatch = getTokenMatch(pos, opts); | ||
if (tokenMatch.nextMatch && tokenMatch.nextMatch[0] === c && tokenMatch.targetMatch[0].length > 1) { | ||
var validator = formatCode[tokenMatch.targetMatch[0]][0]; | ||
if (new RegExp(validator).test("0" + buffer[pos - 1])) { | ||
buffer[pos] = buffer[pos - 1]; | ||
buffer[pos - 1] = "0"; | ||
return { | ||
fuzzy: true, | ||
buffer: buffer, | ||
refreshFromBuffer: {start: pos - 1, end: pos + 1}, | ||
pos: pos + 1 | ||
}; | ||
} | ||
} | ||
} | ||
return true; | ||
}, | ||
postValidation: function (buffer, pos, c, currentResult, opts, maskset, strict, fromCheckval) { | ||
const inputmask = this; | ||
if (strict) return true; | ||
var tokenMatch, validator; | ||
if (currentResult === false) { //try some shifting | ||
tokenMatch = getTokenMatch(pos + 1, opts); | ||
if (tokenMatch.targetMatch && tokenMatch.targetMatchIndex === pos && tokenMatch.targetMatch[0].length > 1 && formatCode[tokenMatch.targetMatch[0]] !== undefined) { | ||
validator = formatCode[tokenMatch.targetMatch[0]][0]; | ||
} else { | ||
tokenMatch = getTokenMatch(pos + 2, opts); | ||
if (tokenMatch.targetMatch && tokenMatch.targetMatchIndex === pos + 1 && tokenMatch.targetMatch[0].length > 1 && formatCode[tokenMatch.targetMatch[0]] !== undefined) { | ||
validator = formatCode[tokenMatch.targetMatch[0]][0]; | ||
} | ||
} | ||
if (validator !== undefined) { | ||
if (maskset.validPositions[pos + 1] !== undefined && new RegExp(validator).test(c + "0")) { | ||
buffer[pos] = c; | ||
buffer[pos + 1] = "0"; | ||
currentResult = { | ||
//insert: [{pos: pos, c: "0"}, {pos: pos + 1, c: c}], | ||
pos: pos + 2, //this will triggeer a refreshfrombuffer | ||
caret: pos | ||
}; | ||
} else if (new RegExp(validator).test("0" + c)) { | ||
buffer[pos] = "0"; | ||
buffer[pos + 1] = c; | ||
currentResult = { | ||
//insert: [{pos: pos, c: "0"}, {pos: pos + 1, c: c}], | ||
pos: pos + 2 //this will triggeer a refreshfrombuffer | ||
}; | ||
} | ||
} | ||
if (strict) return true; | ||
var tokenMatch, validator; | ||
if (currentResult === false) { //try some shifting | ||
tokenMatch = getTokenMatch(pos + 1, opts); | ||
if (tokenMatch.targetMatch && tokenMatch.targetMatchIndex === pos && tokenMatch.targetMatch[0].length > 1 && formatCode[tokenMatch.targetMatch[0]] !== undefined) { | ||
validator = formatCode[tokenMatch.targetMatch[0]][0]; | ||
} else { | ||
tokenMatch = getTokenMatch(pos + 2, opts); | ||
if (tokenMatch.targetMatch && tokenMatch.targetMatchIndex === pos + 1 && tokenMatch.targetMatch[0].length > 1 && formatCode[tokenMatch.targetMatch[0]] !== undefined) { | ||
validator = formatCode[tokenMatch.targetMatch[0]][0]; | ||
} | ||
} | ||
if (validator !== undefined) { | ||
if (maskset.validPositions[pos + 1] !== undefined && new RegExp(validator).test(c + "0")) { | ||
buffer[pos] = c; | ||
buffer[pos + 1] = "0"; | ||
currentResult = { | ||
//insert: [{pos: pos, c: "0"}, {pos: pos + 1, c: c}], | ||
pos: pos + 2, //this will triggeer a refreshfrombuffer | ||
caret: pos | ||
}; | ||
} else if (new RegExp(validator).test("0" + c)) { | ||
buffer[pos] = "0"; | ||
buffer[pos + 1] = c; | ||
currentResult = { | ||
//insert: [{pos: pos, c: "0"}, {pos: pos + 1, c: c}], | ||
pos: pos + 2 //this will triggeer a refreshfrombuffer | ||
}; | ||
} | ||
} | ||
if (currentResult === false) return currentResult; | ||
} | ||
if (currentResult === false) return currentResult; | ||
} | ||
if (currentResult.fuzzy) { | ||
buffer = currentResult.buffer; | ||
pos = currentResult.pos; | ||
} | ||
if (currentResult.fuzzy) { | ||
buffer = currentResult.buffer; | ||
pos = currentResult.pos; | ||
} | ||
//full validate target | ||
tokenMatch = getTokenMatch(pos, opts); | ||
if (tokenMatch.targetMatch && tokenMatch.targetMatch[0] && formatCode[tokenMatch.targetMatch[0]] !== undefined) { | ||
let fcode = formatCode[tokenMatch.targetMatch[0]]; | ||
validator = fcode[0]; | ||
var part = buffer.slice(tokenMatch.targetMatchIndex, tokenMatch.targetMatchIndex + tokenMatch.targetMatch[0].length); | ||
if (new RegExp(validator).test(part.join("")) === false && tokenMatch.targetMatch[0].length === 2 && maskset.validPositions[tokenMatch.targetMatchIndex] && maskset.validPositions[tokenMatch.targetMatchIndex + 1]) { | ||
maskset.validPositions[tokenMatch.targetMatchIndex + 1].input = "0"; | ||
} | ||
if (fcode[2] == "year") { | ||
var _buffer = getMaskTemplate.call(inputmask, false, 1, undefined, true); | ||
for (let i = pos + 1; i < buffer.length; i++) { | ||
buffer[i] = _buffer[i]; | ||
delete maskset.validPositions[i]; | ||
} | ||
} | ||
} | ||
//full validate target | ||
tokenMatch = getTokenMatch(pos, opts); | ||
if (tokenMatch.targetMatch && tokenMatch.targetMatch[0] && formatCode[tokenMatch.targetMatch[0]] !== undefined) { | ||
let fcode = formatCode[tokenMatch.targetMatch[0]]; | ||
validator = fcode[0]; | ||
var part = buffer.slice(tokenMatch.targetMatchIndex, tokenMatch.targetMatchIndex + tokenMatch.targetMatch[0].length); | ||
if (new RegExp(validator).test(part.join("")) === false && tokenMatch.targetMatch[0].length === 2 && maskset.validPositions[tokenMatch.targetMatchIndex] && maskset.validPositions[tokenMatch.targetMatchIndex + 1]) { | ||
maskset.validPositions[tokenMatch.targetMatchIndex + 1].input = "0"; | ||
} | ||
if (fcode[2] == "year") { | ||
var _buffer = getMaskTemplate.call(inputmask, false, 1, undefined, true); | ||
for (let i = pos + 1; i < buffer.length; i++) { | ||
buffer[i] = _buffer[i]; | ||
delete maskset.validPositions[i]; | ||
} | ||
} | ||
} | ||
var result = currentResult, dateParts = analyseMask(buffer.join(""), opts.inputFormat, opts); | ||
if (result && dateParts.date.getTime() === dateParts.date.getTime()) { //check for a valid date ~ an invalid date returns NaN which isn't equal | ||
if (opts.prefillYear) result = prefillYear(dateParts, result, opts); | ||
result = isValidDate.call(inputmask, dateParts, result, opts); | ||
result = isDateInRange(dateParts, result, opts, maskset, fromCheckval); | ||
} | ||
var result = currentResult, dateParts = analyseMask(buffer.join(""), opts.inputFormat, opts); | ||
if (result && dateParts.date.getTime() === dateParts.date.getTime()) { //check for a valid date ~ an invalid date returns NaN which isn't equal | ||
if (opts.prefillYear) result = prefillYear(dateParts, result, opts); | ||
result = isValidDate.call(inputmask, dateParts, result, opts); | ||
result = isDateInRange(dateParts, result, opts, maskset, fromCheckval); | ||
} | ||
if (pos !== undefined && result && currentResult.pos !== pos) { | ||
return { | ||
buffer: parse(opts.inputFormat, dateParts, opts).split(""), | ||
refreshFromBuffer: {start: pos, end: currentResult.pos}, | ||
pos: currentResult.caret || currentResult.pos //correct caret position | ||
}; | ||
} | ||
if (pos !== undefined && result && currentResult.pos !== pos) { | ||
return { | ||
buffer: parse(opts.inputFormat, dateParts, opts).split(""), | ||
refreshFromBuffer: {start: pos, end: currentResult.pos}, | ||
pos: currentResult.caret || currentResult.pos //correct caret position | ||
}; | ||
} | ||
return result; | ||
}, | ||
onKeyDown: function (e, buffer, caretPos, opts) { | ||
var input = this; | ||
if (e.ctrlKey && e.keyCode === keyCode.RIGHT) { | ||
input.inputmask._valueSet(importDate(new Date(), opts)); | ||
$(input).trigger("setvalue"); | ||
} | ||
}, | ||
onUnMask: function (maskedValue, unmaskedValue, opts) { | ||
return unmaskedValue ? parse(opts.outputFormat, analyseMask(maskedValue, opts.inputFormat, opts), opts, true) : unmaskedValue; | ||
}, | ||
casing: function (elem, test, pos, validPositions) { | ||
if (test.nativeDef.indexOf("[ap]") == 0) return elem.toLowerCase(); | ||
if (test.nativeDef.indexOf("[AP]") == 0) return elem.toUpperCase(); | ||
return elem; | ||
}, | ||
onBeforeMask: function (initialValue, opts) { | ||
if (Object.prototype.toString.call(initialValue) === "[object Date]") { | ||
initialValue = importDate(initialValue, opts); | ||
} | ||
return result; | ||
}, | ||
onKeyDown: function (e, buffer, caretPos, opts) { | ||
var input = this; | ||
if (e.ctrlKey && e.keyCode === keyCode.RIGHT) { | ||
input.inputmask._valueSet(importDate(new Date(), opts)); | ||
$(input).trigger("setvalue"); | ||
} | ||
}, | ||
onUnMask: function (maskedValue, unmaskedValue, opts) { | ||
return unmaskedValue ? parse(opts.outputFormat, analyseMask(maskedValue, opts.inputFormat, opts), opts, true) : unmaskedValue; | ||
}, | ||
casing: function (elem, test, pos, validPositions) { | ||
if (test.nativeDef.indexOf("[ap]") == 0) return elem.toLowerCase(); | ||
if (test.nativeDef.indexOf("[AP]") == 0) return elem.toUpperCase(); | ||
return elem; | ||
}, | ||
onBeforeMask: function (initialValue, opts) { | ||
if (Object.prototype.toString.call(initialValue) === "[object Date]") { | ||
initialValue = importDate(initialValue, opts); | ||
} | ||
return initialValue; | ||
}, | ||
insertMode: false, | ||
shiftPositions: false, | ||
keepStatic: false, | ||
inputmode: "numeric", | ||
prefillYear: true //Allows to disable prefill for datetime year. | ||
} | ||
}); | ||
return initialValue; | ||
}, | ||
insertMode: false, | ||
shiftPositions: false, | ||
keepStatic: false, | ||
inputmode: "numeric", | ||
prefillYear: true //Allows to disable prefill for datetime year. | ||
} | ||
}); |
@@ -12,14 +12,14 @@ /* | ||
Inputmask.extendDefinitions({ | ||
"A": { | ||
validator: "[A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]", | ||
casing: "upper" //auto uppercasing | ||
}, | ||
"&": { //alfanumeric uppercasing | ||
validator: "[0-9A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]", | ||
casing: "upper" | ||
}, | ||
"#": { //hexadecimal | ||
validator: "[0-9A-Fa-f]", | ||
casing: "upper" | ||
} | ||
"A": { | ||
validator: "[A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]", | ||
casing: "upper" //auto uppercasing | ||
}, | ||
"&": { //alfanumeric uppercasing | ||
validator: "[0-9A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]", | ||
casing: "upper" | ||
}, | ||
"#": { //hexadecimal | ||
validator: "[0-9A-Fa-f]", | ||
casing: "upper" | ||
} | ||
}); | ||
@@ -30,9 +30,9 @@ | ||
function ipValidator(chrs, maskset, pos, strict, opts) { | ||
if (pos - 1 > -1 && maskset.buffer[pos - 1] !== ".") { | ||
chrs = maskset.buffer[pos - 1] + chrs; | ||
if (pos - 2 > -1 && maskset.buffer[pos - 2] !== ".") { | ||
chrs = maskset.buffer[pos - 2] + chrs; | ||
} else chrs = "0" + chrs; | ||
} else chrs = "00" + chrs; | ||
return ipValidatorRegex.test(chrs); | ||
if (pos - 1 > -1 && maskset.buffer[pos - 1] !== ".") { | ||
chrs = maskset.buffer[pos - 1] + chrs; | ||
if (pos - 2 > -1 && maskset.buffer[pos - 2] !== ".") { | ||
chrs = maskset.buffer[pos - 2] + chrs; | ||
} else chrs = "0" + chrs; | ||
} else chrs = "00" + chrs; | ||
return ipValidatorRegex.test(chrs); | ||
} | ||
@@ -42,86 +42,95 @@ | ||
Inputmask.extendAliases({ | ||
"cssunit": { | ||
regex: "[+-]?[0-9]+\\.?([0-9]+)?(px|em|rem|ex|%|in|cm|mm|pt|pc)" | ||
}, | ||
"url": { //needs update => https://en.wikipedia.org/wiki/URL | ||
regex: "(https?|ftp)://.*", | ||
autoUnmask: false, | ||
keepStatic: false, | ||
tabThrough: true | ||
}, | ||
"ip": { //ip-address mask | ||
mask: "i[i[i]].j[j[j]].k[k[k]].l[l[l]]", | ||
definitions: { | ||
"i": { | ||
validator: ipValidator | ||
}, | ||
"j": { | ||
validator: ipValidator | ||
}, | ||
"k": { | ||
validator: ipValidator | ||
}, | ||
"l": { | ||
validator: ipValidator | ||
} | ||
}, | ||
onUnMask: function (maskedValue, unmaskedValue, opts) { | ||
return maskedValue; | ||
}, | ||
inputmode: "numeric", | ||
}, | ||
"email": { | ||
//https://en.wikipedia.org/wiki/Domain_name#Domain_name_space | ||
//https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names | ||
//should be extended with the toplevel domains at the end | ||
mask: function (opts) { | ||
var emailMask = "*{1,64}[.*{1,64}][.*{1,64}][.*{1,63}]@-{1,63}.-{1,63}[.-{1,63}][.-{1,63}]"; | ||
return opts.separator !== undefined ? `${emailMask}(${opts.separator}${emailMask}){*}` : emailMask; | ||
}, | ||
greedy: false, | ||
casing: "lower", | ||
separator: undefined, | ||
skipOptionalPartCharacter: "", | ||
onBeforePaste: function (pastedValue, opts) { | ||
pastedValue = pastedValue.toLowerCase(); | ||
return pastedValue.replace("mailto:", ""); | ||
}, | ||
definitions: { | ||
"*": { | ||
validator: "[0-9\uFF11-\uFF19A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5!#$%&'*+/=?^_`{|}~-]" | ||
}, | ||
"-": { | ||
validator: "[0-9A-Za-z-]" | ||
} | ||
}, | ||
onUnMask: function (maskedValue, unmaskedValue, opts) { | ||
return maskedValue; | ||
}, | ||
inputmode: "email" | ||
}, | ||
"mac": { | ||
mask: "##:##:##:##:##:##" | ||
}, | ||
//https://en.wikipedia.org/wiki/Vehicle_identification_number | ||
// see issue #1199 | ||
"vin": { | ||
mask: "V{13}9{4}", | ||
definitions: { | ||
"V": { | ||
validator: "[A-HJ-NPR-Za-hj-npr-z\\d]", | ||
casing: "upper" | ||
} | ||
}, | ||
clearIncomplete: true, | ||
autoUnmask: true | ||
}, | ||
//http://rion.io/2013/09/10/validating-social-security-numbers-through-regular-expressions-2/ | ||
//https://en.wikipedia.org/wiki/Social_Security_number | ||
"ssn": { | ||
mask: "999-99-9999", | ||
postValidation: function (buffer, pos, c, currentResult, opts, maskset, strict) { | ||
var bffr = getMaskTemplate.call(this, true, getLastValidPosition.call(this), true, true); | ||
return /^(?!219-09-9999|078-05-1120)(?!666|000|9.{2}).{3}-(?!00).{2}-(?!0{4}).{4}$/.test(bffr.join("")); | ||
} | ||
}, | ||
}); | ||
"cssunit": { | ||
regex: "[+-]?[0-9]+\\.?([0-9]+)?(px|em|rem|ex|%|in|cm|mm|pt|pc)" | ||
}, | ||
"url": { //needs update => https://en.wikipedia.org/wiki/URL | ||
regex: "(https?|ftp)://.*", | ||
autoUnmask: false, | ||
keepStatic: false, | ||
tabThrough: true | ||
}, | ||
"ip": { //ip-address mask | ||
mask: "i{1,3}.j{1,3}.k{1,3}.l{1,3}", | ||
definitions: { | ||
"i": { | ||
validator: ipValidator | ||
}, | ||
"j": { | ||
validator: ipValidator | ||
}, | ||
"k": { | ||
validator: ipValidator | ||
}, | ||
"l": { | ||
validator: ipValidator | ||
} | ||
}, | ||
onUnMask: function (maskedValue, unmaskedValue, opts) { | ||
return maskedValue; | ||
}, | ||
inputmode: "decimal", | ||
substitutes: {",": "."} | ||
}, | ||
"email": { | ||
//https://en.wikipedia.org/wiki/Domain_name#Domain_name_space | ||
//https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names | ||
//should be extended with the toplevel domains at the end | ||
mask: function (opts) { | ||
var emailMask = "*{1,64}[.*{1,64}][.*{1,64}][.*{1,63}]@-{1,63}.-{1,63}[.-{1,63}][.-{1,63}]"; | ||
var mask = emailMask; | ||
if (opts.separator) { | ||
for (let i = 0; i < opts.quantifier; i++) { | ||
mask += `[${opts.separator}${emailMask}]`; | ||
} | ||
} | ||
return mask; | ||
return opts.separator ? `${emailMask}(${opts.separator}${emailMask}){*}` : emailMask; | ||
}, | ||
greedy: false, | ||
casing: "lower", | ||
separator: null, | ||
quantifier: 5, | ||
skipOptionalPartCharacter: "", | ||
onBeforePaste: function (pastedValue, opts) { | ||
pastedValue = pastedValue.toLowerCase(); | ||
return pastedValue.replace("mailto:", ""); | ||
}, | ||
definitions: { | ||
"*": { | ||
validator: "[0-9\uFF11-\uFF19A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5!#$%&'*+/=?^_`{|}~-]" | ||
}, | ||
"-": { | ||
validator: "[0-9A-Za-z-]" | ||
} | ||
}, | ||
onUnMask: function (maskedValue, unmaskedValue, opts) { | ||
return maskedValue; | ||
}, | ||
inputmode: "email" | ||
}, | ||
"mac": { | ||
mask: "##:##:##:##:##:##" | ||
}, | ||
//https://en.wikipedia.org/wiki/Vehicle_identification_number | ||
// see issue #1199 | ||
"vin": { | ||
mask: "V{13}9{4}", | ||
definitions: { | ||
"V": { | ||
validator: "[A-HJ-NPR-Za-hj-npr-z\\d]", | ||
casing: "upper" | ||
} | ||
}, | ||
clearIncomplete: true, | ||
autoUnmask: true | ||
}, | ||
//http://rion.io/2013/09/10/validating-social-security-numbers-through-regular-expressions-2/ | ||
//https://en.wikipedia.org/wiki/Social_Security_number | ||
"ssn": { | ||
mask: "999-99-9999", | ||
postValidation: function (buffer, pos, c, currentResult, opts, maskset, strict) { | ||
var bffr = getMaskTemplate.call(this, true, getLastValidPosition.call(this), true, true); | ||
return /^(?!219-09-9999|078-05-1120)(?!666|000|9.{2}).{3}-(?!00).{2}-(?!0{4}).{4}$/.test(bffr.join("")); | ||
} | ||
}, | ||
}); |
@@ -15,224 +15,224 @@ /* | ||
function autoEscape(txt, opts) { | ||
var escapedTxt = ""; | ||
for (var i = 0; i < txt.length; i++) { | ||
if (Inputmask.prototype.definitions[txt.charAt(i)] || | ||
opts.definitions[txt.charAt(i)] || | ||
opts.optionalmarker[0] === txt.charAt(i) || | ||
opts.optionalmarker[1] === txt.charAt(i) || | ||
opts.quantifiermarker[0] === txt.charAt(i) || | ||
opts.quantifiermarker[1] === txt.charAt(i) || | ||
opts.groupmarker[0] === txt.charAt(i) || | ||
opts.groupmarker[1] === txt.charAt(i) || | ||
opts.alternatormarker === txt.charAt(i)) { | ||
escapedTxt += "\\" + txt.charAt(i); | ||
} else { | ||
escapedTxt += txt.charAt(i); | ||
} | ||
} | ||
return escapedTxt; | ||
var escapedTxt = ""; | ||
for (var i = 0; i < txt.length; i++) { | ||
if (Inputmask.prototype.definitions[txt.charAt(i)] || | ||
opts.definitions[txt.charAt(i)] || | ||
opts.optionalmarker[0] === txt.charAt(i) || | ||
opts.optionalmarker[1] === txt.charAt(i) || | ||
opts.quantifiermarker[0] === txt.charAt(i) || | ||
opts.quantifiermarker[1] === txt.charAt(i) || | ||
opts.groupmarker[0] === txt.charAt(i) || | ||
opts.groupmarker[1] === txt.charAt(i) || | ||
opts.alternatormarker === txt.charAt(i)) { | ||
escapedTxt += "\\" + txt.charAt(i); | ||
} else { | ||
escapedTxt += txt.charAt(i); | ||
} | ||
} | ||
return escapedTxt; | ||
} | ||
function alignDigits(buffer, digits, opts, force) { | ||
if (buffer.length > 0 && digits > 0 && (!opts.digitsOptional || force)) { | ||
var radixPosition = buffer.indexOf(opts.radixPoint), negationBack = false; | ||
if (opts.negationSymbol.back === buffer[buffer.length - 1]) { | ||
negationBack = true; | ||
buffer.length--; | ||
} | ||
if (buffer.length > 0 && digits > 0 && (!opts.digitsOptional || force)) { | ||
var radixPosition = buffer.indexOf(opts.radixPoint), negationBack = false; | ||
if (opts.negationSymbol.back === buffer[buffer.length - 1]) { | ||
negationBack = true; | ||
buffer.length--; | ||
} | ||
if (radixPosition === -1) { | ||
buffer.push(opts.radixPoint); | ||
radixPosition = buffer.length - 1; | ||
} | ||
for (var i = 1; i <= digits; i++) { | ||
if (!isFinite(buffer[radixPosition + i])) { | ||
buffer[radixPosition + i] = "0"; | ||
} | ||
} | ||
} | ||
if (radixPosition === -1) { | ||
buffer.push(opts.radixPoint); | ||
radixPosition = buffer.length - 1; | ||
} | ||
for (var i = 1; i <= digits; i++) { | ||
if (!isFinite(buffer[radixPosition + i])) { | ||
buffer[radixPosition + i] = "0"; | ||
} | ||
} | ||
} | ||
if (negationBack) | ||
buffer.push(opts.negationSymbol.back); | ||
return buffer; | ||
if (negationBack) | ||
buffer.push(opts.negationSymbol.back); | ||
return buffer; | ||
} | ||
function findValidator(symbol, maskset) { | ||
var posNdx = 0; | ||
if (symbol === "+") { | ||
for (posNdx in maskset.validPositions) ; | ||
posNdx = seekNext.call(this, parseInt(posNdx)); | ||
} | ||
for (var tstNdx in maskset.tests) { | ||
tstNdx = parseInt(tstNdx); | ||
if (tstNdx >= posNdx) { | ||
for (var ndx = 0, ndxl = maskset.tests[tstNdx].length; ndx < ndxl; ndx++) { | ||
if ((maskset.validPositions[tstNdx] === undefined || symbol === "-") && maskset.tests[tstNdx][ndx].match.def === symbol) { | ||
return tstNdx + ((maskset.validPositions[tstNdx] !== undefined && symbol !== "-") ? 1 : 0); | ||
} | ||
} | ||
} | ||
} | ||
return posNdx; | ||
var posNdx = 0; | ||
if (symbol === "+") { | ||
for (posNdx in maskset.validPositions) ; | ||
posNdx = seekNext.call(this, parseInt(posNdx)); | ||
} | ||
for (var tstNdx in maskset.tests) { | ||
tstNdx = parseInt(tstNdx); | ||
if (tstNdx >= posNdx) { | ||
for (var ndx = 0, ndxl = maskset.tests[tstNdx].length; ndx < ndxl; ndx++) { | ||
if ((maskset.validPositions[tstNdx] === undefined || symbol === "-") && maskset.tests[tstNdx][ndx].match.def === symbol) { | ||
return tstNdx + ((maskset.validPositions[tstNdx] !== undefined && symbol !== "-") ? 1 : 0); | ||
} | ||
} | ||
} | ||
} | ||
return posNdx; | ||
} | ||
function findValid(symbol, maskset) { | ||
var ret = -1; | ||
for (let ndx in maskset.validPositions) { | ||
let tst = maskset.validPositions[ndx]; | ||
if (tst && tst.match.def === symbol) { | ||
ret = parseInt(ndx); | ||
break; | ||
} | ||
} | ||
return ret; | ||
var ret = -1; | ||
for (let ndx in maskset.validPositions) { | ||
let tst = maskset.validPositions[ndx]; | ||
if (tst && tst.match.def === symbol) { | ||
ret = parseInt(ndx); | ||
break; | ||
} | ||
} | ||
return ret; | ||
} | ||
function parseMinMaxOptions(opts) { | ||
if (opts.parseMinMaxOptions === undefined) { | ||
// convert min and max options | ||
if (opts.min !== null) { | ||
opts.min = opts.min.toString().replace(new RegExp(escapeRegex(opts.groupSeparator), "g"), ""); | ||
if (opts.radixPoint === ",") opts.min = opts.min.replace(opts.radixPoint, "."); | ||
opts.min = isFinite(opts.min) ? parseFloat(opts.min) : NaN; | ||
if (isNaN(opts.min)) opts.min = Number.MIN_VALUE; | ||
} | ||
if (opts.max !== null) { | ||
opts.max = opts.max.toString().replace(new RegExp(escapeRegex(opts.groupSeparator), "g"), ""); | ||
if (opts.radixPoint === ",") opts.max = opts.max.replace(opts.radixPoint, "."); | ||
opts.max = isFinite(opts.max) ? parseFloat(opts.max) : NaN; | ||
if (isNaN(opts.max)) opts.max = Number.MAX_VALUE; | ||
} | ||
opts.parseMinMaxOptions = "done"; | ||
} | ||
if (opts.parseMinMaxOptions === undefined) { | ||
// convert min and max options | ||
if (opts.min !== null) { | ||
opts.min = opts.min.toString().replace(new RegExp(escapeRegex(opts.groupSeparator), "g"), ""); | ||
if (opts.radixPoint === ",") opts.min = opts.min.replace(opts.radixPoint, "."); | ||
opts.min = isFinite(opts.min) ? parseFloat(opts.min) : NaN; | ||
if (isNaN(opts.min)) opts.min = Number.MIN_VALUE; | ||
} | ||
if (opts.max !== null) { | ||
opts.max = opts.max.toString().replace(new RegExp(escapeRegex(opts.groupSeparator), "g"), ""); | ||
if (opts.radixPoint === ",") opts.max = opts.max.replace(opts.radixPoint, "."); | ||
opts.max = isFinite(opts.max) ? parseFloat(opts.max) : NaN; | ||
if (isNaN(opts.max)) opts.max = Number.MAX_VALUE; | ||
} | ||
opts.parseMinMaxOptions = "done"; | ||
} | ||
} | ||
function genMask(opts) { | ||
opts.repeat = 0; | ||
//treat equal separator and radixpoint | ||
if (opts.groupSeparator === opts.radixPoint && opts.digits && opts.digits !== "0") { | ||
if (opts.radixPoint === ".") { | ||
opts.groupSeparator = ","; | ||
} else if (opts.radixPoint === ",") { | ||
opts.groupSeparator = "."; | ||
} else { | ||
opts.groupSeparator = ""; | ||
} | ||
} | ||
//prevent conflict with default skipOptionalPartCharacter | ||
if (opts.groupSeparator === " ") { | ||
opts.skipOptionalPartCharacter = undefined; | ||
} | ||
opts.repeat = 0; | ||
//treat equal separator and radixpoint | ||
if (opts.groupSeparator === opts.radixPoint && opts.digits && opts.digits !== "0") { | ||
if (opts.radixPoint === ".") { | ||
opts.groupSeparator = ","; | ||
} else if (opts.radixPoint === ",") { | ||
opts.groupSeparator = "."; | ||
} else { | ||
opts.groupSeparator = ""; | ||
} | ||
} | ||
//prevent conflict with default skipOptionalPartCharacter | ||
if (opts.groupSeparator === " ") { | ||
opts.skipOptionalPartCharacter = undefined; | ||
} | ||
//enforce placeholder to single | ||
if (opts.placeholder.length > 1) { | ||
opts.placeholder = opts.placeholder.charAt(0); | ||
} | ||
//only allow radixfocus when placeholder = 0 | ||
if (opts.positionCaretOnClick === "radixFocus" && opts.placeholder === "") { | ||
opts.positionCaretOnClick = "lvp"; | ||
} | ||
//enforce placeholder to single | ||
if (opts.placeholder.length > 1) { | ||
opts.placeholder = opts.placeholder.charAt(0); | ||
} | ||
//only allow radixfocus when placeholder = 0 | ||
if (opts.positionCaretOnClick === "radixFocus" && opts.placeholder === "") { | ||
opts.positionCaretOnClick = "lvp"; | ||
} | ||
var decimalDef = "0", radixPointDef = opts.radixPoint; | ||
if (opts.numericInput === true && opts.__financeInput === undefined) { //finance people input style | ||
decimalDef = "1"; | ||
opts.positionCaretOnClick = opts.positionCaretOnClick === "radixFocus" ? "lvp" : opts.positionCaretOnClick; | ||
opts.digitsOptional = false; | ||
if (isNaN(opts.digits)) opts.digits = 2; | ||
opts._radixDance = false; | ||
radixPointDef = (opts.radixPoint === "," ? "?" : "!"); | ||
if (opts.radixPoint !== "" && opts.definitions[radixPointDef] === undefined) { | ||
//update separator definition | ||
opts.definitions[radixPointDef] = {}; | ||
opts.definitions[radixPointDef].validator = "[" + opts.radixPoint + "]"; | ||
opts.definitions[radixPointDef].placeholder = opts.radixPoint; | ||
opts.definitions[radixPointDef].static = true; | ||
opts.definitions[radixPointDef].generated = true; //forced marker as generated input | ||
} | ||
} else { | ||
opts.__financeInput = false; //needed to keep original selection when remasking | ||
opts.numericInput = true; | ||
} | ||
var decimalDef = "0", radixPointDef = opts.radixPoint; | ||
if (opts.numericInput === true && opts.__financeInput === undefined) { //finance people input style | ||
decimalDef = "1"; | ||
opts.positionCaretOnClick = opts.positionCaretOnClick === "radixFocus" ? "lvp" : opts.positionCaretOnClick; | ||
opts.digitsOptional = false; | ||
if (isNaN(opts.digits)) opts.digits = 2; | ||
opts._radixDance = false; | ||
radixPointDef = (opts.radixPoint === "," ? "?" : "!"); | ||
if (opts.radixPoint !== "" && opts.definitions[radixPointDef] === undefined) { | ||
//update separator definition | ||
opts.definitions[radixPointDef] = {}; | ||
opts.definitions[radixPointDef].validator = "[" + opts.radixPoint + "]"; | ||
opts.definitions[radixPointDef].placeholder = opts.radixPoint; | ||
opts.definitions[radixPointDef].static = true; | ||
opts.definitions[radixPointDef].generated = true; //forced marker as generated input | ||
} | ||
} else { | ||
opts.__financeInput = false; //needed to keep original selection when remasking | ||
opts.numericInput = true; | ||
} | ||
var mask = "[+]", altMask; | ||
mask += autoEscape(opts.prefix, opts); | ||
if (opts.groupSeparator !== "") { | ||
if (opts.definitions[opts.groupSeparator] === undefined) { | ||
//update separatot definition | ||
opts.definitions[opts.groupSeparator] = {}; | ||
opts.definitions[opts.groupSeparator].validator = "[" + opts.groupSeparator + "]"; | ||
opts.definitions[opts.groupSeparator].placeholder = opts.groupSeparator; | ||
opts.definitions[opts.groupSeparator].static = true; | ||
opts.definitions[opts.groupSeparator].generated = true; //forced marker as generated input | ||
} | ||
mask += opts._mask(opts); | ||
} else { | ||
mask += "9{+}"; | ||
} | ||
if (opts.digits !== undefined && opts.digits !== 0) { | ||
var dq = opts.digits.toString().split(","); | ||
if (isFinite(dq[0]) && dq[1] && isFinite(dq[1])) { | ||
mask += radixPointDef + decimalDef + "{" + opts.digits + "}"; | ||
} else if (isNaN(opts.digits) || parseInt(opts.digits) > 0) { | ||
if (opts.digitsOptional || opts.jitMasking) { | ||
altMask = mask + radixPointDef + decimalDef + "{0," + opts.digits + "}"; | ||
// mask += "[" + opts.radixPoint + "]"; | ||
opts.keepStatic = true; | ||
} else { | ||
mask += radixPointDef + decimalDef + "{" + opts.digits + "}"; | ||
} | ||
} | ||
} else { | ||
opts.inputmode = "numeric"; | ||
} | ||
mask += autoEscape(opts.suffix, opts); | ||
mask += "[-]"; | ||
var mask = "[+]", altMask; | ||
mask += autoEscape(opts.prefix, opts); | ||
if (opts.groupSeparator !== "") { | ||
if (opts.definitions[opts.groupSeparator] === undefined) { | ||
//update separatot definition | ||
opts.definitions[opts.groupSeparator] = {}; | ||
opts.definitions[opts.groupSeparator].validator = "[" + opts.groupSeparator + "]"; | ||
opts.definitions[opts.groupSeparator].placeholder = opts.groupSeparator; | ||
opts.definitions[opts.groupSeparator].static = true; | ||
opts.definitions[opts.groupSeparator].generated = true; //forced marker as generated input | ||
} | ||
mask += opts._mask(opts); | ||
} else { | ||
mask += "9{+}"; | ||
} | ||
if (opts.digits !== undefined && opts.digits !== 0) { | ||
var dq = opts.digits.toString().split(","); | ||
if (isFinite(dq[0]) && dq[1] && isFinite(dq[1])) { | ||
mask += radixPointDef + decimalDef + "{" + opts.digits + "}"; | ||
} else if (isNaN(opts.digits) || parseInt(opts.digits) > 0) { | ||
if (opts.digitsOptional || opts.jitMasking) { | ||
altMask = mask + radixPointDef + decimalDef + "{0," + opts.digits + "}"; | ||
// mask += "[" + opts.radixPoint + "]"; | ||
opts.keepStatic = true; | ||
} else { | ||
mask += radixPointDef + decimalDef + "{" + opts.digits + "}"; | ||
} | ||
} | ||
} else { | ||
opts.inputmode = "numeric"; | ||
} | ||
mask += autoEscape(opts.suffix, opts); | ||
mask += "[-]"; | ||
if (altMask) { | ||
mask = [(altMask + autoEscape(opts.suffix, opts) + "[-]"), mask]; | ||
} | ||
if (altMask) { | ||
mask = [(altMask + autoEscape(opts.suffix, opts) + "[-]"), mask]; | ||
} | ||
opts.greedy = false; //enforce greedy false | ||
opts.greedy = false; //enforce greedy false | ||
parseMinMaxOptions(opts); | ||
if (opts.radixPoint !== "") | ||
opts.substitutes[opts.radixPoint == "." ? "," : "."] = opts.radixPoint; | ||
// console.log(mask); | ||
return mask; | ||
parseMinMaxOptions(opts); | ||
if (opts.radixPoint !== "") | ||
opts.substitutes[opts.radixPoint == "." ? "," : "."] = opts.radixPoint; | ||
// console.log(mask); | ||
return mask; | ||
} | ||
function hanndleRadixDance(pos, c, radixPos, maskset, opts) { | ||
if (opts._radixDance && opts.numericInput && c !== opts.negationSymbol.back) { | ||
if (pos <= radixPos && (radixPos > 0 || c == opts.radixPoint) && (maskset.validPositions[pos - 1] === undefined || maskset.validPositions[pos - 1].input !== opts.negationSymbol.back)) { | ||
pos -= 1; | ||
} | ||
} | ||
return pos; | ||
if (opts._radixDance && opts.numericInput && c !== opts.negationSymbol.back) { | ||
if (pos <= radixPos && (radixPos > 0 || c == opts.radixPoint) && (maskset.validPositions[pos - 1] === undefined || maskset.validPositions[pos - 1].input !== opts.negationSymbol.back)) { | ||
pos -= 1; | ||
} | ||
} | ||
return pos; | ||
} | ||
function decimalValidator(chrs, maskset, pos, strict, opts) { | ||
var radixPos = maskset.buffer ? maskset.buffer.indexOf(opts.radixPoint) : -1, | ||
result = (radixPos !== -1 || (strict && opts.jitMasking)) && new RegExp(opts.definitions["9"].validator).test(chrs); | ||
if (opts._radixDance && radixPos !== -1 && result && maskset.validPositions[radixPos] == undefined) { | ||
return { | ||
insert: { | ||
pos: radixPos === pos ? radixPos + 1 : radixPos, | ||
c: opts.radixPoint | ||
}, | ||
pos: pos | ||
}; | ||
} | ||
var radixPos = maskset.buffer ? maskset.buffer.indexOf(opts.radixPoint) : -1, | ||
result = (radixPos !== -1 || (strict && opts.jitMasking)) && new RegExp(opts.definitions["9"].validator).test(chrs); | ||
if (opts._radixDance && radixPos !== -1 && result && maskset.validPositions[radixPos] == undefined) { | ||
return { | ||
insert: { | ||
pos: radixPos === pos ? radixPos + 1 : radixPos, | ||
c: opts.radixPoint | ||
}, | ||
pos: pos | ||
}; | ||
} | ||
return result; | ||
return result; | ||
} | ||
function checkForLeadingZeroes(buffer, opts) { | ||
//check leading zeros | ||
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("")), | ||
number = numberMatches ? numberMatches[2] : "", leadingzeroes = false; | ||
if (number) { | ||
number = number.split(opts.radixPoint.charAt(0))[0]; | ||
leadingzeroes = new RegExp("^[0" + opts.groupSeparator + "]*").exec(number); | ||
} | ||
return leadingzeroes && (leadingzeroes[0].length > 1 || leadingzeroes[0].length > 0 && leadingzeroes[0].length < number.length) ? leadingzeroes : false; | ||
//check leading zeros | ||
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("")), | ||
number = numberMatches ? numberMatches[2] : "", leadingzeroes = false; | ||
if (number) { | ||
number = number.split(opts.radixPoint.charAt(0))[0]; | ||
leadingzeroes = new RegExp("^[0" + opts.groupSeparator + "]*").exec(number); | ||
} | ||
return leadingzeroes && (leadingzeroes[0].length > 1 || leadingzeroes[0].length > 0 && leadingzeroes[0].length < number.length) ? leadingzeroes : false; | ||
} | ||
@@ -242,398 +242,392 @@ | ||
Inputmask.extendAliases({ | ||
"numeric": { | ||
mask: genMask, | ||
_mask: function (opts) { | ||
return "(" + opts.groupSeparator + "999){+|1}"; | ||
}, | ||
digits: "*", //number of fractionalDigits | ||
digitsOptional: true, | ||
enforceDigitsOnBlur: false, | ||
radixPoint: ".", | ||
positionCaretOnClick: "radixFocus", | ||
_radixDance: true, | ||
groupSeparator: "", | ||
allowMinus: true, | ||
negationSymbol: { | ||
front: "-", //"(" | ||
back: "" //")" | ||
}, | ||
prefix: "", | ||
suffix: "", | ||
min: null, //minimum value | ||
max: null, //maximum value | ||
SetMaxOnOverflow: false, | ||
step: 1, | ||
inputType: "text", //number ~ specify that values which are set are in textform (radix point is same as in the options) or in numberform (radixpoint = .) | ||
unmaskAsNumber: false, | ||
roundingFN: Math.round, //Math.floor , fn(x) | ||
inputmode: "decimal", | ||
shortcuts: {k: "000", m: "000000"}, | ||
//global options | ||
placeholder: "0", | ||
greedy: false, | ||
rightAlign: true, | ||
insertMode: true, | ||
autoUnmask: false, | ||
skipOptionalPartCharacter: "", | ||
usePrototypeDefinitions: false, | ||
definitions: { | ||
"0": { | ||
validator: decimalValidator | ||
}, | ||
"1": { | ||
validator: decimalValidator, | ||
definitionSymbol: "9" | ||
}, | ||
"9": { //\uFF11-\uFF19 #1606 | ||
validator: "[0-9\uFF10-\uFF19\u0660-\u0669\u06F0-\u06F9]", | ||
definitionSymbol: "*" | ||
}, | ||
"+": { | ||
validator: function (chrs, maskset, pos, strict, opts) { | ||
return (opts.allowMinus && (chrs === "-" || chrs === opts.negationSymbol.front)); | ||
"numeric": { | ||
mask: genMask, | ||
_mask: function (opts) { | ||
return "(" + opts.groupSeparator + "999){+|1}"; | ||
}, | ||
digits: "*", //number of fractionalDigits | ||
digitsOptional: true, | ||
enforceDigitsOnBlur: false, | ||
radixPoint: ".", | ||
positionCaretOnClick: "radixFocus", | ||
_radixDance: true, | ||
groupSeparator: "", | ||
allowMinus: true, | ||
negationSymbol: { | ||
front: "-", //"(" | ||
back: "" //")" | ||
}, | ||
prefix: "", | ||
suffix: "", | ||
min: null, //minimum value | ||
max: null, //maximum value | ||
SetMaxOnOverflow: false, | ||
step: 1, | ||
inputType: "text", //number ~ specify that values which are set are in textform (radix point is same as in the options) or in numberform (radixpoint = .) | ||
unmaskAsNumber: false, | ||
roundingFN: Math.round, //Math.floor , fn(x) | ||
inputmode: "decimal", | ||
shortcuts: {k: "1000", m: "1000000"}, | ||
//global options | ||
placeholder: "0", | ||
greedy: false, | ||
rightAlign: true, | ||
insertMode: true, | ||
autoUnmask: false, | ||
skipOptionalPartCharacter: "", | ||
usePrototypeDefinitions: false, | ||
stripLeadingZeroes: true, | ||
definitions: { | ||
"0": { | ||
validator: decimalValidator | ||
}, | ||
"1": { | ||
validator: decimalValidator, | ||
definitionSymbol: "9" | ||
}, | ||
"9": { //\uFF11-\uFF19 #1606 | ||
validator: "[0-9\uFF10-\uFF19\u0660-\u0669\u06F0-\u06F9]", | ||
definitionSymbol: "*" | ||
}, | ||
"+": { | ||
validator: function (chrs, maskset, pos, strict, opts) { | ||
return (opts.allowMinus && (chrs === "-" || chrs === opts.negationSymbol.front)); | ||
} | ||
}, | ||
"-": { | ||
validator: function (chrs, maskset, pos, strict, opts) { | ||
return (opts.allowMinus && chrs === opts.negationSymbol.back); | ||
} | ||
} | ||
}, | ||
preValidation: function (buffer, pos, c, isSelection, opts, maskset, caretPos, strict) { | ||
const inputmask = this; | ||
} | ||
}, | ||
"-": { | ||
validator: function (chrs, maskset, pos, strict, opts) { | ||
return (opts.allowMinus && chrs === opts.negationSymbol.back); | ||
} | ||
} | ||
}, | ||
preValidation: function (buffer, pos, c, isSelection, opts, maskset, caretPos, strict) { | ||
const inputmask = this; | ||
if (opts.__financeInput !== false && c === opts.radixPoint) return false; | ||
var pattern; | ||
if ((pattern = (opts.shortcuts && opts.shortcuts[c]))) { | ||
if (pattern.length > 1) { | ||
var inserts = []; | ||
for (var i = 0; i < pattern.length; i++) { | ||
inserts.push({pos: pos + i, c: pattern[i], strict: false}); | ||
} | ||
} | ||
return { | ||
insert: inserts | ||
}; | ||
} | ||
if (opts.__financeInput !== false && c === opts.radixPoint) return false; | ||
var radixPos = buffer.indexOf(opts.radixPoint), initPos = pos; | ||
pos = hanndleRadixDance(pos, c, radixPos, maskset, opts); | ||
if (c === "-" || c === opts.negationSymbol.front) { | ||
if (opts.allowMinus !== true) return false; | ||
var isNegative = false, | ||
front = findValid("+", maskset), back = findValid("-", maskset); | ||
if (front !== -1) { | ||
isNegative = [front, back]; | ||
} | ||
var radixPos = buffer.indexOf(opts.radixPoint), initPos = pos; | ||
pos = hanndleRadixDance(pos, c, radixPos, maskset, opts); | ||
if (c === "-" || c === opts.negationSymbol.front) { | ||
if (opts.allowMinus !== true) return false; | ||
var isNegative = false, | ||
front = findValid("+", maskset), back = findValid("-", maskset); | ||
if (front !== -1) { | ||
isNegative = [front, back]; | ||
} | ||
return isNegative !== false ? { | ||
remove: isNegative, | ||
caret: initPos - opts.negationSymbol.back.length | ||
} : { | ||
insert: [ | ||
{ | ||
pos: findValidator.call(inputmask, "+", maskset), | ||
c: opts.negationSymbol.front, | ||
fromIsValid: true | ||
}, | ||
{ | ||
pos: findValidator.call(inputmask, "-", maskset), | ||
c: opts.negationSymbol.back, | ||
fromIsValid: undefined | ||
}], | ||
caret: initPos + opts.negationSymbol.back.length | ||
}; | ||
} | ||
return isNegative !== false ? { | ||
remove: isNegative, | ||
caret: initPos - opts.negationSymbol.back.length | ||
} : { | ||
insert: [ | ||
{ | ||
pos: findValidator.call(inputmask, "+", maskset), | ||
c: opts.negationSymbol.front, | ||
fromIsValid: true | ||
}, | ||
{ | ||
pos: findValidator.call(inputmask, "-", maskset), | ||
c: opts.negationSymbol.back, | ||
fromIsValid: undefined | ||
}], | ||
caret: initPos + opts.negationSymbol.back.length | ||
}; | ||
} | ||
if (c === opts.groupSeparator) { | ||
return {caret: initPos}; | ||
} | ||
if (c === opts.groupSeparator) { | ||
return {caret: initPos}; | ||
} | ||
if (strict) return true; | ||
if (radixPos !== -1 && (opts._radixDance === true && isSelection === false && c === opts.radixPoint && (opts.digits !== undefined && (isNaN(opts.digits) || parseInt(opts.digits) > 0)) && radixPos !== pos)) { | ||
return { | ||
"caret": opts._radixDance && pos === radixPos - 1 ? radixPos + 1 : radixPos | ||
}; | ||
} | ||
if (opts.__financeInput === false) { | ||
if (isSelection) { | ||
if (opts.digitsOptional) { | ||
return {rewritePosition: caretPos.end}; | ||
} else if (!opts.digitsOptional) { | ||
if (caretPos.begin > radixPos && caretPos.end <= radixPos) { | ||
if (c === opts.radixPoint) { | ||
return { | ||
insert: {pos: radixPos + 1, c: "0", fromIsValid: true}, | ||
rewritePosition: radixPos | ||
}; | ||
} else { | ||
return {rewritePosition: radixPos + 1}; | ||
} | ||
} else if (caretPos.begin < radixPos) { | ||
return {rewritePosition: caretPos.begin - 1}; | ||
} | ||
} | ||
} else if (!opts.showMaskOnHover && !opts.showMaskOnFocus && !opts.digitsOptional && opts.digits > 0 && this.__valueGet.call(this.el) === "") { | ||
return {rewritePosition: radixPos}; | ||
} | ||
} | ||
return {rewritePosition: pos}; | ||
}, | ||
postValidation: function (buffer, pos, c, currentResult, opts, maskset, strict) { | ||
if (currentResult === false) return currentResult; | ||
if (strict) return true; | ||
if (opts.min !== null || opts.max !== null) { | ||
var unmasked = opts.onUnMask(buffer.slice().reverse().join(""), undefined, $.extend({}, opts, { | ||
unmaskAsNumber: true | ||
})); | ||
if (opts.min !== null && unmasked < opts.min && (unmasked.toString().length > opts.min.toString().length || unmasked < 0)) { | ||
return false; | ||
// return { | ||
// refreshFromBuffer: true, | ||
// buffer: alignDigits(opts.min.toString().replace(".", opts.radixPoint).split(""), opts.digits, opts).reverse() | ||
// }; | ||
} | ||
if (strict) return true; | ||
if (radixPos !== -1 && (opts._radixDance === true && isSelection === false && c === opts.radixPoint && (opts.digits !== undefined && (isNaN(opts.digits) || parseInt(opts.digits) > 0)) && radixPos !== pos)) { | ||
return { | ||
"caret": opts._radixDance && pos === radixPos - 1 ? radixPos + 1 : radixPos | ||
}; | ||
} | ||
if (opts.__financeInput === false) { | ||
if (isSelection) { | ||
if (opts.digitsOptional) { | ||
return {rewritePosition: caretPos.end}; | ||
} else if (!opts.digitsOptional) { | ||
if (caretPos.begin > radixPos && caretPos.end <= radixPos) { | ||
if (c === opts.radixPoint) { | ||
return { | ||
insert: {pos: radixPos + 1, c: "0", fromIsValid: true}, | ||
rewritePosition: radixPos | ||
}; | ||
} else { | ||
return {rewritePosition: radixPos + 1}; | ||
} | ||
} else if (caretPos.begin < radixPos) { | ||
return {rewritePosition: caretPos.begin - 1}; | ||
} | ||
} | ||
} else if (!opts.showMaskOnHover && !opts.showMaskOnFocus && !opts.digitsOptional && opts.digits > 0 && this.__valueGet.call(this.el) === "") { | ||
return {rewritePosition: radixPos}; | ||
} | ||
} | ||
return {rewritePosition: pos}; | ||
}, | ||
postValidation: function (buffer, pos, c, currentResult, opts, maskset, strict) { | ||
if (currentResult === false) return currentResult; | ||
if (strict) return true; | ||
if (opts.min !== null || opts.max !== null) { | ||
var unmasked = opts.onUnMask(buffer.slice().reverse().join(""), undefined, $.extend({}, opts, { | ||
unmaskAsNumber: true | ||
})); | ||
if (opts.min !== null && unmasked < opts.min && (unmasked.toString().length > opts.min.toString().length || unmasked < 0)) { | ||
return false; | ||
// return { | ||
// refreshFromBuffer: true, | ||
// buffer: alignDigits(opts.min.toString().replace(".", opts.radixPoint).split(""), opts.digits, opts).reverse() | ||
// }; | ||
} | ||
if (opts.max !== null && unmasked > opts.max) { | ||
return opts.SetMaxOnOverflow ? { | ||
refreshFromBuffer: true, | ||
buffer: alignDigits(opts.max.toString().replace(".", opts.radixPoint).split(""), opts.digits, opts).reverse() | ||
} : false; | ||
} | ||
} | ||
if (opts.max !== null && unmasked > opts.max) { | ||
return opts.SetMaxOnOverflow ? { | ||
refreshFromBuffer: true, | ||
buffer: alignDigits(opts.max.toString().replace(".", opts.radixPoint).split(""), opts.digits, opts).reverse() | ||
} : false; | ||
} | ||
} | ||
return currentResult; | ||
}, | ||
onUnMask: function (maskedValue, unmaskedValue, opts) { | ||
if (unmaskedValue === "" && opts.nullable === true) { | ||
return unmaskedValue; | ||
} | ||
var processValue = maskedValue.replace(opts.prefix, ""); | ||
processValue = processValue.replace(opts.suffix, ""); | ||
processValue = processValue.replace(new RegExp(escapeRegex(opts.groupSeparator), "g"), ""); | ||
if (opts.placeholder.charAt(0) !== "") { | ||
processValue = processValue.replace(new RegExp(opts.placeholder.charAt(0), "g"), "0"); | ||
} | ||
if (opts.unmaskAsNumber) { | ||
if (opts.radixPoint !== "" && processValue.indexOf(opts.radixPoint) !== -1) processValue = processValue.replace(escapeRegex.call(this, opts.radixPoint), "."); | ||
processValue = processValue.replace(new RegExp("^" + escapeRegex(opts.negationSymbol.front)), "-"); | ||
processValue = processValue.replace(new RegExp(escapeRegex(opts.negationSymbol.back) + "$"), ""); | ||
return Number(processValue); | ||
} | ||
return processValue; | ||
} | ||
, | ||
isComplete: function (buffer, opts) { | ||
var maskedValue = (opts.numericInput ? buffer.slice().reverse() : buffer).join(""); | ||
maskedValue = maskedValue.replace(new RegExp("^" + escapeRegex(opts.negationSymbol.front)), "-"); | ||
maskedValue = maskedValue.replace(new RegExp(escapeRegex(opts.negationSymbol.back) + "$"), ""); | ||
maskedValue = maskedValue.replace(opts.prefix, ""); | ||
maskedValue = maskedValue.replace(opts.suffix, ""); | ||
maskedValue = maskedValue.replace(new RegExp(escapeRegex(opts.groupSeparator) + "([0-9]{3})", "g"), "$1"); | ||
if (opts.radixPoint === ",") maskedValue = maskedValue.replace(escapeRegex(opts.radixPoint), "."); | ||
return isFinite(maskedValue); | ||
}, | ||
onBeforeMask: function (initialValue, opts) { | ||
var radixPoint = opts.radixPoint || ","; | ||
if (isFinite(opts.digits)) opts.digits = parseInt(opts.digits); | ||
return currentResult; | ||
}, | ||
onUnMask: function (maskedValue, unmaskedValue, opts) { | ||
if (unmaskedValue === "" && opts.nullable === true) { | ||
return unmaskedValue; | ||
} | ||
var processValue = maskedValue.replace(opts.prefix, ""); | ||
processValue = processValue.replace(opts.suffix, ""); | ||
processValue = processValue.replace(new RegExp(escapeRegex(opts.groupSeparator), "g"), ""); | ||
if (opts.placeholder.charAt(0) !== "") { | ||
processValue = processValue.replace(new RegExp(opts.placeholder.charAt(0), "g"), "0"); | ||
} | ||
if (opts.unmaskAsNumber) { | ||
if (opts.radixPoint !== "" && processValue.indexOf(opts.radixPoint) !== -1) processValue = processValue.replace(escapeRegex.call(this, opts.radixPoint), "."); | ||
processValue = processValue.replace(new RegExp("^" + escapeRegex(opts.negationSymbol.front)), "-"); | ||
processValue = processValue.replace(new RegExp(escapeRegex(opts.negationSymbol.back) + "$"), ""); | ||
return Number(processValue); | ||
} | ||
return processValue; | ||
} | ||
, | ||
isComplete: function (buffer, opts) { | ||
var maskedValue = (opts.numericInput ? buffer.slice().reverse() : buffer).join(""); | ||
maskedValue = maskedValue.replace(new RegExp("^" + escapeRegex(opts.negationSymbol.front)), "-"); | ||
maskedValue = maskedValue.replace(new RegExp(escapeRegex(opts.negationSymbol.back) + "$"), ""); | ||
maskedValue = maskedValue.replace(opts.prefix, ""); | ||
maskedValue = maskedValue.replace(opts.suffix, ""); | ||
maskedValue = maskedValue.replace(new RegExp(escapeRegex(opts.groupSeparator) + "([0-9]{3})", "g"), "$1"); | ||
if (opts.radixPoint === ",") maskedValue = maskedValue.replace(escapeRegex(opts.radixPoint), "."); | ||
return isFinite(maskedValue); | ||
}, | ||
onBeforeMask: function (initialValue, opts) { | ||
var radixPoint = opts.radixPoint || ","; | ||
if (isFinite(opts.digits)) opts.digits = parseInt(opts.digits); | ||
if ((typeof initialValue == "number" || opts.inputType === "number") && radixPoint !== "") { | ||
initialValue = initialValue.toString().replace(".", radixPoint); | ||
} | ||
var isNagtive = initialValue.charAt(0) === "-" || initialValue.charAt(0) === opts.negationSymbol.front; | ||
var valueParts = initialValue.split(radixPoint), | ||
integerPart = valueParts[0].replace(/[^\-0-9]/g, ""), | ||
decimalPart = valueParts.length > 1 ? valueParts[1].replace(/[^0-9]/g, "") : "", | ||
forceDigits = valueParts.length > 1; | ||
if ((typeof initialValue == "number" || opts.inputType === "number") && radixPoint !== "") { | ||
initialValue = initialValue.toString().replace(".", radixPoint); | ||
} | ||
var isNagtive = initialValue.charAt(0) === "-" || initialValue.charAt(0) === opts.negationSymbol.front; | ||
var valueParts = initialValue.split(radixPoint), | ||
integerPart = valueParts[0].replace(/[^\-0-9]/g, ""), | ||
decimalPart = valueParts.length > 1 ? valueParts[1].replace(/[^0-9]/g, "") : "", | ||
forceDigits = valueParts.length > 1; | ||
initialValue = integerPart + (decimalPart !== "" ? radixPoint + decimalPart : decimalPart); | ||
initialValue = integerPart + (decimalPart !== "" ? radixPoint + decimalPart : decimalPart); | ||
var digits = 0; | ||
if (radixPoint !== "") { | ||
digits = !opts.digitsOptional ? opts.digits : (opts.digits < decimalPart.length ? opts.digits : decimalPart.length); | ||
if (decimalPart !== "" || !opts.digitsOptional) { | ||
var digitsFactor = Math.pow(10, digits || 1); | ||
var digits = 0; | ||
if (radixPoint !== "") { | ||
digits = !opts.digitsOptional ? opts.digits : (opts.digits < decimalPart.length ? opts.digits : decimalPart.length); | ||
if (decimalPart !== "" || !opts.digitsOptional) { | ||
var digitsFactor = Math.pow(10, digits || 1); | ||
//make the initialValue a valid javascript number for the parsefloat | ||
initialValue = initialValue.replace(escapeRegex(radixPoint), "."); | ||
if (!isNaN(parseFloat(initialValue))) { | ||
initialValue = (opts.roundingFN(parseFloat(initialValue) * digitsFactor) / digitsFactor).toFixed(digits); | ||
} | ||
initialValue = initialValue.toString().replace(".", radixPoint); | ||
} | ||
} | ||
//this needs to be in a separate part and not directly in decimalPart to allow rounding | ||
if (opts.digits === 0 && initialValue.indexOf(radixPoint) !== -1) { | ||
initialValue = initialValue.substring(0, initialValue.indexOf(radixPoint)); | ||
} | ||
//make the initialValue a valid javascript number for the parsefloat | ||
initialValue = initialValue.replace(escapeRegex(radixPoint), "."); | ||
if (!isNaN(parseFloat(initialValue))) { | ||
initialValue = (opts.roundingFN(parseFloat(initialValue) * digitsFactor) / digitsFactor).toFixed(digits); | ||
} | ||
initialValue = initialValue.toString().replace(".", radixPoint); | ||
} | ||
} | ||
//this needs to be in a separate part and not directly in decimalPart to allow rounding | ||
if (opts.digits === 0 && initialValue.indexOf(radixPoint) !== -1) { | ||
initialValue = initialValue.substring(0, initialValue.indexOf(radixPoint)); | ||
} | ||
if (opts.min !== null || opts.max !== null) { | ||
var numberValue = initialValue.toString().replace(radixPoint, "."); | ||
if (opts.min !== null && numberValue < opts.min) { | ||
initialValue = opts.min.toString().replace(".", radixPoint); | ||
} else if (opts.max !== null && numberValue > opts.max) { | ||
initialValue = opts.max.toString().replace(".", radixPoint); | ||
} | ||
} | ||
if (opts.min !== null || opts.max !== null) { | ||
var numberValue = initialValue.toString().replace(radixPoint, "."); | ||
if (opts.min !== null && numberValue < opts.min) { | ||
initialValue = opts.min.toString().replace(".", radixPoint); | ||
} else if (opts.max !== null && numberValue > opts.max) { | ||
initialValue = opts.max.toString().replace(".", radixPoint); | ||
} | ||
} | ||
if (isNagtive && initialValue.charAt(0) !== "-") { | ||
initialValue = "-" + initialValue; | ||
} | ||
return alignDigits(initialValue.toString().split(""), digits, opts, forceDigits).join(""); | ||
} | ||
, | ||
onBeforeWrite: function (e, buffer, caretPos, opts) { | ||
function stripBuffer(buffer, stripRadix) { | ||
if (opts.__financeInput !== false || stripRadix) { | ||
var position = buffer.indexOf(opts.radixPoint); | ||
if (position !== -1) { | ||
buffer.splice(position, 1); | ||
} | ||
} | ||
if (opts.groupSeparator !== "") { | ||
while ((position = buffer.indexOf(opts.groupSeparator)) !== -1) { | ||
buffer.splice(position, 1); | ||
} | ||
} | ||
if (isNagtive && initialValue.charAt(0) !== "-") { | ||
initialValue = "-" + initialValue; | ||
} | ||
return alignDigits(initialValue.toString().split(""), digits, opts, forceDigits).join(""); | ||
} | ||
, | ||
onBeforeWrite: function (e, buffer, caretPos, opts) { | ||
function stripBuffer(buffer, stripRadix) { | ||
if (opts.__financeInput !== false || stripRadix) { | ||
var position = buffer.indexOf(opts.radixPoint); | ||
if (position !== -1) { | ||
buffer.splice(position, 1); | ||
} | ||
} | ||
if (opts.groupSeparator !== "") { | ||
while ((position = buffer.indexOf(opts.groupSeparator)) !== -1) { | ||
buffer.splice(position, 1); | ||
} | ||
} | ||
return buffer; | ||
} | ||
return buffer; | ||
} | ||
let result, leadingzeroes; | ||
if (opts.stripLeadingZeroes && (leadingzeroes = checkForLeadingZeroes(buffer, opts))) { | ||
const caretNdx = buffer.join("").lastIndexOf(leadingzeroes[0].split("").reverse().join("")) - (leadingzeroes[0] == leadingzeroes.input ? 0 : 1), | ||
offset = (leadingzeroes[0] == leadingzeroes.input ? 1 : 0); | ||
for (let i = leadingzeroes[0].length - offset; i > 0; i--) { | ||
delete this.maskset.validPositions[caretNdx + i]; | ||
delete buffer[caretNdx + i]; | ||
} | ||
} | ||
var result, | ||
leadingzeroes = checkForLeadingZeroes(buffer, opts); | ||
if (e) { | ||
switch (e.type) { | ||
case "blur": | ||
case "checkval": | ||
if (opts.min !== null) { | ||
var unmasked = opts.onUnMask(buffer.slice().reverse().join(""), undefined, $.extend({}, opts, { | ||
unmaskAsNumber: true | ||
})); | ||
if (opts.min !== null && unmasked < opts.min) { | ||
return { | ||
refreshFromBuffer: true, | ||
buffer: alignDigits(opts.min.toString().replace(".", opts.radixPoint).split(""), opts.digits, opts).reverse() | ||
}; | ||
} | ||
} | ||
if (buffer[buffer.length - 1] === opts.negationSymbol.front) { //strip negation symbol on blur when value is 0 | ||
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("")), | ||
number = nmbrMtchs ? nmbrMtchs[2] : ""; | ||
if (number == 0) { | ||
result = {refreshFromBuffer: true, buffer: [0]}; | ||
} | ||
} else if (opts.radixPoint !== "") { //strip radixpoint on blur when it is the latest char | ||
var radixNDX = buffer.indexOf(opts.radixPoint); | ||
if (radixNDX === opts.suffix.length) { | ||
if (result && result.buffer) { | ||
result.buffer.splice(0, 1 + opts.suffix.length); | ||
} else { | ||
buffer.splice(0, 1 + opts.suffix.length); | ||
result = | ||
{refreshFromBuffer: true, buffer: stripBuffer(buffer)}; | ||
} | ||
} | ||
} | ||
if (leadingzeroes) { | ||
const caretNdx = buffer.join("").lastIndexOf(leadingzeroes[0].split("").reverse().join("")) - (leadingzeroes[0] == leadingzeroes.input ? 0 : 1), | ||
offset = (leadingzeroes[0] == leadingzeroes.input ? 1 : 0); | ||
for (let i = leadingzeroes[0].length - offset; i > 0; i--) { | ||
delete this.maskset.validPositions[caretNdx + i]; | ||
delete buffer[caretNdx + i]; | ||
} | ||
} | ||
if (opts.enforceDigitsOnBlur) { | ||
result = result || {}; | ||
var bffr = (result && result.buffer) || buffer.slice().reverse(); | ||
result.refreshFromBuffer = true; | ||
result.buffer = alignDigits(bffr, opts.digits, opts, true).reverse(); | ||
} | ||
} | ||
} | ||
if (e) { | ||
switch (e.type) { | ||
case "blur": | ||
case "checkval": | ||
if (opts.min !== null) { | ||
var unmasked = opts.onUnMask(buffer.slice().reverse().join(""), undefined, $.extend({}, opts, { | ||
unmaskAsNumber: true | ||
})); | ||
if (opts.min !== null && unmasked < opts.min) { | ||
return { | ||
refreshFromBuffer: true, | ||
buffer: alignDigits(opts.min.toString().replace(".", opts.radixPoint).split(""), opts.digits, opts).reverse() | ||
}; | ||
} | ||
} | ||
if (buffer[buffer.length - 1] === opts.negationSymbol.front) { //strip negation symbol on blur when value is 0 | ||
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("")), | ||
number = nmbrMtchs ? nmbrMtchs[2] : ""; | ||
if (number == 0) { | ||
result = {refreshFromBuffer: true, buffer: [0]}; | ||
} | ||
} else if (opts.radixPoint !== "") { //strip radixpoint on blur when it is the latest char | ||
var radixNDX = buffer.indexOf(opts.radixPoint); | ||
if (radixNDX === opts.suffix.length) { | ||
if (result && result.buffer) { | ||
result.buffer.splice(0, 1 + opts.suffix.length); | ||
} else { | ||
buffer.splice(0, 1 + opts.suffix.length); | ||
result = | ||
{refreshFromBuffer: true, buffer: stripBuffer(buffer)}; | ||
} | ||
} | ||
} | ||
if (opts.enforceDigitsOnBlur) { | ||
result = result || {}; | ||
var bffr = (result && result.buffer) || buffer.slice().reverse(); | ||
result.refreshFromBuffer = true; | ||
result.buffer = alignDigits(bffr, opts.digits, opts, true).reverse(); | ||
} | ||
} | ||
} | ||
return result; | ||
}, | ||
onKeyDown: function (e, buffer, caretPos, opts) { | ||
var $input = $(this), bffr; | ||
if (e.ctrlKey) { | ||
switch (e.keyCode) { | ||
case keyCode.UP: | ||
this.inputmask.__valueSet.call(this, parseFloat(this.inputmask.unmaskedvalue()) + parseInt(opts.step)); | ||
$input.trigger("setvalue"); | ||
return false; | ||
case keyCode.DOWN: | ||
this.inputmask.__valueSet.call(this, parseFloat(this.inputmask.unmaskedvalue()) - parseInt(opts.step)); | ||
$input.trigger("setvalue"); | ||
return false; | ||
} | ||
} | ||
if (!e.shiftKey && (e.keyCode === keyCode.DELETE || e.keyCode === keyCode.BACKSPACE || e.keyCode === keyCode.BACKSPACE_SAFARI) && caretPos.begin !== buffer.length) { | ||
if (buffer[e.keyCode === keyCode.DELETE ? caretPos.begin - 1 : caretPos.end] === opts.negationSymbol.front) { | ||
bffr = buffer.slice().reverse(); | ||
if (opts.negationSymbol.front !== "") bffr.shift(); | ||
if (opts.negationSymbol.back !== "") bffr.pop(); | ||
$input.trigger("setvalue", [bffr.join(""), caretPos.begin]); | ||
return false; | ||
} else if (opts._radixDance === true) { | ||
var radixPos = buffer.indexOf(opts.radixPoint); | ||
if (!opts.digitsOptional) { | ||
if (radixPos !== -1 && (caretPos.begin < radixPos || caretPos.end < radixPos || (e.keyCode === keyCode.DELETE && caretPos.begin === radixPos))) { | ||
if (caretPos.begin === caretPos.end && (e.keyCode === keyCode.BACKSPACE || e.keyCode === keyCode.BACKSPACE_SAFARI)) { //only adjust when not a selection | ||
caretPos.begin++; | ||
} | ||
bffr = buffer.slice().reverse(); | ||
bffr.splice(bffr.length - caretPos.begin, caretPos.begin - caretPos.end + 1); | ||
// console.log(caretPos); | ||
bffr = alignDigits(bffr, opts.digits, opts).join(""); | ||
$input.trigger("setvalue", [bffr, caretPos.begin >= bffr.length ? radixPos + 1 : caretPos.begin]); | ||
return false; | ||
} | ||
} else if (radixPos === 0) { | ||
bffr = buffer.slice().reverse(); | ||
bffr.pop(); | ||
$input.trigger("setvalue", [bffr.join(""), caretPos.begin >= bffr.length ? bffr.length : caretPos.begin]); | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"currency": { | ||
prefix: "", //"$ ", | ||
groupSeparator: ",", | ||
alias: "numeric", | ||
digits: 2, | ||
digitsOptional: false | ||
}, | ||
"decimal": { | ||
alias: "numeric" | ||
}, | ||
"integer": { | ||
alias: "numeric", | ||
inputmode: "numeric", | ||
digits: 0 | ||
}, | ||
"percentage": { | ||
alias: "numeric", | ||
min: 0, | ||
max: 100, | ||
suffix: " %", | ||
digits: 0, | ||
allowMinus: false | ||
}, | ||
"indianns": { //indian numbering system | ||
alias: "numeric", | ||
_mask: function (opts) { | ||
return "(" + opts.groupSeparator + "99){*|1}(" + opts.groupSeparator + "999){1|1}"; | ||
}, | ||
groupSeparator: ",", | ||
radixPoint: ".", | ||
placeholder: "0", | ||
digits: 2, | ||
digitsOptional: false | ||
} | ||
}); | ||
return result; | ||
}, | ||
onKeyDown: function (e, buffer, caretPos, opts) { | ||
var $input = $(this), bffr; | ||
var pattern, c = String.fromCharCode(e.keyCode).toLowerCase(); | ||
if ((pattern = (opts.shortcuts && opts.shortcuts[c]))) { | ||
if (pattern.length > 1) { | ||
this.inputmask.__valueSet.call(this, parseFloat(this.inputmask.unmaskedvalue()) * parseInt(pattern)); | ||
$input.trigger("setvalue"); | ||
return false; | ||
} | ||
} | ||
if (e.ctrlKey) { | ||
switch (e.keyCode) { | ||
case keyCode.UP: | ||
this.inputmask.__valueSet.call(this, parseFloat(this.inputmask.unmaskedvalue()) + parseInt(opts.step)); | ||
$input.trigger("setvalue"); | ||
return false; | ||
case keyCode.DOWN: | ||
this.inputmask.__valueSet.call(this, parseFloat(this.inputmask.unmaskedvalue()) - parseInt(opts.step)); | ||
$input.trigger("setvalue"); | ||
return false; | ||
} | ||
} | ||
if (!e.shiftKey && (e.keyCode === keyCode.DELETE || e.keyCode === keyCode.BACKSPACE || e.keyCode === keyCode.BACKSPACE_SAFARI) && caretPos.begin !== buffer.length) { | ||
if (buffer[e.keyCode === keyCode.DELETE ? caretPos.begin - 1 : caretPos.end] === opts.negationSymbol.front) { | ||
bffr = buffer.slice().reverse(); | ||
if (opts.negationSymbol.front !== "") bffr.shift(); | ||
if (opts.negationSymbol.back !== "") bffr.pop(); | ||
$input.trigger("setvalue", [bffr.join(""), caretPos.begin]); | ||
return false; | ||
} else if (opts._radixDance === true) { | ||
var radixPos = buffer.indexOf(opts.radixPoint); | ||
if (!opts.digitsOptional) { | ||
if (radixPos !== -1 && (caretPos.begin < radixPos || caretPos.end < radixPos || (e.keyCode === keyCode.DELETE && caretPos.begin === radixPos))) { | ||
if (caretPos.begin === caretPos.end && (e.keyCode === keyCode.BACKSPACE || e.keyCode === keyCode.BACKSPACE_SAFARI)) { //only adjust when not a selection | ||
caretPos.begin++; | ||
} | ||
bffr = buffer.slice().reverse(); | ||
bffr.splice(bffr.length - caretPos.begin, caretPos.begin - caretPos.end + 1); | ||
// console.log(caretPos); | ||
bffr = alignDigits(bffr, opts.digits, opts).join(""); | ||
$input.trigger("setvalue", [bffr, caretPos.begin >= bffr.length ? radixPos + 1 : caretPos.begin]); | ||
return false; | ||
} | ||
} else if (radixPos === 0) { | ||
bffr = buffer.slice().reverse(); | ||
bffr.pop(); | ||
$input.trigger("setvalue", [bffr.join(""), caretPos.begin >= bffr.length ? bffr.length : caretPos.begin]); | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"currency": { | ||
prefix: "", //"$ ", | ||
groupSeparator: ",", | ||
alias: "numeric", | ||
digits: 2, | ||
digitsOptional: false | ||
}, | ||
"decimal": { | ||
alias: "numeric" | ||
}, | ||
"integer": { | ||
alias: "numeric", | ||
inputmode: "numeric", | ||
digits: 0 | ||
}, | ||
"percentage": { | ||
alias: "numeric", | ||
min: 0, | ||
max: 100, | ||
suffix: " %", | ||
digits: 0, | ||
allowMinus: false | ||
}, | ||
"indianns": { //indian numbering system | ||
alias: "numeric", | ||
_mask: function (opts) { | ||
return "(" + opts.groupSeparator + "99){*|1}(" + opts.groupSeparator + "999){1|1}"; | ||
}, | ||
groupSeparator: ",", | ||
radixPoint: ".", | ||
placeholder: "0", | ||
digits: 2, | ||
digitsOptional: false | ||
} | ||
}); |
@@ -8,463 +8,461 @@ import $ from "./dependencyLibs/inputmask.dependencyLib"; | ||
function generateMaskSet(opts, nocache) { | ||
var ms; | ||
var ms; | ||
function generateMask(mask, metadata, opts) { | ||
var regexMask = false; | ||
if (mask === null || mask === "") { | ||
regexMask = opts.regex !== null; | ||
if (regexMask) { | ||
mask = opts.regex; | ||
mask = mask.replace(/^(\^)(.*)(\$)$/, "$2"); | ||
} else { | ||
regexMask = true; | ||
mask = ".*"; | ||
} | ||
} | ||
if (mask.length === 1 && opts.greedy === false && opts.repeat !== 0) { | ||
opts.placeholder = ""; | ||
} //hide placeholder with single non-greedy mask | ||
if (opts.repeat > 0 || opts.repeat === "*" || opts.repeat === "+") { | ||
var repeatStart = opts.repeat === "*" ? 0 : (opts.repeat === "+" ? 1 : opts.repeat); | ||
mask = opts.groupmarker[0] + mask + opts.groupmarker[1] + opts.quantifiermarker[0] + repeatStart + "," + opts.repeat + opts.quantifiermarker[1]; | ||
} | ||
function generateMask(mask, metadata, opts) { | ||
var regexMask = false; | ||
if (mask === null || mask === "") { | ||
regexMask = opts.regex !== null; | ||
if (regexMask) { | ||
mask = opts.regex; | ||
mask = mask.replace(/^(\^)(.*)(\$)$/, "$2"); | ||
} else { | ||
regexMask = true; | ||
mask = ".*"; | ||
} | ||
} | ||
if (mask.length === 1 && opts.greedy === false && opts.repeat !== 0) { | ||
opts.placeholder = ""; | ||
} //hide placeholder with single non-greedy mask | ||
if (opts.repeat > 0 || opts.repeat === "*" || opts.repeat === "+") { | ||
var repeatStart = opts.repeat === "*" ? 0 : (opts.repeat === "+" ? 1 : opts.repeat); | ||
mask = opts.groupmarker[0] + mask + opts.groupmarker[1] + opts.quantifiermarker[0] + repeatStart + "," + opts.repeat + opts.quantifiermarker[1]; | ||
} | ||
// console.log(mask); | ||
var masksetDefinition, maskdefKey; | ||
maskdefKey = regexMask ? "regex_" + opts.regex : opts.numericInput ? mask.split("").reverse().join("") : mask; | ||
if (opts.keepStatic !== false) { //keepstatic modifies the output from the testdefinitions ~ so differentiate in the maskcache | ||
maskdefKey = "ks_" + maskdefKey; | ||
} | ||
// console.log(mask); | ||
var masksetDefinition, maskdefKey; | ||
maskdefKey = regexMask ? "regex_" + opts.regex : opts.numericInput ? mask.split("").reverse().join("") : mask; | ||
if (opts.keepStatic !== null) { //keepstatic modifies the output from the testdefinitions ~ so differentiate in the maskcache | ||
maskdefKey = "ks_" + opts.keepStatic + maskdefKey; | ||
} | ||
if (Inputmask.prototype.masksCache[maskdefKey] === undefined || nocache === true) { | ||
masksetDefinition = { | ||
"mask": mask, | ||
"maskToken": Inputmask.prototype.analyseMask(mask, regexMask, opts), | ||
"validPositions": {}, | ||
"_buffer": undefined, | ||
"buffer": undefined, | ||
"tests": {}, | ||
"excludes": {}, //excluded alternations | ||
"metadata": metadata, | ||
"maskLength": undefined, | ||
"jitOffset": {} | ||
}; | ||
if (nocache !== true) { | ||
Inputmask.prototype.masksCache[maskdefKey] = masksetDefinition; | ||
masksetDefinition = $.extend(true, {}, Inputmask.prototype.masksCache[maskdefKey]); | ||
} | ||
} else { | ||
masksetDefinition = $.extend(true, {}, Inputmask.prototype.masksCache[maskdefKey]); | ||
} | ||
if (Inputmask.prototype.masksCache[maskdefKey] === undefined || nocache === true) { | ||
masksetDefinition = { | ||
"mask": mask, | ||
"maskToken": Inputmask.prototype.analyseMask(mask, regexMask, opts), | ||
"validPositions": {}, | ||
"_buffer": undefined, | ||
"buffer": undefined, | ||
"tests": {}, | ||
"excludes": {}, //excluded alternations | ||
"metadata": metadata, | ||
"maskLength": undefined, | ||
"jitOffset": {} | ||
}; | ||
if (nocache !== true) { | ||
Inputmask.prototype.masksCache[maskdefKey] = masksetDefinition; | ||
masksetDefinition = $.extend(true, {}, Inputmask.prototype.masksCache[maskdefKey]); | ||
} | ||
} else { | ||
masksetDefinition = $.extend(true, {}, Inputmask.prototype.masksCache[maskdefKey]); | ||
} | ||
return masksetDefinition; | ||
} | ||
return masksetDefinition; | ||
} | ||
if (typeof opts.mask === "function") { //allow mask to be a preprocessing fn - should return a valid mask | ||
opts.mask = opts.mask(opts); | ||
} | ||
if (Array.isArray(opts.mask)) { | ||
if (opts.mask.length > 1) { | ||
if (opts.keepStatic === null) { //enable by default when passing multiple masks when the option is not explicitly specified | ||
opts.keepStatic = true; | ||
} | ||
var altMask = opts.groupmarker[0]; | ||
(opts.isRTL ? opts.mask.reverse() : opts.mask).forEach(function (msk) { | ||
if (altMask.length > 1) { | ||
altMask += opts.groupmarker[1] + opts.alternatormarker + opts.groupmarker[0]; | ||
} | ||
if (msk.mask !== undefined && typeof msk.mask !== "function") { | ||
altMask += msk.mask; | ||
} else { | ||
altMask += msk; | ||
} | ||
}); | ||
altMask += opts.groupmarker[1]; | ||
// console.log(altMask); | ||
return generateMask(altMask, opts.mask, opts); | ||
} else { | ||
opts.mask = opts.mask.pop(); | ||
} | ||
} | ||
if (opts.keepStatic === null) opts.keepStatic = false; | ||
if (opts.mask && opts.mask.mask !== undefined && typeof opts.mask.mask !== "function") { | ||
ms = generateMask(opts.mask.mask, opts.mask, opts); | ||
} else { | ||
ms = generateMask(opts.mask, opts.mask, opts); | ||
} | ||
return ms; | ||
if (typeof opts.mask === "function") { //allow mask to be a preprocessing fn - should return a valid mask | ||
opts.mask = opts.mask(opts); | ||
} | ||
if (Array.isArray(opts.mask)) { | ||
if (opts.mask.length > 1) { | ||
if (opts.keepStatic === null) { //enable by default when passing multiple masks when the option is not explicitly specified | ||
opts.keepStatic = true; | ||
} | ||
var altMask = opts.groupmarker[0]; | ||
(opts.isRTL ? opts.mask.reverse() : opts.mask).forEach(function (msk) { | ||
if (altMask.length > 1) { | ||
altMask += opts.alternatormarker; | ||
} | ||
if (msk.mask !== undefined && typeof msk.mask !== "function") { | ||
altMask += msk.mask; | ||
} else { | ||
altMask += msk; | ||
} | ||
}); | ||
altMask += opts.groupmarker[1]; | ||
// console.log(altMask); | ||
return generateMask(altMask, opts.mask, opts); | ||
} else { | ||
opts.mask = opts.mask.pop(); | ||
} | ||
} | ||
if (opts.mask && opts.mask.mask !== undefined && typeof opts.mask.mask !== "function") { | ||
ms = generateMask(opts.mask.mask, opts.mask, opts); | ||
} else { | ||
ms = generateMask(opts.mask, opts.mask, opts); | ||
} | ||
if (opts.keepStatic === null) opts.keepStatic = false; | ||
return ms; | ||
} | ||
function analyseMask(mask, regexMask, opts) { | ||
const tokenizer = /(?:[?*+]|\{[0-9+*]+(?:,[0-9+*]*)?(?:\|[0-9+*]*)?\})|[^.?*+^${[]()|\\]+|./g, | ||
//Thx to https://github.com/slevithan/regex-colorizer for the regexTokenizer regex | ||
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; | ||
var escaped = false, | ||
currentToken = new MaskToken(), | ||
match, | ||
m, | ||
openenings = [], | ||
maskTokens = [], | ||
openingToken, | ||
currentOpeningToken, | ||
alternator, | ||
lastMatch, | ||
closeRegexGroup = false; | ||
const tokenizer = /(?:[?*+]|\{[0-9+*]+(?:,[0-9+*]*)?(?:\|[0-9+*]*)?\})|[^.?*+^${[]()|\\]+|./g, | ||
//Thx to https://github.com/slevithan/regex-colorizer for the regexTokenizer regex | ||
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; | ||
var escaped = false, | ||
currentToken = new MaskToken(), | ||
match, | ||
m, | ||
openenings = [], | ||
maskTokens = [], | ||
openingToken, | ||
currentOpeningToken, | ||
alternator, | ||
lastMatch, | ||
closeRegexGroup = false; | ||
//test definition => {fn: RegExp/function, static: true/false optionality: bool, newBlockMarker: bool, casing: null/upper/lower, def: definitionSymbol, placeholder: placeholder, mask: real maskDefinition} | ||
function insertTestDefinition(mtoken, element, position) { | ||
position = position !== undefined ? position : mtoken.matches.length; | ||
var prevMatch = mtoken.matches[position - 1]; | ||
if (regexMask) { | ||
if (element.indexOf("[") === 0 || (escaped && /\\d|\\s|\\w]/i.test(element)) || element === ".") { | ||
mtoken.matches.splice(position++, 0, { | ||
fn: new RegExp(element, opts.casing ? "i" : ""), | ||
static: false, | ||
optionality: false, | ||
newBlockMarker: prevMatch === undefined ? "master" : prevMatch.def !== element, | ||
casing: null, | ||
def: element, | ||
placeholder: undefined, | ||
nativeDef: element | ||
}); | ||
} else { | ||
if (escaped) element = element[element.length - 1]; | ||
element.split("").forEach(function (lmnt, ndx) { | ||
prevMatch = mtoken.matches[position - 1]; | ||
mtoken.matches.splice(position++, 0, { | ||
fn: /[a-z]/i.test((opts.staticDefinitionSymbol || lmnt)) ? new RegExp("[" + (opts.staticDefinitionSymbol || lmnt) + "]", opts.casing ? "i" : "") : null, | ||
static: true, | ||
optionality: false, | ||
newBlockMarker: prevMatch === undefined ? "master" : (prevMatch.def !== lmnt && prevMatch.static !== true), | ||
casing: null, | ||
def: opts.staticDefinitionSymbol || lmnt, | ||
placeholder: opts.staticDefinitionSymbol !== undefined ? lmnt : undefined, | ||
nativeDef: (escaped ? "'" : "") + lmnt | ||
}); | ||
}); | ||
} | ||
escaped = false; | ||
} else { | ||
var maskdef = (opts.definitions && opts.definitions[element]) || (opts.usePrototypeDefinitions && Inputmask.prototype.definitions[element]); | ||
if (maskdef && !escaped) { | ||
mtoken.matches.splice(position++, 0, { | ||
fn: maskdef.validator ? typeof maskdef.validator == "string" ? new RegExp(maskdef.validator, opts.casing ? "i" : "") : new function () { | ||
this.test = maskdef.validator; | ||
} : new RegExp("."), | ||
static: maskdef.static || false, | ||
optionality: maskdef.optional || false, | ||
newBlockMarker: (prevMatch === undefined || maskdef.optional) ? "master" : prevMatch.def !== (maskdef.definitionSymbol || element), | ||
casing: maskdef.casing, | ||
def: maskdef.definitionSymbol || element, | ||
placeholder: maskdef.placeholder, | ||
nativeDef: element, | ||
generated: maskdef.generated | ||
}); | ||
} else { | ||
mtoken.matches.splice(position++, 0, { | ||
fn: /[a-z]/i.test((opts.staticDefinitionSymbol || element)) ? new RegExp("[" + (opts.staticDefinitionSymbol || element) + "]", opts.casing ? "i" : "") : null, | ||
static: true, | ||
optionality: false, | ||
newBlockMarker: prevMatch === undefined ? "master" : (prevMatch.def !== element && prevMatch.static !== true), | ||
casing: null, | ||
def: opts.staticDefinitionSymbol || element, | ||
placeholder: opts.staticDefinitionSymbol !== undefined ? element : undefined, | ||
nativeDef: (escaped ? "'" : "") + element | ||
}); | ||
escaped = false; | ||
} | ||
} | ||
} | ||
//test definition => {fn: RegExp/function, static: true/false optionality: bool, newBlockMarker: bool, casing: null/upper/lower, def: definitionSymbol, placeholder: placeholder, mask: real maskDefinition} | ||
function insertTestDefinition(mtoken, element, position) { | ||
position = position !== undefined ? position : mtoken.matches.length; | ||
var prevMatch = mtoken.matches[position - 1]; | ||
if (regexMask) { | ||
if (element.indexOf("[") === 0 || (escaped && /\\d|\\s|\\w/i.test(element)) || element === ".") { | ||
mtoken.matches.splice(position++, 0, { | ||
fn: new RegExp(element, opts.casing ? "i" : ""), | ||
static: false, | ||
optionality: false, | ||
newBlockMarker: prevMatch === undefined ? "master" : prevMatch.def !== element, | ||
casing: null, | ||
def: element, | ||
placeholder: undefined, | ||
nativeDef: element | ||
}); | ||
} else { | ||
if (escaped) element = element[element.length - 1]; | ||
element.split("").forEach(function (lmnt, ndx) { | ||
prevMatch = mtoken.matches[position - 1]; | ||
mtoken.matches.splice(position++, 0, { | ||
fn: /[a-z]/i.test((opts.staticDefinitionSymbol || lmnt)) ? new RegExp("[" + (opts.staticDefinitionSymbol || lmnt) + "]", opts.casing ? "i" : "") : null, | ||
static: true, | ||
optionality: false, | ||
newBlockMarker: prevMatch === undefined ? "master" : (prevMatch.def !== lmnt && prevMatch.static !== true), | ||
casing: null, | ||
def: opts.staticDefinitionSymbol || lmnt, | ||
placeholder: opts.staticDefinitionSymbol !== undefined ? lmnt : undefined, | ||
nativeDef: (escaped ? "'" : "") + lmnt | ||
}); | ||
}); | ||
} | ||
escaped = false; | ||
} else { | ||
var maskdef = (opts.definitions && opts.definitions[element]) || (opts.usePrototypeDefinitions && Inputmask.prototype.definitions[element]); | ||
if (maskdef && !escaped) { | ||
mtoken.matches.splice(position++, 0, { | ||
fn: maskdef.validator ? typeof maskdef.validator == "string" ? new RegExp(maskdef.validator, opts.casing ? "i" : "") : new function () { | ||
this.test = maskdef.validator; | ||
} : new RegExp("."), | ||
static: maskdef.static || false, | ||
optionality: maskdef.optional || false, | ||
newBlockMarker: (prevMatch === undefined || maskdef.optional) ? "master" : prevMatch.def !== (maskdef.definitionSymbol || element), | ||
casing: maskdef.casing, | ||
def: maskdef.definitionSymbol || element, | ||
placeholder: maskdef.placeholder, | ||
nativeDef: element, | ||
generated: maskdef.generated | ||
}); | ||
} else { | ||
mtoken.matches.splice(position++, 0, { | ||
fn: /[a-z]/i.test((opts.staticDefinitionSymbol || element)) ? new RegExp("[" + (opts.staticDefinitionSymbol || element) + "]", opts.casing ? "i" : "") : null, | ||
static: true, | ||
optionality: false, | ||
newBlockMarker: prevMatch === undefined ? "master" : (prevMatch.def !== element && prevMatch.static !== true), | ||
casing: null, | ||
def: opts.staticDefinitionSymbol || element, | ||
placeholder: opts.staticDefinitionSymbol !== undefined ? element : undefined, | ||
nativeDef: (escaped ? "'" : "") + element | ||
}); | ||
escaped = false; | ||
} | ||
} | ||
} | ||
function verifyGroupMarker(maskToken) { | ||
if (maskToken && maskToken.matches) { | ||
maskToken.matches.forEach(function (token, ndx) { | ||
var nextToken = maskToken.matches[ndx + 1]; | ||
if ((nextToken === undefined || (nextToken.matches === undefined || nextToken.isQuantifier === false)) && token && token.isGroup) { //this is not a group but a normal mask => convert | ||
token.isGroup = false; | ||
if (!regexMask) { | ||
insertTestDefinition(token, opts.groupmarker[0], 0); | ||
if (token.openGroup !== true) { | ||
insertTestDefinition(token, opts.groupmarker[1]); | ||
} | ||
} | ||
} | ||
verifyGroupMarker(token); | ||
}); | ||
} | ||
} | ||
function verifyGroupMarker(maskToken) { | ||
if (maskToken && maskToken.matches) { | ||
maskToken.matches.forEach(function (token, ndx) { | ||
var nextToken = maskToken.matches[ndx + 1]; | ||
if ((nextToken === undefined || (nextToken.matches === undefined || nextToken.isQuantifier === false)) && token && token.isGroup) { //this is not a group but a normal mask => convert | ||
token.isGroup = false; | ||
if (!regexMask) { | ||
insertTestDefinition(token, opts.groupmarker[0], 0); | ||
if (token.openGroup !== true) { | ||
insertTestDefinition(token, opts.groupmarker[1]); | ||
} | ||
} | ||
} | ||
verifyGroupMarker(token); | ||
}); | ||
} | ||
} | ||
function defaultCase() { | ||
if (openenings.length > 0) { | ||
currentOpeningToken = openenings[openenings.length - 1]; | ||
insertTestDefinition(currentOpeningToken, m); | ||
if (currentOpeningToken.isAlternator) { //handle alternator a | b case | ||
alternator = openenings.pop(); | ||
for (var mndx = 0; mndx < alternator.matches.length; mndx++) { | ||
if (alternator.matches[mndx].isGroup) alternator.matches[mndx].isGroup = false; //don't mark alternate groups as group | ||
} | ||
if (openenings.length > 0) { | ||
currentOpeningToken = openenings[openenings.length - 1]; | ||
currentOpeningToken.matches.push(alternator); | ||
} else { | ||
currentToken.matches.push(alternator); | ||
} | ||
} | ||
} else { | ||
insertTestDefinition(currentToken, m); | ||
} | ||
} | ||
function defaultCase() { | ||
if (openenings.length > 0) { | ||
currentOpeningToken = openenings[openenings.length - 1]; | ||
insertTestDefinition(currentOpeningToken, m); | ||
if (currentOpeningToken.isAlternator) { //handle alternator a | b case | ||
alternator = openenings.pop(); | ||
for (var mndx = 0; mndx < alternator.matches.length; mndx++) { | ||
if (alternator.matches[mndx].isGroup) alternator.matches[mndx].isGroup = false; //don't mark alternate groups as group | ||
} | ||
if (openenings.length > 0) { | ||
currentOpeningToken = openenings[openenings.length - 1]; | ||
currentOpeningToken.matches.push(alternator); | ||
} else { | ||
currentToken.matches.push(alternator); | ||
} | ||
} | ||
} else { | ||
insertTestDefinition(currentToken, m); | ||
} | ||
} | ||
function reverseTokens(maskToken) { | ||
function reverseStatic(st) { | ||
if (st === opts.optionalmarker[0]) { | ||
st = opts.optionalmarker[1]; | ||
} else if (st === opts.optionalmarker[1]) { | ||
st = opts.optionalmarker[0]; | ||
} else if (st === opts.groupmarker[0]) { | ||
st = opts.groupmarker[1]; | ||
} else if (st === opts.groupmarker[1]) st = opts.groupmarker[0]; | ||
function reverseTokens(maskToken) { | ||
function reverseStatic(st) { | ||
if (st === opts.optionalmarker[0]) { | ||
st = opts.optionalmarker[1]; | ||
} else if (st === opts.optionalmarker[1]) { | ||
st = opts.optionalmarker[0]; | ||
} else if (st === opts.groupmarker[0]) { | ||
st = opts.groupmarker[1]; | ||
} else if (st === opts.groupmarker[1]) st = opts.groupmarker[0]; | ||
return st; | ||
} | ||
return st; | ||
} | ||
maskToken.matches = maskToken.matches.reverse(); | ||
for (var match in maskToken.matches) { | ||
if (Object.prototype.hasOwnProperty.call(maskToken.matches, match)) { | ||
var intMatch = parseInt(match); | ||
if (maskToken.matches[match].isQuantifier && maskToken.matches[intMatch + 1] && maskToken.matches[intMatch + 1].isGroup) { //reposition quantifier | ||
var qt = maskToken.matches[match]; | ||
maskToken.matches.splice(match, 1); | ||
maskToken.matches.splice(intMatch + 1, 0, qt); | ||
} | ||
if (maskToken.matches[match].matches !== undefined) { | ||
maskToken.matches[match] = reverseTokens(maskToken.matches[match]); | ||
} else { | ||
maskToken.matches[match] = reverseStatic(maskToken.matches[match]); | ||
} | ||
} | ||
} | ||
maskToken.matches = maskToken.matches.reverse(); | ||
for (var match in maskToken.matches) { | ||
if (Object.prototype.hasOwnProperty.call(maskToken.matches, match)) { | ||
var intMatch = parseInt(match); | ||
if (maskToken.matches[match].isQuantifier && maskToken.matches[intMatch + 1] && maskToken.matches[intMatch + 1].isGroup) { //reposition quantifier | ||
var qt = maskToken.matches[match]; | ||
maskToken.matches.splice(match, 1); | ||
maskToken.matches.splice(intMatch + 1, 0, qt); | ||
} | ||
if (maskToken.matches[match].matches !== undefined) { | ||
maskToken.matches[match] = reverseTokens(maskToken.matches[match]); | ||
} else { | ||
maskToken.matches[match] = reverseStatic(maskToken.matches[match]); | ||
} | ||
} | ||
} | ||
return maskToken; | ||
} | ||
return maskToken; | ||
} | ||
function groupify(matches) { | ||
var groupToken = new MaskToken(true); | ||
groupToken.openGroup = false; | ||
groupToken.matches = matches; | ||
return groupToken; | ||
} | ||
function groupify(matches) { | ||
var groupToken = new MaskToken(true); | ||
groupToken.openGroup = false; | ||
groupToken.matches = matches; | ||
return groupToken; | ||
} | ||
function closeGroup() { | ||
// Group closing | ||
openingToken = openenings.pop(); | ||
openingToken.openGroup = false; //mark group as complete | ||
if (openingToken !== undefined) { | ||
if (openenings.length > 0) { | ||
currentOpeningToken = openenings[openenings.length - 1]; | ||
currentOpeningToken.matches.push(openingToken); | ||
if (currentOpeningToken.isAlternator) { //handle alternator (a) | (b) case | ||
alternator = openenings.pop(); | ||
for (var mndx = 0; mndx < alternator.matches.length; mndx++) { | ||
alternator.matches[mndx].isGroup = false; //don't mark alternate groups as group | ||
alternator.matches[mndx].alternatorGroup = false; | ||
} | ||
if (openenings.length > 0) { | ||
currentOpeningToken = openenings[openenings.length - 1]; | ||
currentOpeningToken.matches.push(alternator); | ||
} else { | ||
currentToken.matches.push(alternator); | ||
} | ||
} | ||
} else { | ||
currentToken.matches.push(openingToken); | ||
} | ||
} else { | ||
defaultCase(); | ||
} | ||
} | ||
function closeGroup() { | ||
// Group closing | ||
openingToken = openenings.pop(); | ||
openingToken.openGroup = false; //mark group as complete | ||
if (openingToken !== undefined) { | ||
if (openenings.length > 0) { | ||
currentOpeningToken = openenings[openenings.length - 1]; | ||
currentOpeningToken.matches.push(openingToken); | ||
if (currentOpeningToken.isAlternator) { //handle alternator (a) | (b) case | ||
alternator = openenings.pop(); | ||
let altMatchesLength = alternator.matches[0].matches ? alternator.matches[0].matches.length : 1; | ||
for (var mndx = 0; mndx < alternator.matches.length; mndx++) { | ||
alternator.matches[mndx].isGroup = false; //don't mark alternate groups as group | ||
alternator.matches[mndx].alternatorGroup = false; | ||
if (opts.keepStatic === null && altMatchesLength < (alternator.matches[mndx].matches ? alternator.matches[mndx].matches.length : 1)) { //enable by default when passing multiple masks when the option is not explicitly specified | ||
opts.keepStatic = true; | ||
} | ||
altMatchesLength = alternator.matches[mndx].matches ? alternator.matches[mndx].matches.length : 1; | ||
} | ||
if (openenings.length > 0) { | ||
currentOpeningToken = openenings[openenings.length - 1]; | ||
currentOpeningToken.matches.push(alternator); | ||
} else { | ||
currentToken.matches.push(alternator); | ||
} | ||
} | ||
} else { | ||
currentToken.matches.push(openingToken); | ||
} | ||
} else { | ||
defaultCase(); | ||
} | ||
} | ||
function groupQuantifier(matches) { | ||
var lastMatch = matches.pop(); | ||
if (lastMatch.isQuantifier) { | ||
lastMatch = groupify([matches.pop(), lastMatch]); | ||
} | ||
return lastMatch; | ||
} | ||
function groupQuantifier(matches) { | ||
var lastMatch = matches.pop(); | ||
if (lastMatch.isQuantifier) { | ||
lastMatch = groupify([matches.pop(), lastMatch]); | ||
} | ||
return lastMatch; | ||
} | ||
if (regexMask) { | ||
opts.optionalmarker[0] = undefined; | ||
opts.optionalmarker[1] = undefined; | ||
} | ||
while ((match = regexMask ? regexTokenizer.exec(mask) : tokenizer.exec(mask))) { | ||
m = match[0]; | ||
if (regexMask) { | ||
opts.optionalmarker[0] = undefined; | ||
opts.optionalmarker[1] = undefined; | ||
} | ||
while ((match = regexMask ? regexTokenizer.exec(mask) : tokenizer.exec(mask))) { | ||
m = match[0]; | ||
if (regexMask) { | ||
switch (m.charAt(0)) { | ||
//Quantifier | ||
case "?": | ||
m = "{0,1}"; | ||
break; | ||
case "+": | ||
case "*": | ||
m = "{" + m + "}"; | ||
break; | ||
case "|": | ||
//regex mask alternator ex: [01][0-9]|2[0-3] => ([01][0-9]|2[0-3]) | ||
if (openenings.length === 0) { //wrap the mask in a group to form a regex alternator ([01][0-9]|2[0-3]) | ||
var altRegexGroup = groupify(currentToken.matches); | ||
altRegexGroup.openGroup = true; | ||
openenings.push(altRegexGroup); | ||
currentToken.matches = []; | ||
closeRegexGroup = true; | ||
} | ||
break; | ||
} | ||
switch (m) { | ||
case "\\d": | ||
m = "[0-9]"; | ||
break; | ||
} | ||
} | ||
if (regexMask) { | ||
switch (m.charAt(0)) { | ||
//Quantifier | ||
case "?": | ||
m = "{0,1}"; | ||
break; | ||
case "+": | ||
case "*": | ||
m = "{" + m + "}"; | ||
break; | ||
case "|": | ||
//regex mask alternator ex: [01][0-9]|2[0-3] => ([01][0-9]|2[0-3]) | ||
if (openenings.length === 0) { //wrap the mask in a group to form a regex alternator ([01][0-9]|2[0-3]) | ||
var altRegexGroup = groupify(currentToken.matches); | ||
altRegexGroup.openGroup = true; | ||
openenings.push(altRegexGroup); | ||
currentToken.matches = []; | ||
closeRegexGroup = true; | ||
} | ||
break; | ||
} | ||
switch (m) { | ||
case "\\d": | ||
m = "[0-9]"; | ||
break; | ||
case "(?=": //lookahead | ||
// openenings.push(new MaskToken(true)); | ||
break; | ||
case "(?!": //negative lookahead | ||
// openenings.push(new MaskToken(true)); | ||
break; | ||
case "(?<=": //lookbehind | ||
// openenings.push(new MaskToken(true)); | ||
break; | ||
case "(?<!": //negative lookbehind | ||
// openenings.push(new MaskToken(true)); | ||
break; | ||
} | ||
} | ||
if (escaped) { | ||
defaultCase(); | ||
continue; | ||
} | ||
switch (m) { | ||
case "(?=": //lookahead | ||
// openenings.push(new MaskToken(true)); | ||
break; | ||
case "(?!": //negative lookahead | ||
// openenings.push(new MaskToken(true)); | ||
break; | ||
case "(?<=": //lookbehind | ||
// openenings.push(new MaskToken(true)); | ||
break; | ||
case "(?<!": //negative lookbehind | ||
// openenings.push(new MaskToken(true)); | ||
break; | ||
} | ||
switch (m.charAt(0)) { | ||
case "$": | ||
case "^": | ||
//ignore beginswith and endswith as in masking this makes no point | ||
if (!regexMask) { | ||
defaultCase(); | ||
} | ||
break; | ||
case opts.escapeChar: | ||
escaped = true; | ||
if (regexMask) { | ||
defaultCase(); | ||
} | ||
break; | ||
// optional closing | ||
case opts.optionalmarker[1]: | ||
case opts.groupmarker[1]: | ||
closeGroup(); | ||
break; | ||
case opts.optionalmarker[0]: | ||
// optional opening | ||
openenings.push(new MaskToken(false, true)); | ||
break; | ||
case opts.groupmarker[0]: | ||
// Group opening | ||
openenings.push(new MaskToken(true)); | ||
break; | ||
case opts.quantifiermarker[0]: | ||
//Quantifier | ||
var quantifier = new MaskToken(false, false, true); | ||
if (escaped) { | ||
defaultCase(); | ||
continue; | ||
} | ||
switch (m.charAt(0)) { | ||
case "$": | ||
case "^": | ||
//ignore beginswith and endswith as in masking this makes no point | ||
if (!regexMask) { | ||
defaultCase(); | ||
} | ||
break; | ||
case opts.escapeChar: | ||
escaped = true; | ||
if (regexMask) defaultCase(); | ||
break; | ||
// optional closing | ||
case opts.optionalmarker[1]: | ||
case opts.groupmarker[1]: | ||
closeGroup(); | ||
break; | ||
case opts.optionalmarker[0]: | ||
// optional opening | ||
openenings.push(new MaskToken(false, true)); | ||
break; | ||
case opts.groupmarker[0]: | ||
// Group opening | ||
openenings.push(new MaskToken(true)); | ||
break; | ||
case opts.quantifiermarker[0]: | ||
//Quantifier | ||
var quantifier = new MaskToken(false, false, true); | ||
m = m.replace(/[{}?]/g, ""); //? matches lazy quantifiers | ||
var mqj = m.split("|"), | ||
mq = mqj[0].split(","), | ||
mq0 = isNaN(mq[0]) ? mq[0] : parseInt(mq[0]), | ||
mq1 = mq.length === 1 ? mq0 : (isNaN(mq[1]) ? mq[1] : parseInt(mq[1])), | ||
mqJit = isNaN(mqj[1]) ? mqj[1] : parseInt(mqj[1]); | ||
if (mq0 === "*" || mq0 === "+") { | ||
mq0 = mq1 === "*" ? 0 : 1; | ||
} | ||
quantifier.quantifier = { | ||
min: mq0, | ||
max: mq1, | ||
jit: mqJit | ||
}; | ||
var matches = openenings.length > 0 ? openenings[openenings.length - 1].matches : currentToken.matches; | ||
match = matches.pop(); | ||
if (match.isAlternator) { //handle quantifier in an alternation [0-9]{2}|[0-9]{3} | ||
matches.push(match); //push back alternator | ||
matches = match.matches; //remap target matches | ||
var groupToken = new MaskToken(true); | ||
var tmpMatch = matches.pop(); | ||
matches.push(groupToken); //push the group | ||
matches = groupToken.matches; | ||
match = tmpMatch; | ||
} | ||
if (!match.isGroup) { | ||
// if (regexMask && match.fn === null) { //why is this needed??? | ||
// if (match.def === ".") match.fn = new RegExp(match.def, opts.casing ? "i" : ""); | ||
// } | ||
m = m.replace(/[{}?]/g, ""); //? matches lazy quantifiers | ||
var mqj = m.split("|"), | ||
mq = mqj[0].split(","), | ||
mq0 = isNaN(mq[0]) ? mq[0] : parseInt(mq[0]), | ||
mq1 = mq.length === 1 ? mq0 : (isNaN(mq[1]) ? mq[1] : parseInt(mq[1])), | ||
mqJit = isNaN(mqj[1]) ? mqj[1] : parseInt(mqj[1]); | ||
if (mq0 === "*" || mq0 === "+") { | ||
mq0 = mq1 === "*" ? 0 : 1; | ||
} | ||
quantifier.quantifier = { | ||
min: mq0, | ||
max: mq1, | ||
jit: mqJit | ||
}; | ||
var matches = openenings.length > 0 ? openenings[openenings.length - 1].matches : currentToken.matches; | ||
match = matches.pop(); | ||
if (match.isAlternator) { //handle quantifier in an alternation [0-9]{2}|[0-9]{3} | ||
matches.push(match); //push back alternator | ||
matches = match.matches; //remap target matches | ||
var groupToken = new MaskToken(true); | ||
var tmpMatch = matches.pop(); | ||
matches.push(groupToken); //push the group | ||
matches = groupToken.matches; | ||
match = tmpMatch; | ||
} | ||
if (!match.isGroup) { | ||
// if (regexMask && match.fn === null) { //why is this needed??? | ||
// if (match.def === ".") match.fn = new RegExp(match.def, opts.casing ? "i" : ""); | ||
// } | ||
match = groupify([match]); | ||
} | ||
matches.push(match); | ||
matches.push(quantifier); | ||
match = groupify([match]); | ||
} | ||
matches.push(match); | ||
matches.push(quantifier); | ||
break; | ||
case opts.alternatormarker: | ||
break; | ||
case opts.alternatormarker: | ||
if (openenings.length > 0) { | ||
currentOpeningToken = openenings[openenings.length - 1]; | ||
var subToken = currentOpeningToken.matches[currentOpeningToken.matches.length - 1]; | ||
if (currentOpeningToken.openGroup && //regexp alt syntax | ||
(subToken.matches === undefined || (subToken.isGroup === false && subToken.isAlternator === false))) { //alternations within group | ||
lastMatch = openenings.pop(); | ||
} else { | ||
lastMatch = groupQuantifier(currentOpeningToken.matches); | ||
} | ||
} else { | ||
lastMatch = groupQuantifier(currentToken.matches); | ||
} | ||
if (lastMatch.isAlternator) { | ||
openenings.push(lastMatch); | ||
} else { | ||
if (lastMatch.alternatorGroup) { | ||
alternator = openenings.pop(); | ||
lastMatch.alternatorGroup = false; | ||
} else { | ||
alternator = new MaskToken(false, false, false, true); | ||
} | ||
alternator.matches.push(lastMatch); | ||
openenings.push(alternator); | ||
if (lastMatch.openGroup) { //regexp alt syntax | ||
lastMatch.openGroup = false; | ||
var alternatorGroup = new MaskToken(true); | ||
alternatorGroup.alternatorGroup = true; | ||
openenings.push(alternatorGroup); | ||
} | ||
} | ||
break; | ||
default: | ||
defaultCase(); | ||
} | ||
} | ||
if (closeRegexGroup) closeGroup(); | ||
if (openenings.length > 0) { | ||
currentOpeningToken = openenings[openenings.length - 1]; | ||
var subToken = currentOpeningToken.matches[currentOpeningToken.matches.length - 1]; | ||
if (currentOpeningToken.openGroup && //regexp alt syntax | ||
(subToken.matches === undefined || (subToken.isGroup === false && subToken.isAlternator === false))) { //alternations within group | ||
lastMatch = openenings.pop(); | ||
} else { | ||
lastMatch = groupQuantifier(currentOpeningToken.matches); | ||
} | ||
} else { | ||
lastMatch = groupQuantifier(currentToken.matches); | ||
} | ||
if (lastMatch.isAlternator) { | ||
openenings.push(lastMatch); | ||
} else { | ||
if (lastMatch.alternatorGroup) { | ||
alternator = openenings.pop(); | ||
lastMatch.alternatorGroup = false; | ||
} else { | ||
alternator = new MaskToken(false, false, false, true); | ||
} | ||
alternator.matches.push(lastMatch); | ||
openenings.push(alternator); | ||
if (lastMatch.openGroup) { //regexp alt syntax | ||
lastMatch.openGroup = false; | ||
var alternatorGroup = new MaskToken(true); | ||
alternatorGroup.alternatorGroup = true; | ||
openenings.push(alternatorGroup); | ||
} | ||
} | ||
break; | ||
default: | ||
defaultCase(); | ||
} | ||
} | ||
while (openenings.length > 0) { | ||
openingToken = openenings.pop(); | ||
currentToken.matches.push(openingToken); | ||
} | ||
if (currentToken.matches.length > 0) { | ||
verifyGroupMarker(currentToken); | ||
maskTokens.push(currentToken); | ||
} | ||
if (closeRegexGroup) closeGroup(); | ||
while (openenings.length > 0) { | ||
openingToken = openenings.pop(); | ||
currentToken.matches.push(openingToken); | ||
} | ||
if (currentToken.matches.length > 0) { | ||
verifyGroupMarker(currentToken); | ||
maskTokens.push(currentToken); | ||
} | ||
if (opts.numericInput || opts.isRTL) { | ||
reverseTokens(maskTokens[0]); | ||
} | ||
// console.log(JSON.stringify(maskTokens)); | ||
return maskTokens; | ||
if (opts.numericInput || opts.isRTL) { | ||
reverseTokens(maskTokens[0]); | ||
} | ||
// console.log(JSON.stringify(maskTokens)); | ||
return maskTokens; | ||
} |
@@ -72,3 +72,6 @@ export { | ||
var greedy = opts.greedy; | ||
if (clearOptionalTail) opts.greedy = false; | ||
if (clearOptionalTail && opts.greedy) { | ||
opts.greedy = false; | ||
inputmask.maskset.tests = {}; | ||
} | ||
minimalPos = minimalPos || 0; | ||
@@ -80,3 +83,3 @@ var maskTemplate = [], | ||
if (baseOnInput === true && maskset.validPositions[pos]) { | ||
testPos = (clearOptionalTail && maskset.validPositions[pos].match.optionality === true | ||
testPos = (clearOptionalTail && maskset.validPositions[pos].match.optionality | ||
&& maskset.validPositions[pos + 1] === undefined | ||
@@ -130,5 +133,9 @@ && (maskset.validPositions[pos].generatedInput === true || (maskset.validPositions[pos].input == opts.skipOptionalPartCharacter && pos > 0))) | ||
opts = this.opts; | ||
var optionalityLevel = determineOptionalityLevel(pos, tests); | ||
pos = pos > 0 ? pos - 1 : 0; | ||
var altTest = getTest.call(inputmask, pos), targetLocator = getLocator(altTest), tstLocator, closest, bestMatch; | ||
if (opts.greedy && tests.length > 1 && tests[tests.length - 1].match.def === "") | ||
tests.pop(); | ||
// console.log(" optionality = " + optionalityLevel); | ||
// console.log(" - " + JSON.stringify(tests)); | ||
for (var ndx = 0; ndx < tests.length; ndx++) { //find best matching | ||
@@ -138,6 +145,10 @@ var tst = tests[ndx]; | ||
var distance = Math.abs(tstLocator - targetLocator); | ||
if (closest === undefined | ||
|| (tstLocator !== "" && distance < closest) | ||
|| (bestMatch && !opts.greedy && bestMatch.match.optionality && bestMatch.match.newBlockMarker === "master" && (!tst.match.optionality || !tst.match.newBlockMarker)) | ||
|| (bestMatch && bestMatch.match.optionalQuantifier && !tst.match.optionalQuantifier)) { | ||
|| (bestMatch && !opts.greedy && | ||
(bestMatch.match.optionality && bestMatch.match.optionality - optionalityLevel > 0) && | ||
bestMatch.match.newBlockMarker === "master" && | ||
((!tst.match.optionality || tst.match.optionality - optionalityLevel < 1) || !tst.match.newBlockMarker)) | ||
|| (bestMatch && !opts.greedy && bestMatch.match.optionalQuantifier && !tst.match.optionalQuantifier)) { | ||
closest = distance; | ||
@@ -147,6 +158,24 @@ bestMatch = tst; | ||
} | ||
return bestMatch; | ||
} | ||
function determineOptionalityLevel(pos, tests) { | ||
let optionalityLevel = 0, differentOptionalLevels = false; | ||
tests.forEach(test => { | ||
if (test.match.optionality) { | ||
if (optionalityLevel !== 0 && optionalityLevel !== test.match.optionality) | ||
differentOptionalLevels = true; | ||
if (optionalityLevel === 0 || optionalityLevel > test.match.optionality) { | ||
optionalityLevel = test.match.optionality; | ||
} | ||
} | ||
}); | ||
if (optionalityLevel) { | ||
if (pos == 0) optionalityLevel = 0; | ||
else if (tests.length == 1) optionalityLevel = 0; | ||
else if (!differentOptionalLevels) optionalityLevel = 0; | ||
} | ||
return optionalityLevel; | ||
} | ||
//tobe put on prototype? | ||
@@ -307,3 +336,3 @@ function getTest(pos, tests) { | ||
}); | ||
if (match.optionality === true && quantifierRecurse === undefined && | ||
if (match.optionality && quantifierRecurse === undefined && | ||
((opts.definitions && opts.definitions[match.nativeDef] && opts.definitions[match.nativeDef].optional) || | ||
@@ -327,6 +356,7 @@ (Inputmask.prototype.definitions[match.nativeDef] && Inputmask.prototype.definitions[match.nativeDef].optional))) { //prevent loop see #698 | ||
if (ndx >= mtchsNdx) { | ||
mtch.match.optionality = true; | ||
mtch.match.optionality = mtch.match.optionality ? mtch.match.optionality + 1 : 1; | ||
} | ||
}); | ||
latestMatch = matches[matches.length - 1].match; | ||
if (quantifierRecurse === undefined && isFirstMatch(latestMatch, optionalToken)) { //prevent loop see #698 | ||
@@ -559,9 +589,17 @@ insertStop = true; //insert a stop | ||
} | ||
var result; | ||
if (ndxIntlzr !== undefined && maskset.tests[pos]) { //prioritize full tests for caching | ||
return $.extend(true, [], matches); | ||
result = $.extend(true, [], matches); | ||
} else { | ||
maskset.tests[pos] = $.extend(true, [], matches); //set a clone to prevent overwriting some props | ||
result = maskset.tests[pos]; | ||
} | ||
maskset.tests[pos] = $.extend(true, [], matches); //set a clone to prevent overwriting some props | ||
// console.log(pos + " - " + JSON.stringify(matches)); | ||
return maskset.tests[pos]; | ||
//cleanup optionality marking | ||
matches.forEach(t => { | ||
t.match.optionality = false; | ||
}); | ||
return result; | ||
} |
@@ -19,5 +19,5 @@ import { | ||
} from "./positioning"; | ||
import {EventHandlers} from "./eventhandlers"; | ||
import { EventHandlers } from "./eventhandlers"; | ||
export {alternate, checkAlternationMatch, isComplete, isValid, refreshFromBuffer, revalidateMask, handleRemove}; | ||
export { alternate, checkAlternationMatch, isComplete, isSelection, isValid, refreshFromBuffer, revalidateMask, handleRemove }; | ||
@@ -107,3 +107,3 @@ //tobe put on prototype? | ||
if (maskPos == true && isValidRslt) { //return validposition on generalise | ||
returnRslt = {caretPos: i}; | ||
returnRslt = { caretPos: i }; | ||
} | ||
@@ -245,3 +245,3 @@ } | ||
end: maskset.p | ||
}, false).begin; | ||
}, false, opts.insertMode === false && k === keyCode.BACKSPACE ? "none" : undefined).begin; | ||
} | ||
@@ -274,2 +274,8 @@ } | ||
function isSelection(posObj) { | ||
const inputmask = this, | ||
opts = this.opts, insertModeOffset = opts.insertMode ? 0 : 1; | ||
return inputmask.isRTL ? (posObj.begin - posObj.end) > insertModeOffset : (posObj.end - posObj.begin) > insertModeOffset; | ||
} | ||
//tobe put on prototype? | ||
@@ -282,7 +288,2 @@ function isValid(pos, c, strict, fromIsValid, fromAlternate, validateOnly, fromCheckval) { //strict true ~ no correction or autofill | ||
function isSelection(posObj) { | ||
return inputmask.isRTL ? (posObj.begin - posObj.end) > 1 || ((posObj.begin - posObj.end) === 1) : | ||
(posObj.end - posObj.begin) > 1 || ((posObj.end - posObj.begin) === 1); | ||
} | ||
strict = strict === true; //always set a value to strict to prevent possible strange behavior in the extensions | ||
@@ -302,3 +303,3 @@ | ||
}).forEach(function (lmnt) { | ||
revalidateMask.call(inputmask, {begin: lmnt, end: lmnt + 1}); | ||
revalidateMask.call(inputmask, { begin: lmnt, end: lmnt + 1 }); | ||
}); | ||
@@ -346,3 +347,3 @@ commandObj.remove = undefined; | ||
rslt = test.fn != null ? | ||
test.fn.test(c, maskset, position, strict, opts, isSelection(pos)) : (c === test.def || c === opts.skipOptionalPartCharacter) && test.def !== "" ? //non mask | ||
test.fn.test(c, maskset, position, strict, opts, isSelection.call(inputmask, pos)) : (c === test.def || c === opts.skipOptionalPartCharacter) && test.def !== "" ? //non mask | ||
{ | ||
@@ -394,3 +395,3 @@ c: getPlaceholder.call(inputmask, position, test, true) || test.def, | ||
if (typeof opts.preValidation === "function" && fromIsValid !== true && validateOnly !== true) { | ||
result = opts.preValidation.call(inputmask, getBuffer.call(inputmask), maskPos, c, isSelection(pos), opts, maskset, pos, strict || fromAlternate); | ||
result = opts.preValidation.call(inputmask, getBuffer.call(inputmask), maskPos, c, isSelection.call(inputmask, pos), opts, maskset, pos, strict || fromAlternate); | ||
result = processCommandObject(result); | ||
@@ -438,3 +439,3 @@ } | ||
result = alternate.call(inputmask, maskPos, c, strict, fromIsValid, undefined, pos); | ||
} else if (isSelection(pos) && maskset.tests[maskPos] && maskset.tests[maskPos].length > 1 && opts.keepStatic && !strict && fromAlternate !== true) { //selection clears an alternated keepstatic mask ~ #2189 | ||
} else if (isSelection.call(inputmask, pos) && maskset.tests[maskPos] && maskset.tests[maskPos].length > 1 && opts.keepStatic && !strict && fromAlternate !== true) { //selection clears an alternated keepstatic mask ~ #2189 | ||
result = alternate.call(inputmask, true); | ||
@@ -521,3 +522,3 @@ } | ||
end = buffer.length; | ||
p = determineNewCaretPosition.call(inputmask, {begin: 0, end: 0}, false).begin; | ||
p = determineNewCaretPosition.call(inputmask, { begin: 0, end: 0 }, false).begin; | ||
} else { | ||
@@ -608,3 +609,3 @@ for (i = start; i < end; i++) { | ||
validatedPos = validatedPos !== undefined ? validatedPos : begin; | ||
if (begin !== end || (opts.insertMode && maskset.validPositions[validatedPos] !== undefined && fromIsValid === undefined) || validTest === undefined || validTest.match.optionalQuantifier|| validTest.match.optionality) { | ||
if (begin !== end || (opts.insertMode && maskset.validPositions[validatedPos] !== undefined && fromIsValid === undefined) || validTest === undefined || validTest.match.optionalQuantifier || validTest.match.optionality) { | ||
//reposition & revalidate others | ||
@@ -622,3 +623,3 @@ var positionsClone = $.extend(true, {}, maskset.validPositions), | ||
var j = validatedPos, | ||
posMatch = j, t, canMatch; | ||
posMatch = j, t, canMatch, test; | ||
@@ -637,3 +638,3 @@ if (validTest) { | ||
})))) { | ||
while (getTest.call(inputmask, posMatch).match.def !== "") { //loop needed to match further positions | ||
while (test = getTest.call(inputmask, posMatch), test.match.def !== "") { //loop needed to match further positions | ||
if ((canMatch = positionCanMatchDefinition.call(inputmask, posMatch, t, opts)) !== false || t.match.def === "+") { //validated match //we still need some hackery for the + validator (numeric alias) | ||
@@ -652,3 +653,3 @@ if (t.match.def === "+") getBuffer.call(inputmask, true); | ||
} | ||
if (!valid && posMatch > maskset.maskLength) { | ||
if (!valid && getBuffer.call(inputmask), posMatch > maskset.maskLength) { | ||
break; | ||
@@ -655,0 +656,0 @@ } |
{ | ||
"name": "inputmask", | ||
"version": "5.0.7-beta.29", | ||
"version": "5.0.7", | ||
"description": "Inputmask is a javascript library which creates an input mask. Inputmask can run against vanilla javascript, jQuery and jqlite.", | ||
@@ -39,9 +39,9 @@ "main": "dist/inputmask.js", | ||
"devDependencies": { | ||
"@babel/core": "^7.15.0", | ||
"@babel/plugin-transform-modules-commonjs": "^7.15.0", | ||
"@babel/preset-env": "^7.15.0", | ||
"@babel/preset-typescript": "7.15.0", | ||
"@babel/core": "^7.16.5", | ||
"@babel/plugin-transform-modules-commonjs": "^7.16.5", | ||
"@babel/preset-env": "^7.16.5", | ||
"@babel/preset-typescript": "^7.16.5", | ||
"@robinherbots/grunt-available-tasks": "^0.6.4", | ||
"@robinherbots/grunt-nuget": "^0.3.2", | ||
"babel-loader": "^8.2.2", | ||
"babel-loader": "^8.2.3", | ||
"grunt": "^1.4.1", | ||
@@ -51,12 +51,12 @@ "grunt-bump": "^0.8.0", | ||
"grunt-contrib-copy": "^1.0.0", | ||
"grunt-eslint": "^23.0.0", | ||
"grunt-eslint": "^24.0.0", | ||
"grunt-release": "^0.14.0", | ||
"grunt-webpack": "^4.0.3", | ||
"grunt-webpack": "^5.0.0", | ||
"jquery": "^3.6.0", | ||
"load-grunt-tasks": "^5.1.0", | ||
"lodash": "^4.17.21", | ||
"qunit": "^2.16.0", | ||
"webpack": "^5.51.1", | ||
"webpack-cli": "^4.8.0" | ||
"qunit": "^2.17.2", | ||
"webpack": "^5.65.0", | ||
"webpack-cli": "^4.9.1" | ||
} | ||
} |
@@ -10,3 +10,3 @@ # Inputmask | ||
[![NPM Version][npm-image]][npm-url] [![Dependency Status][david-image]][david-url] [![devDependency Status][david-dev-image]][david-dev-url] | ||
![npm](https://img.shields.io/npm/v/inputmask) ![npm (tag)](https://img.shields.io/npm/v/inputmask/next) ![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/npm/inputmask) | ||
@@ -207,3 +207,3 @@ Inputmask is a javascript library that creates an input mask. Inputmask can run against vanilla javascript, jQuery, and jqlite. | ||
### Optional masks | ||
It is possible to define some parts in the mask is optional. This is done by using [ ]. | ||
It is possible to define some parts in the mask as optional. This is done by using [ ]. | ||
@@ -302,3 +302,4 @@ Example: | ||
"(aaa)|(999)" => aaa or 999 | ||
"(aaa|999|9AA)" => aaa or 999 or 9AA | ||
"(aaa|999|9AA)" => aaa or 999 or 9AA | ||
"aaaa|9999" => aaa a or 9 999 | ||
@@ -1017,3 +1018,7 @@ **Also make sure to read about the [keepStatic](#keepStatic) option.** | ||
**When the option is not set, it will default to false, except for multiple masks it will default to true!!** | ||
**When the option is not set, it will default to false.** | ||
**Except:** | ||
- for multiple masks it will default to true | ||
- when the first alternation is shorter then the next it will also default to true. | ||
- ex: (9|999), (99)|(aaaa) | ||
@@ -1278,9 +1283,2 @@ ### positionCaretOnTab | ||
[npm-url]: https://npmjs.org/package/inputmask | ||
[npm-image]: https://img.shields.io/npm/v/inputmask.svg | ||
[david-url]: https://david-dm.org/RobinHerbots/inputmask#info=dependencies | ||
[david-image]: https://img.shields.io/david/RobinHerbots/inputmask.svg | ||
[david-dev-url]: https://david-dm.org/RobinHerbots/inputmask#info=devDependencies | ||
[david-dev-image]: https://img.shields.io/david/dev/RobinHerbots/inputmask.svg | ||
[input-type-ref]: https://html.spec.whatwg.org/multipage/forms.html#do-not-apply |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
849387
11200
2
1280