From 5d6f757002bc1272dc0711d1c3110c3a64d08d72 Mon Sep 17 00:00:00 2001 From: Joris Vercammen Date: Thu, 10 Aug 2017 12:09:00 +0200 Subject: [PATCH 1/2] Add travis.yml file --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..d1e7e1316 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +before_script: + - npm install -g gulp-cli +script: gulp validate From 349ed9a89c3744b91fd4d42de27c4271a57276d2 Mon Sep 17 00:00:00 2001 From: Joris Vercammen Date: Thu, 10 Aug 2017 12:48:02 +0200 Subject: [PATCH 2/2] Add new travis.yml file to automate tests Also fixes some of the test failures. --- .travis.yml | 14 +++++++++-- js/inputmask.extensions.js | 2 +- js/inputmask.js | 10 ++++---- js/inputmask.numeric.extensions.js | 38 ++++++++++++++++++++---------- js/inputmask.phone.extensions.js | 8 ++++--- js/inputmask.regex.extensions.js | 2 +- js/jquery.inputmask.js | 4 +++- webpack.config.js | 2 +- 8 files changed, 54 insertions(+), 26 deletions(-) diff --git a/.travis.yml b/.travis.yml index d1e7e1316..b9527433e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,14 @@ language: node_js +node_js: "7" + +# Before running the script, make sure that grunt is installed. before_script: - - npm install -g gulp-cli -script: gulp validate + - npm install -g grunt-cli + +# Run gulp validate to run all the tests. +script: grunt validate + +# Cache the node modules directory. +cache: + directories: + - "node_modules" diff --git a/js/inputmask.extensions.js b/js/inputmask.extensions.js index 804f424a8..07725fe11 100644 --- a/js/inputmask.extensions.js +++ b/js/inputmask.extensions.js @@ -104,7 +104,7 @@ "vin": { mask: "V{13}9{4}", definitions: { - 'V': { + "V": { validator: "[A-HJ-NPR-Za-hj-npr-z\\d]", cardinality: 1, casing: "upper" diff --git a/js/inputmask.js b/js/inputmask.js index f604631e5..f8a41381f 100644 --- a/js/inputmask.js +++ b/js/inputmask.js @@ -238,17 +238,19 @@ }); return elems && elems[0] ? (elems[0].inputmask || this) : this; }, - option: function (options, noremask) { //set extra options || retrieve value of a current option + option: function (options, noremask) { + // Set extra options || retrieve value of a current option. if (typeof options === "string") { return this.opts[options]; } else if (typeof options === "object") { $.extend(this.userOptions, options); //user passed options - //remask + // Remask. if (this.el && noremask !== true) { this.mask(this.el); } return this; } + return this; }, unmaskedvalue: function (value) { this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache); @@ -1137,7 +1139,7 @@ break; } else if (staticCanMatchDefinition(altMatch, altMatch2) || isSubsetOf(altMatch, altMatch2)) { // console.log("case 5"); - if (altMatch.alternation == altMatch2.alternation && + if (altMatch.alternation === altMatch2.alternation && altMatch.locator[altMatch.alternation].toString().indexOf(altMatch2.locator[altMatch2.alternation].toString().split("")[0]) === -1) { //no alternation marker @@ -1736,7 +1738,7 @@ if (getMaskSet().validPositions[pndx]) break; } ////fill missing nonmask and valid placeholders - var testTemplate, testsFromPos; + var testTemplate, testsFromPos, result; for (pndx++; pndx < maskPos; pndx++) { if (getMaskSet().validPositions[pndx] === undefined && (opts.jitMasking === false || opts.jitMasking > pndx)) { testsFromPos = getTests(pndx, getTestTemplate(pndx - 1).locator, pndx - 1).slice(); diff --git a/js/inputmask.numeric.extensions.js b/js/inputmask.numeric.extensions.js index 7abc101c1..c21982356 100644 --- a/js/inputmask.numeric.extensions.js +++ b/js/inputmask.numeric.extensions.js @@ -28,9 +28,12 @@ opts.quantifiermarker.end === txt.charAt(i) || opts.groupmarker.start === txt.charAt(i) || opts.groupmarker.end === txt.charAt(i) || - opts.alternatormarker === txt.charAt(i)) + opts.alternatormarker === txt.charAt(i)) { escapedTxt += "\\" + txt.charAt(i) - else escapedTxt += txt.charAt(i); + } + else { + escapedTxt += txt.charAt(i); + } } return escapedTxt; } @@ -137,7 +140,7 @@ unmaskAsNumber: false, inputmode: "numeric", preValidation: function (buffer, pos, c, isSelection, opts) { - if (c === "-" || c == opts.negationSymbol.front) { + if (c === "-" || c === opts.negationSymbol.front) { if (opts.allowMinus !== true) return false; opts.isNegative = opts.isNegative === undefined ? true : !opts.isNegative; if (buffer.join("") === "") return true; @@ -172,9 +175,9 @@ var suffix = opts.suffix.split(""), prefix = opts.prefix.split(""); - if (currentResult.pos == undefined && currentResult.caret !== undefined && currentResult.dopost !== true) return currentResult; + if (currentResult.pos === undefined && currentResult.caret !== undefined && currentResult.dopost !== true) return currentResult; - var caretPos = currentResult.caret != undefined ? currentResult.caret : currentResult.pos; + var caretPos = currentResult.caret !== undefined ? currentResult.caret : currentResult.pos; var maskedValue = buffer.slice(); if (opts.numericInput) { caretPos = maskedValue.length - caretPos - 1; @@ -188,7 +191,9 @@ } - if (caretPos == maskedValue.length - opts.suffix.length - 1 && charAtPos === opts.radixPoint) return currentResult; + if (caretPos === maskedValue.length - opts.suffix.length - 1 && charAtPos === opts.radixPoint) { + return currentResult; + } if (charAtPos !== undefined) { if (charAtPos !== opts.radixPoint && @@ -279,9 +284,12 @@ if (charAtPos !== undefined) { if (charAtPos !== opts.radixPoint && charAtPos !== opts.negationSymbol.front && charAtPos !== opts.negationSymbol.back) { caretPos = $.inArray("?", processValue); - if (caretPos > -1) + if (caretPos > -1) { processValue[caretPos] = charAtPos; - else caretPos = currentResult.caret || 0; + } + else { + caretPos = currentResult.caret || 0; + } } else if (charAtPos === opts.radixPoint || charAtPos === opts.negationSymbol.front || charAtPos === opts.negationSymbol.back) { @@ -395,11 +403,13 @@ processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), ""); //filter 0 after radixpoint var pvRadixSplit = processValue.split(opts.radixPoint); - if (pvRadixSplit.length > 1) + if (pvRadixSplit.length > 1) { pvRadixSplit[1] = pvRadixSplit[1].replace(/0/g, opts.placeholder.charAt(0)); + } //filter 0 before radixpoint - if (pvRadixSplit[0] === "0") + if (pvRadixSplit[0] === "0") { pvRadixSplit[0] = pvRadixSplit[0].replace(/0/g, opts.placeholder.charAt(0)); + } processValue = pvRadixSplit[0] + opts.radixPoint + pvRadixSplit[1] || ""; var bufferTemplate = maskset._buffer.join(""); //getBuffer().slice(lvp).join(''); if (processValue === opts.radixPoint) { @@ -472,8 +482,9 @@ var processValue = maskedValue.replace(opts.prefix, ""); processValue = processValue.replace(opts.suffix, ""); processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), ""); - if (opts.placeholder.charAt(0) !== "") + 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(Inputmask.escapeRegex.call(this, opts.radixPoint), "."); processValue = processValue.replace(new RegExp("^" + Inputmask.escapeRegex(opts.negationSymbol.front)), "-"); @@ -507,8 +518,9 @@ if (opts.radixPoint !== "" && isFinite(initialValue)) { var vs = initialValue.split("."), groupSize = opts.groupSeparator !== "" ? parseInt(opts.groupSize) : 0; - if (vs.length === 2 && (vs[0].length > groupSize || vs[1].length > groupSize || (vs[0].length <= groupSize && vs[1].length < groupSize))) + if (vs.length === 2 && (vs[0].length > groupSize || vs[1].length > groupSize || (vs[0].length <= groupSize && vs[1].length < groupSize))) { initialValue = initialValue.replace(".", opts.radixPoint); + } } var kommaMatches = initialValue.match(/,/g); var dotMatches = initialValue.match(/\./g); @@ -564,7 +576,7 @@ vp.input === opts.negationSymbol.front || vp.input === opts.negationSymbol.back; - if (canClear && (vp.match.nativeDef == "+" || vp.match.nativeDef == "-")) { + if (canClear && (vp.match.nativeDef === "+" || vp.match.nativeDef === "-")) { opts.isNegative = false; } diff --git a/js/inputmask.phone.extensions.js b/js/inputmask.phone.extensions.js index f612d1c41..274819434 100644 --- a/js/inputmask.phone.extensions.js +++ b/js/inputmask.phone.extensions.js @@ -35,8 +35,9 @@ function reduceVariations(masks, previousVariation, previousmaskGroup) { previousVariation = previousVariation || ""; previousmaskGroup = previousmaskGroup || maskGroups; - if (previousVariation !== "") + if (previousVariation !== "") { previousmaskGroup[previousVariation] = {}; + } var variation = "", maskGroup = previousmaskGroup[previousVariation] || previousmaskGroup; for (var i = masks.length - 1; i >= 0; i--) { mask = masks[i].mask || masks[i]; @@ -56,10 +57,11 @@ var mask = "", submasks = []; for (var ndx in maskGroup) { if ($.isArray(maskGroup[ndx])) { - if (maskGroup[ndx].length === 1) + if (maskGroup[ndx].length === 1) { submasks.push(ndx + maskGroup[ndx]); - else + } else { submasks.push(ndx + opts.groupmarker.start + maskGroup[ndx].join(opts.groupmarker.end + opts.alternatormarker + opts.groupmarker.start) + opts.groupmarker.end); + } } else { submasks.push(ndx + rebuild(maskGroup[ndx])); } diff --git a/js/inputmask.regex.extensions.js b/js/inputmask.regex.extensions.js index b0d3f51ea..53dbf829b 100644 --- a/js/inputmask.regex.extensions.js +++ b/js/inputmask.regex.extensions.js @@ -159,7 +159,7 @@ } } else { var testExp; - if (matchToken.charAt(0) == "[") { + if (matchToken.charAt(0) === "[") { testExp = regexPart; testExp += matchToken; for (var j = 0; j < openGroupCount; j++) { diff --git a/js/jquery.inputmask.js b/js/jquery.inputmask.js index a775e0bbe..241bc999d 100644 --- a/js/jquery.inputmask.js +++ b/js/jquery.inputmask.js @@ -69,7 +69,9 @@ return this.each(function () { if (this.inputmask !== undefined) { return this.inputmask.option(fn); - } else nptmask.mask(this); + } else { + return nptmask.mask(this); + } }); } else { return this.each(function () { diff --git a/webpack.config.js b/webpack.config.js index c444b7136..4eccd2f71 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; let webpack = require('webpack'); let path = require('path');