diff --git a/CHANGELOG.md b/CHANGELOG.md index a0462f4..7da2d1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +2.0.1 +===== + +- The npm module now includes built files under `dist/`. + 2.0.0 ===== diff --git a/dist/card-validator.js b/dist/card-validator.js index 5075687..86318dd 100644 --- a/dist/card-validator.js +++ b/dist/card-validator.js @@ -2102,7 +2102,7 @@ function isEmptyObject(object) { } function cardNumber(value) { - var cardType, valid; + var cardType, valid, i, maxLength; if (isNumber(value)) { value = String(value); @@ -2116,32 +2116,28 @@ function cardNumber(value) { if (!/^\d*$/.test(value)) { return verification(null, false, false); } - // TODO: Just letting these go here as validPartials - // The optimal solution would be to have a separate - // set of regexes for partial validations + cardType = getCardType(value); + if (isEmptyObject(cardType)) { return verification(null, false, false); } - // Discover cannot be determined until we have 4 digits - if (value.length <= 3 && value[0] === '6') { - return verification(null, true, false); + if (cardType.type === 'unionpay') { // UnionPay is not Luhn 10 compliant + valid = true; + } else { + valid = luhn10(value); } - // Non-discover cards - if (value.length <= 1 && /^(5|4|3)/.test(value)) { return verification(null, true, false); } + for (i = 0; i < cardType.lengths.length; i++) { + if (cardType.lengths[i] === value.length) { + return verification(cardType, valid, valid); + } + } - cardType = getCardType(value); - if (isEmptyObject(cardType)) { return verification(null, false, false); } + maxLength = Math.max.apply(null, cardType.lengths); - // Recognized as card but not long enough yet: validPartial - if (value.length < cardType.length) { + if (value.length < maxLength) { return verification(cardType, true, false); } - if (value.length > cardType.length) { - return verification(cardType, false, false); - } - - valid = luhn10(value); - return verification(cardType, valid, valid); + return verification(cardType, false, false); } module.exports = cardNumber; diff --git a/dist/card-validator.min.js b/dist/card-validator.min.js index efe3438..e0867be 100644 --- a/dist/card-validator.min.js +++ b/dist/card-validator.min.js @@ -1 +1 @@ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.cardValidator=e()}}(function(){return function e(n,t,r){function o(s,i){if(!t[s]){if(!n[s]){var u="function"==typeof require&&require;if(!i&&u)return u(s,!0);if(a)return a(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var l=t[s]={exports:{}};n[s][0].call(l.exports,function(e){var t=n[s][1][e];return o(t?t:e)},l,l.exports,e,n,t,r)}return t[s].exports}for(var a="function"==typeof require&&require,s=0;s-1&&e%1==0&&v>=e}function s(e){return null==e?!1:y.call(e)==c?g.test(h.call(e)):o(e)&&f.test(e)}function i(e){return e=r(e),e&&d.test(e)?e.replace(l,"\\$&"):e}var u="[object Array]",c="[object Function]",l=/[.*+?^${}()|[\]\/\\]/g,d=RegExp(l.source),f=/^\[object .+?Constructor\]$/,p=Object.prototype,h=Function.prototype.toString,y=p.toString,g=RegExp("^"+i(y).replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),b=s(b=Array.isArray)&&b,v=Math.pow(2,53)-1,m=b||function(e){return o(e)&&a(e.length)&&y.call(e)==u};n.exports=m},{}],11:[function(e,n,t){function r(e){return"string"==typeof e?e:null==e?"":e+""}function o(e){return!!e&&"object"==typeof e}function a(e){return null==e?!1:p.call(e)==i?h.test(f.call(e)):o(e)&&l.test(e)}function s(e){return e=r(e),e&&c.test(e)?e.replace(u,"\\$&"):e}var i="[object Function]",u=/[.*+?^${}()|[\]\/\\]/g,c=RegExp(u.source),l=/^\[object .+?Constructor\]$/,d=Object.prototype,f=Function.prototype.toString,p=d.toString,h=RegExp("^"+s(p).replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");n.exports=a},{}],12:[function(e,n,t){function r(e){return function(n){return null==n?void 0:n[e]}}function o(e){return null!=e&&s(m(e))}function a(e,n){return e=+e,n=null==n?b:n,e>-1&&e%1==0&&n>e}function s(e){return"number"==typeof e&&e>-1&&e%1==0&&b>=e}function i(e){for(var n=c(e),t=n.length,r=t&&e.length,o=r&&s(r)&&(d(e)||v.nonEnumArgs&&l(e)),i=-1,u=[];++i0;++r-1&&e%1==0&&d>=e}function i(e){return r(e)&&a(e)&&l.call(e)==u}var u="[object Arguments]",c=Object.prototype,l=c.toString,d=Math.pow(2,53)-1,f=o("length");n.exports=i},{}],14:[function(e,n,t){function r(e,n,t){if("function"!=typeof e)return o;if(void 0===n)return e;switch(t){case 1:return function(t){return e.call(n,t)};case 3:return function(t,r,o){return e.call(n,t,r,o)};case 4:return function(t,r,o,a){return e.call(n,t,r,o,a)};case 5:return function(t,r,o,a,s){return e.call(n,t,r,o,a,s)}}return function(){return e.apply(n,arguments)}}function o(e){return e}n.exports=r},{}],15:[function(e,n,t){function r(e,n,t){var r=l(n);p.apply(r,h(n));for(var o=-1,a=r.length;++o2&&t[s-2],u=s>2&&t[2],c=s>1&&t[s-1];for("function"==typeof i?(i=o(i,c,5),s-=2):(i="function"==typeof c?c:null,s-=i?1:0),u&&a(t[0],t[1],u)&&(i=3>s?null:i,s=1);++r-1&&e%1==0&&n>e}function s(e,n,t){if(!u(t))return!1;var r=typeof n;if("number"==r?o(t)&&a(n,t.length):"string"==r&&n in t){var s=t[n];return e===e?e===s:s!==s}return!1}function i(e){return"number"==typeof e&&e>-1&&e%1==0&&c>=e}function u(e){var n=typeof e;return"function"==n||!!e&&"object"==n}var c=Math.pow(2,53)-1,l=r("length");n.exports=s},{}],21:[function(e,n,t){function r(e,n){if("function"!=typeof e)throw new TypeError(o);return n=a(void 0===n?e.length-1:+n||0,0),function(){for(var t=arguments,r=-1,o=a(t.length-n,0),s=Array(o);++rn.length?r(n,!1,!1):(t=u(e),r(n,t,t))):r(null,!1,!1)):r(null,!1,!1)}var s=e("lodash.isstring"),i=e("lodash.assign"),u=e("./luhn-10"),c=e("credit-card-type"),l=e("lodash.isnumber");n.exports=a},{"./luhn-10":33,"credit-card-type":2,"lodash.assign":15,"lodash.isnumber":26,"lodash.isstring":27}],29:[function(e,n,t){function r(e,n){return{isValid:e,isPotentiallyValid:n}}function o(e,n){return n=n||s,a(e)&&/^\d*$/.test(e)?e.length===n?r(!0,!0):e.lengthn?r(!1,!1):r(!0,!0):r(!1,!1)}var a=e("lodash.isstring"),s=3;n.exports=o},{"lodash.isstring":27}],30:[function(e,n,t){function r(e,n,t,r){return{isValid:e,isPotentiallyValid:n,month:t,year:r}}function o(e){var n,t,o;return u(e)?(e=e.replace(/^(\d\d) (\d\d(\d\d)?)$/,"$1/$2"),n=a(e),t=s(n.month),o=i(n.year),t.isValid&&o.isValid?r(!0,!0,n.month,n.year):t.isPotentiallyValid&&o.isPotentiallyValid?r(!1,!0,null,null):r(!1,!1,null,null)):r(!1,!1,null,null)}var a=e("./parse-date"),s=e("./expiration-month"),i=e("./expiration-year"),u=e("lodash.isstring");n.exports=o},{"./expiration-month":31,"./expiration-year":32,"./parse-date":34,"lodash.isstring":27}],31:[function(e,n,t){function r(e,n){return{isValid:e,isPotentiallyValid:n}}function o(e){var n,t;return a(e)?""===e.replace(/\s/g,"")||"0"===e?r(!1,!0):/^\d*$/.test(e)?(n=parseInt(e,10),isNaN(e)?r(!1,!1):(t=n>0&&13>n,r(t,t))):r(!1,!1):r(!1,!1)}var a=e("lodash.isstring");n.exports=o},{"lodash.isstring":27}],32:[function(e,n,t){function r(e,n){return{isValid:e,isPotentiallyValid:n}}function o(e){var n,t,o,i,u,c;return a(e)?""===e.replace(/\s/g,"")?r(!1,!0):/^\d*$/.test(e)?(i=e.length,2>i?r(!1,!0):(t=(new Date).getFullYear(),3===i?(o=e.slice(0,2),n=String(t).slice(0,2),r(!1,o===n)):i>4?r(!1,!1):(e=parseInt(e,10),u=Number(String(t).substr(2,2)),2===i?c=e>=u&&u+s>=e:4===i&&(c=e>=t&&t+s>=e),r(c,c)))):r(!1,!1):r(!1,!1)}var a=e("lodash.isstring"),s=19;n.exports=o},{"lodash.isstring":27}],33:[function(e,n,t){n.exports=function(e,n,t,r,o){for(r=+e[n=e.length-1],o=0;n--;)t=+e[n],r+=++o%2?2*t%10+(t>4):t;return!(r%10)}},{}],34:[function(e,n,t){function r(e){var n,t;return e.match("/")?(e=e.split(/\s*\/\s*/g),{month:e[0],year:e.slice(1).join()}):(t="0"===e[0]||e.length>5||4===e.length||3===e.length?2:1,n=e.substr(0,t),{month:n,year:e.substr(n.length,4)})}n.exports=r},{}],35:[function(e,n,t){function r(e,n){return{isValid:e,isPotentiallyValid:n}}function o(e){return a(e)?e.length<4?r(!1,!0):r(!0,!0):r(!1,!1)}var a=e("lodash.isstring");n.exports=o},{"lodash.isstring":27}]},{},[1])(1)}); \ No newline at end of file +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.cardValidator=e()}}(function(){return function e(n,t,r){function o(i,s){if(!t[i]){if(!n[i]){var u="function"==typeof require&&require;if(!s&&u)return u(i,!0);if(a)return a(i,!0);var c=new Error("Cannot find module '"+i+"'");throw c.code="MODULE_NOT_FOUND",c}var l=t[i]={exports:{}};n[i][0].call(l.exports,function(e){var t=n[i][1][e];return o(t?t:e)},l,l.exports,e,n,t,r)}return t[i].exports}for(var a="function"==typeof require&&require,i=0;i-1&&e%1==0&&v>=e}function i(e){return null==e?!1:y.call(e)==c?g.test(h.call(e)):o(e)&&f.test(e)}function s(e){return e=r(e),e&&d.test(e)?e.replace(l,"\\$&"):e}var u="[object Array]",c="[object Function]",l=/[.*+?^${}()|[\]\/\\]/g,d=RegExp(l.source),f=/^\[object .+?Constructor\]$/,p=Object.prototype,h=Function.prototype.toString,y=p.toString,g=RegExp("^"+s(y).replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),b=i(b=Array.isArray)&&b,v=Math.pow(2,53)-1,m=b||function(e){return o(e)&&a(e.length)&&y.call(e)==u};n.exports=m},{}],11:[function(e,n,t){function r(e){return"string"==typeof e?e:null==e?"":e+""}function o(e){return!!e&&"object"==typeof e}function a(e){return null==e?!1:p.call(e)==s?h.test(f.call(e)):o(e)&&l.test(e)}function i(e){return e=r(e),e&&c.test(e)?e.replace(u,"\\$&"):e}var s="[object Function]",u=/[.*+?^${}()|[\]\/\\]/g,c=RegExp(u.source),l=/^\[object .+?Constructor\]$/,d=Object.prototype,f=Function.prototype.toString,p=d.toString,h=RegExp("^"+i(p).replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");n.exports=a},{}],12:[function(e,n,t){function r(e){return function(n){return null==n?void 0:n[e]}}function o(e){return null!=e&&i(m(e))}function a(e,n){return e=+e,n=null==n?b:n,e>-1&&e%1==0&&n>e}function i(e){return"number"==typeof e&&e>-1&&e%1==0&&b>=e}function s(e){for(var n=c(e),t=n.length,r=t&&e.length,o=r&&i(r)&&(d(e)||v.nonEnumArgs&&l(e)),s=-1,u=[];++s0;++r-1&&e%1==0&&d>=e}function s(e){return r(e)&&a(e)&&l.call(e)==u}var u="[object Arguments]",c=Object.prototype,l=c.toString,d=Math.pow(2,53)-1,f=o("length");n.exports=s},{}],14:[function(e,n,t){function r(e,n,t){if("function"!=typeof e)return o;if(void 0===n)return e;switch(t){case 1:return function(t){return e.call(n,t)};case 3:return function(t,r,o){return e.call(n,t,r,o)};case 4:return function(t,r,o,a){return e.call(n,t,r,o,a)};case 5:return function(t,r,o,a,i){return e.call(n,t,r,o,a,i)}}return function(){return e.apply(n,arguments)}}function o(e){return e}n.exports=r},{}],15:[function(e,n,t){function r(e,n,t){var r=l(n);p.apply(r,h(n));for(var o=-1,a=r.length;++o2&&t[i-2],u=i>2&&t[2],c=i>1&&t[i-1];for("function"==typeof s?(s=o(s,c,5),i-=2):(s="function"==typeof c?c:null,i-=s?1:0),u&&a(t[0],t[1],u)&&(s=3>i?null:s,i=1);++r-1&&e%1==0&&n>e}function i(e,n,t){if(!u(t))return!1;var r=typeof n;if("number"==r?o(t)&&a(n,t.length):"string"==r&&n in t){var i=t[n];return e===e?e===i:i!==i}return!1}function s(e){return"number"==typeof e&&e>-1&&e%1==0&&c>=e}function u(e){var n=typeof e;return"function"==n||!!e&&"object"==n}var c=Math.pow(2,53)-1,l=r("length");n.exports=i},{}],21:[function(e,n,t){function r(e,n){if("function"!=typeof e)throw new TypeError(o);return n=a(void 0===n?e.length-1:+n||0,0),function(){for(var t=arguments,r=-1,o=a(t.length-n,0),i=Array(o);++rn?r(!1,!1):r(!0,!0):r(!1,!1)}var a=e("lodash.isstring"),i=3;n.exports=o},{"lodash.isstring":27}],30:[function(e,n,t){function r(e,n,t,r){return{isValid:e,isPotentiallyValid:n,month:t,year:r}}function o(e){var n,t,o;return u(e)?(e=e.replace(/^(\d\d) (\d\d(\d\d)?)$/,"$1/$2"),n=a(e),t=i(n.month),o=s(n.year),t.isValid&&o.isValid?r(!0,!0,n.month,n.year):t.isPotentiallyValid&&o.isPotentiallyValid?r(!1,!0,null,null):r(!1,!1,null,null)):r(!1,!1,null,null)}var a=e("./parse-date"),i=e("./expiration-month"),s=e("./expiration-year"),u=e("lodash.isstring");n.exports=o},{"./expiration-month":31,"./expiration-year":32,"./parse-date":34,"lodash.isstring":27}],31:[function(e,n,t){function r(e,n){return{isValid:e,isPotentiallyValid:n}}function o(e){var n,t;return a(e)?""===e.replace(/\s/g,"")||"0"===e?r(!1,!0):/^\d*$/.test(e)?(n=parseInt(e,10),isNaN(e)?r(!1,!1):(t=n>0&&13>n,r(t,t))):r(!1,!1):r(!1,!1)}var a=e("lodash.isstring");n.exports=o},{"lodash.isstring":27}],32:[function(e,n,t){function r(e,n){return{isValid:e,isPotentiallyValid:n}}function o(e){var n,t,o,s,u,c;return a(e)?""===e.replace(/\s/g,"")?r(!1,!0):/^\d*$/.test(e)?(s=e.length,2>s?r(!1,!0):(t=(new Date).getFullYear(),3===s?(o=e.slice(0,2),n=String(t).slice(0,2),r(!1,o===n)):s>4?r(!1,!1):(e=parseInt(e,10),u=Number(String(t).substr(2,2)),2===s?c=e>=u&&u+i>=e:4===s&&(c=e>=t&&t+i>=e),r(c,c)))):r(!1,!1):r(!1,!1)}var a=e("lodash.isstring"),i=19;n.exports=o},{"lodash.isstring":27}],33:[function(e,n,t){n.exports=function(e,n,t,r,o){for(r=+e[n=e.length-1],o=0;n--;)t=+e[n],r+=++o%2?2*t%10+(t>4):t;return!(r%10)}},{}],34:[function(e,n,t){function r(e){var n,t;return e.match("/")?(e=e.split(/\s*\/\s*/g),{month:e[0],year:e.slice(1).join()}):(t="0"===e[0]||e.length>5||4===e.length||3===e.length?2:1,n=e.substr(0,t),{month:n,year:e.substr(n.length,4)})}n.exports=r},{}],35:[function(e,n,t){function r(e,n){return{isValid:e,isPotentiallyValid:n}}function o(e){return a(e)?e.length<4?r(!1,!0):r(!0,!0):r(!1,!1)}var a=e("lodash.isstring");n.exports=o},{"lodash.isstring":27}]},{},[1])(1)}); \ No newline at end of file diff --git a/package.json b/package.json index 1a3ee0b..6c4726d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "card-validator", - "version": "2.0.0", + "version": "2.0.1", "description": "A library for validating credit card fields", "main": "index.js", "repository": {