Comparing version 1.2.1 to 1.2.2
@@ -87,3 +87,3 @@ import v8n from 'v8n'; | ||
if (/^[a-zA-Z]{2,}(\s+(([a-zA-Z]{3,})|([a-zA-Z]{2,}\s+[a-zA-Z]{3,})))+$/.test(vf) && !/[bcdfghjklmnpqrstvwxyz]{3,}/.test(vf)) { | ||
if (/^[a-zA-Z]{2,}(\s+(([a-zA-Z]{3,})|([a-zA-Z]{2,}\s+[a-zA-Z]{3,})))+$/.test(vf) && !/[bcdfghjklmnpqrstvwxz]{3,}/.test(vf)) { | ||
return true; | ||
@@ -90,0 +90,0 @@ } |
@@ -5,3 +5,3 @@ /** | ||
* ---------------------------------- | ||
* v1.2.1 | ||
* v1.2.2 | ||
* | ||
@@ -107,3 +107,3 @@ * Copyright (c)2020 Bruno Foggia, 99xp. | ||
if (/^[a-zA-Z]{2,}(\s+(([a-zA-Z]{3,})|([a-zA-Z]{2,}\s+[a-zA-Z]{3,})))+$/.test(vf) && !/[bcdfghjklmnpqrstvwxyz]{3,}/.test(vf)) { | ||
if (/^[a-zA-Z]{2,}(\s+(([a-zA-Z]{3,})|([a-zA-Z]{2,}\s+[a-zA-Z]{3,})))+$/.test(vf) && !/[bcdfghjklmnpqrstvwxz]{3,}/.test(vf)) { | ||
return true; | ||
@@ -110,0 +110,0 @@ } |
@@ -5,3 +5,3 @@ /** | ||
* ---------------------------------- | ||
* v1.2.1 | ||
* v1.2.2 | ||
* | ||
@@ -13,3 +13,3 @@ * Copyright (c)2020 Bruno Foggia, 99xp. | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("v8n"),require("underscore-99xp")):"function"==typeof define&&define.amd?define(["exports","v8n","underscore-99xp"],t):t((e=e||self).v8nx={},e.v8n,e._)}(this,function(e,t,r){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t,r=r&&r.hasOwnProperty("default")?r.default:r,t.extend({regex:(e,t)=>r.partial(function(e,t,n){if(r.isArray(t)){var a=t[0],s=t[1];n=n.replace(a,s)}return(()=>!!n&&(n=n.toString(),!!e.test(n)))()},e,t)}),t.extend({email:e=>e=>{return function(e){return!(!e||"string"!=typeof e||!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/.test(e))}(e)}}),t.extend({stringAlpha:e=>e=>{return function(e){return!(!e||"string"!=typeof e||!/[a-zA-Z]+/.test(e)||!/[0-9]+/.test(e)||/[^a-zA-Z0-9]+/.test(e))}(e)}}),t.extend({fullname:e=>e=>{return function(e){if(!e||"string"!=typeof e)return!1;var t=e.normalize("NFD").replace(/[\u0300-\u036f]/g,"");return!(!/^[a-zA-Z]{2,}(\s+(([a-zA-Z]{3,})|([a-zA-Z]{2,}\s+[a-zA-Z]{3,})))+$/.test(t)||/[bcdfghjklmnpqrstvwxyz]{3,}/.test(t))}(e)}}),t.extend({passwordMatch:e=>(e,t)=>{return function(e){if("object"!=typeof e||void 0===e[0])return!0;var[t,r,n]=e,a=n.split("_");return a.pop(),a=a.join("_"),!!(t&&r&&a in r)&&t+""==r[a]+""}(e)}});var n=function(e){const t=e=>(e=>t=>e.findIndex(e=>t===e)>=0)((e=>Array.from({length:e},(e,t)=>t))(10).map(r(11)))(e),r=e=>t=>`${t}`.repeat(e),n=e=>t=>a((e=>e%11)(((e,t)=>e.reduce((e=>(t,r,n)=>t+r*e--)(t),0))(t,e))),a=e=>e>1?11-e:0;return(e=>11===e.length&&(e=>!e)(t(e))&&(e=>{const t=(e=>e.substr(0,9).split(""))(e),r=n(10)(t),a=n(11)(t.concat(r));return(e=>t=>t===e)((e=>`${e[9]}${e[10]}`)(e))(((e,t)=>`${e}${t}`)(r,a))})(e))(e.replace(/(\.|\-)/g,""))};t.extend({cpf:e=>e=>n(e.replace(/(\.|\-)/g,""))});var a=function(e){const t=e=>(e=>t=>e.findIndex(e=>t===e)>=0)((e=>Array.from({length:e},(e,t)=>t))(10).map(r(14)))(e),r=e=>t=>`${t}`.repeat(e);return(e=>14===e.length&&(e=>!e)(t(e))&&(e=>{if(!e||(e=>e%14)(e.length)>0)return!1;var t,r,n,a,s,u;for(t=e.length-2,r=e.substring(0,t),n=e.substring(t),a=0,s=t-7,u=t;u>=1;u--)a+=r.charAt(t-u)*s--,s<2&&(s=9);if((a%11<2?0:11-a%11)+""!=n.charAt(0)+"")return!1;for(t+=1,r=e.substring(0,t),a=0,s=t-7,u=t;u>=1;u--)a+=r.charAt(t-u)*s--,s<2&&(s=9);return(a%11<2?0:11-a%11)+""==n.charAt(1)+""})(e))(e.replace(/(\.|\-|\/)/g,""))};t.extend({cnpj:e=>e=>a(e.replace(/(\.|\-|\/)/g,""))}),t.extend({cpfcnpj:e=>e=>{var t=e.replace(/(\.|\-|\/)/g,"");return 11===t.length?n(t):a(t)}}),t.extend({creditcard:e=>e=>{const t=e=>{const t=e.toString().split("").map(e=>parseInt(e));(e=>13===e.length||15===e.length||16===e.length)(t);const r=(e=>{const t=e.filter((e,t)=>t%2==1),r=e.filter((e,t)=>t%2==0);let n,a;return e.length%2==1?(n=t.map(e=>2*e),a=r):(n=r.map(e=>2*e),a=t),{arr1:n,arr2:a}})(t);return((e=>e.join("").split("").map(e=>parseInt(e)))(r.arr1).reduce((e,t)=>e+t)+r.arr2.reduce((e,t)=>e+t))%10==0};return(e=>t(e))(e.replace(/[^0-9]/g,""))}}),t.extend({creditcardValidTo:e=>e=>{return(e=>(e=>{if(!/^\d{2}\/\d{4}$/.test(e))return!1;var[t,r]=e.split("/"),n=(new Date).getFullYear(),a=(new Date).getMonth()+1;return!(parseInt(t,10)<1||parseInt(t,10)>12||parseInt(r,10)<n||parseInt(r,10)>n+10||parseInt(r,10)===n&&parseInt(t,10)<a)})(e))(e)}}),t.extend({renavam:e=>e=>{return function(e){if(!e||"string"!=typeof e)return!1;if(!(e=e.padStart(11,"0")).match("^[0-9]{11}$"))return!1;for(var t=e.substring(0,10).split("").reverse().join(""),r=0,n=2,a=0;a<10;a++)r+=t.substring(a,a+1)*n,n>=9?n=2:n++;var s=11-r%11;return(s=s>=10?0:s)===parseInt(e.substring(e.length-1,e.length))}(e.replace(/[^0-9]/g,""))}}),t.extend({brphone:e=>e=>{return function(e){return!(!e||"string"!=typeof e||!/^[0-9]{10,11}$/.test(e))}(e.replace(/[^0-9]/g,""))}}),e.default=t,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("v8n"),require("underscore-99xp")):"function"==typeof define&&define.amd?define(["exports","v8n","underscore-99xp"],t):t((e=e||self).v8nx={},e.v8n,e._)}(this,function(e,t,r){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t,r=r&&r.hasOwnProperty("default")?r.default:r,t.extend({regex:(e,t)=>r.partial(function(e,t,n){if(r.isArray(t)){var a=t[0],s=t[1];n=n.replace(a,s)}return(()=>!!n&&(n=n.toString(),!!e.test(n)))()},e,t)}),t.extend({email:e=>e=>{return function(e){return!(!e||"string"!=typeof e||!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/.test(e))}(e)}}),t.extend({stringAlpha:e=>e=>{return function(e){return!(!e||"string"!=typeof e||!/[a-zA-Z]+/.test(e)||!/[0-9]+/.test(e)||/[^a-zA-Z0-9]+/.test(e))}(e)}}),t.extend({fullname:e=>e=>{return function(e){if(!e||"string"!=typeof e)return!1;var t=e.normalize("NFD").replace(/[\u0300-\u036f]/g,"");return!(!/^[a-zA-Z]{2,}(\s+(([a-zA-Z]{3,})|([a-zA-Z]{2,}\s+[a-zA-Z]{3,})))+$/.test(t)||/[bcdfghjklmnpqrstvwxz]{3,}/.test(t))}(e)}}),t.extend({passwordMatch:e=>(e,t)=>{return function(e){if("object"!=typeof e||void 0===e[0])return!0;var[t,r,n]=e,a=n.split("_");return a.pop(),a=a.join("_"),!!(t&&r&&a in r)&&t+""==r[a]+""}(e)}});var n=function(e){const t=e=>(e=>t=>e.findIndex(e=>t===e)>=0)((e=>Array.from({length:e},(e,t)=>t))(10).map(r(11)))(e),r=e=>t=>`${t}`.repeat(e),n=e=>t=>a((e=>e%11)(((e,t)=>e.reduce((e=>(t,r,n)=>t+r*e--)(t),0))(t,e))),a=e=>e>1?11-e:0;return(e=>11===e.length&&(e=>!e)(t(e))&&(e=>{const t=(e=>e.substr(0,9).split(""))(e),r=n(10)(t),a=n(11)(t.concat(r));return(e=>t=>t===e)((e=>`${e[9]}${e[10]}`)(e))(((e,t)=>`${e}${t}`)(r,a))})(e))(e.replace(/(\.|\-)/g,""))};t.extend({cpf:e=>e=>n(e.replace(/(\.|\-)/g,""))});var a=function(e){const t=e=>(e=>t=>e.findIndex(e=>t===e)>=0)((e=>Array.from({length:e},(e,t)=>t))(10).map(r(14)))(e),r=e=>t=>`${t}`.repeat(e);return(e=>14===e.length&&(e=>!e)(t(e))&&(e=>{if(!e||(e=>e%14)(e.length)>0)return!1;var t,r,n,a,s,u;for(t=e.length-2,r=e.substring(0,t),n=e.substring(t),a=0,s=t-7,u=t;u>=1;u--)a+=r.charAt(t-u)*s--,s<2&&(s=9);if((a%11<2?0:11-a%11)+""!=n.charAt(0)+"")return!1;for(t+=1,r=e.substring(0,t),a=0,s=t-7,u=t;u>=1;u--)a+=r.charAt(t-u)*s--,s<2&&(s=9);return(a%11<2?0:11-a%11)+""==n.charAt(1)+""})(e))(e.replace(/(\.|\-|\/)/g,""))};t.extend({cnpj:e=>e=>a(e.replace(/(\.|\-|\/)/g,""))}),t.extend({cpfcnpj:e=>e=>{var t=e.replace(/(\.|\-|\/)/g,"");return 11===t.length?n(t):a(t)}}),t.extend({creditcard:e=>e=>{const t=e=>{const t=e.toString().split("").map(e=>parseInt(e));(e=>13===e.length||15===e.length||16===e.length)(t);const r=(e=>{const t=e.filter((e,t)=>t%2==1),r=e.filter((e,t)=>t%2==0);let n,a;return e.length%2==1?(n=t.map(e=>2*e),a=r):(n=r.map(e=>2*e),a=t),{arr1:n,arr2:a}})(t);return((e=>e.join("").split("").map(e=>parseInt(e)))(r.arr1).reduce((e,t)=>e+t)+r.arr2.reduce((e,t)=>e+t))%10==0};return(e=>t(e))(e.replace(/[^0-9]/g,""))}}),t.extend({creditcardValidTo:e=>e=>{return(e=>(e=>{if(!/^\d{2}\/\d{4}$/.test(e))return!1;var[t,r]=e.split("/"),n=(new Date).getFullYear(),a=(new Date).getMonth()+1;return!(parseInt(t,10)<1||parseInt(t,10)>12||parseInt(r,10)<n||parseInt(r,10)>n+10||parseInt(r,10)===n&&parseInt(t,10)<a)})(e))(e)}}),t.extend({renavam:e=>e=>{return function(e){if(!e||"string"!=typeof e)return!1;if(!(e=e.padStart(11,"0")).match("^[0-9]{11}$"))return!1;for(var t=e.substring(0,10).split("").reverse().join(""),r=0,n=2,a=0;a<10;a++)r+=t.substring(a,a+1)*n,n>=9?n=2:n++;var s=11-r%11;return(s=s>=10?0:s)===parseInt(e.substring(e.length-1,e.length))}(e.replace(/[^0-9]/g,""))}}),t.extend({brphone:e=>e=>{return function(e){return!(!e||"string"!=typeof e||!/^[0-9]{10,11}$/.test(e))}(e.replace(/[^0-9]/g,""))}}),e.default=t,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=v8n-99xp.min.js.map |
{ | ||
"name": "v8n-99xp", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "util", |
// [v8n-99xp](https://github.com/brunnofoggia/v8n-99xp) is a set of validation | ||
// methods based on projects I've been working on using | ||
// [v8n](https://imbrn.github.io/v8n/). Validations included: email, alpha string, | ||
// [v8n](https://imbrn.github.io/v8n/). Validations included: email, alpha string, | ||
// fullname, passwords match, cpf, cnpj, credit card number and validto, renavam, brphone | ||
// Baseline setup | ||
@@ -15,26 +14,30 @@ // -------------- | ||
regex(testRule, replaceRule) { | ||
return _.partial(function (tr, rr, v) { | ||
var validate = () => { | ||
if (!v) { | ||
return false; | ||
} | ||
v = v.toString(); | ||
return _.partial( | ||
function (tr, rr, v) { | ||
var validate = () => { | ||
if (!v) { | ||
return false; | ||
} | ||
v = v.toString(); | ||
if (tr.test(v)) { | ||
return true; | ||
} | ||
if (tr.test(v)) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
return false; | ||
}; | ||
if (_.isArray(rr)) { | ||
var regex = rr[0], | ||
str = rr[1]; | ||
if (_.isArray(rr)) { | ||
var regex = rr[0], | ||
str = rr[1]; | ||
v = v.replace(regex, str); | ||
} | ||
v = v.replace(regex, str); | ||
} | ||
return validate(); | ||
}, testRule, replaceRule); | ||
} | ||
return validate(); | ||
}, | ||
testRule, | ||
replaceRule | ||
); | ||
}, | ||
}); | ||
@@ -51,3 +54,5 @@ | ||
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/.test(email)) { | ||
if ( | ||
/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/.test(email) | ||
) { | ||
return true; | ||
@@ -60,4 +65,4 @@ } | ||
return validate(value); | ||
} | ||
} | ||
}; | ||
}, | ||
}); | ||
@@ -74,3 +79,7 @@ | ||
if (/[a-zA-Z]+/.test(s) && /[0-9]+/.test(s) && !/[^a-zA-Z0-9]+/.test(s)) { | ||
if ( | ||
/[a-zA-Z]+/.test(s) && | ||
/[0-9]+/.test(s) && | ||
!/[^a-zA-Z0-9]+/.test(s) | ||
) { | ||
return true; | ||
@@ -83,4 +92,4 @@ } | ||
return validate(value); | ||
} | ||
} | ||
}; | ||
}, | ||
}); | ||
@@ -98,4 +107,8 @@ | ||
var vf = v.normalize('NFD').replace(/[\u0300-\u036f]/g, ''); | ||
if (/^[a-zA-Z]{2,}(\s+(([a-zA-Z]{3,})|([a-zA-Z]{2,}\s+[a-zA-Z]{3,})))+$/.test(vf) && | ||
!/[bcdfghjklmnpqrstvwxyz]{3,}/.test(vf)) { | ||
if ( | ||
/^[a-zA-Z]{2,}(\s+(([a-zA-Z]{3,})|([a-zA-Z]{2,}\s+[a-zA-Z]{3,})))+$/.test( | ||
vf | ||
) && | ||
!/[bcdfghjklmnpqrstvwxz]{3,}/.test(vf) | ||
) { | ||
return true; | ||
@@ -108,4 +121,4 @@ } | ||
return validate(value); | ||
} | ||
} | ||
}; | ||
}, | ||
}); | ||
@@ -122,3 +135,6 @@ | ||
var validate = function (data) { | ||
if (typeof data !== 'object' || typeof data[0] === 'undefined') { | ||
if ( | ||
typeof data !== 'object' || | ||
typeof data[0] === 'undefined' | ||
) { | ||
return true; | ||
@@ -145,50 +161,50 @@ } | ||
return validate(value, attrs); | ||
} | ||
} | ||
}; | ||
}, | ||
}); | ||
// CPF Validation (works with or without mask) | ||
var validateCPF = function(value) { | ||
const mod11 = (num) => num % 11 | ||
const not = (x) => !x | ||
const isEqual = (a) => (b) => b === a | ||
const mergeDigits = (num1, num2) => `${num1}${num2}` | ||
const getTwoLastDigits = (cpf) => `${cpf[9]}${cpf[10]}` | ||
const getCpfToCheckInArray = (cpf) => cpf.substr(0, 9).split('') | ||
const generateArray = (length) => Array.from({ length }, (v, k) => k) | ||
var validateCPF = function (value) { | ||
const mod11 = (num) => num % 11; | ||
const not = (x) => !x; | ||
const isEqual = (a) => (b) => b === a; | ||
const mergeDigits = (num1, num2) => `${num1}${num2}`; | ||
const getTwoLastDigits = (cpf) => `${cpf[9]}${cpf[10]}`; | ||
const getCpfToCheckInArray = (cpf) => cpf.substr(0, 9).split(''); | ||
const generateArray = (length) => Array.from({ length }, (v, k) => k); | ||
const isIn = (list) => (val) => | ||
list.findIndex(v => val === v) >= 0 | ||
const isIn = (list) => (val) => list.findIndex((v) => val === v) >= 0; | ||
const isSameDigitsCPF = (cpfFull) => | ||
isIn(generateArray(10).map(generateStringSequence(11)))(cpfFull) | ||
isIn(generateArray(10).map(generateStringSequence(11)))(cpfFull); | ||
const generateStringSequence = (times) => (char) => | ||
(`${char}`.repeat(times)) | ||
const generateStringSequence = (times) => (char) => `${char}`.repeat(times); | ||
const toSumOfMultiplication = (total) => (result, num, i) => | ||
result + (num * total--) | ||
result + num * total--; | ||
const getSumOfMultiplication = (list, total) => | ||
list.reduce(toSumOfMultiplication(total), 0) | ||
list.reduce(toSumOfMultiplication(total), 0); | ||
const getValidationDigit = (total) => (cpf) => | ||
getDigit(mod11(getSumOfMultiplication(cpf, total))) | ||
getDigit(mod11(getSumOfMultiplication(cpf, total))); | ||
const getDigit = (num) => (num > 1) ? 11 - num : 0 | ||
const getDigit = (num) => (num > 1 ? 11 - num : 0); | ||
const isValidCPF = (cpfFull) => { | ||
const cpf = getCpfToCheckInArray(cpfFull) | ||
const firstDigit = getValidationDigit(10)(cpf) | ||
const secondDigit = getValidationDigit(11)(cpf.concat(firstDigit)) | ||
const cpf = getCpfToCheckInArray(cpfFull); | ||
const firstDigit = getValidationDigit(10)(cpf); | ||
const secondDigit = getValidationDigit(11)(cpf.concat(firstDigit)); | ||
return isEqual(getTwoLastDigits(cpfFull))(mergeDigits(firstDigit, secondDigit)); | ||
} | ||
return isEqual(getTwoLastDigits(cpfFull))( | ||
mergeDigits(firstDigit, secondDigit) | ||
); | ||
}; | ||
const validate = (CPF) => CPF.length === 11 && not(isSameDigitsCPF(CPF)) && isValidCPF(CPF) | ||
const validate = (CPF) => | ||
CPF.length === 11 && not(isSameDigitsCPF(CPF)) && isValidCPF(CPF); | ||
return validate(value.replace(/(\.|\-)/g, '')); | ||
}; | ||
} | ||
v8n.extend({ | ||
@@ -198,18 +214,17 @@ cpf(expected) { | ||
return validateCPF(value.replace(/(\.|\-)/g, '')); | ||
} | ||
} | ||
}; | ||
}, | ||
}); | ||
var validateCNPJ = function (value) { | ||
const mod14 = (num) => num % 14 | ||
const not = (x) => !x | ||
const generateArray = (length) => Array.from({ length }, (v, k) => k) | ||
const mod14 = (num) => num % 14; | ||
const not = (x) => !x; | ||
const generateArray = (length) => Array.from({ length }, (v, k) => k); | ||
const isIn = (list) => (val) => list.findIndex(v => val === v) >= 0; | ||
const isIn = (list) => (val) => list.findIndex((v) => val === v) >= 0; | ||
const isSameDigitsCNPJ = (cnpjFull) => | ||
isIn(generateArray(10).map(generateStringSequence(14)))(cnpjFull) | ||
isIn(generateArray(10).map(generateStringSequence(14)))(cnpjFull); | ||
const generateStringSequence = (times) => (char) => | ||
(`${char}`.repeat(times)) | ||
const generateStringSequence = (times) => (char) => `${char}`.repeat(times); | ||
@@ -234,3 +249,3 @@ const isValidCNPJ = (cnpj) => { | ||
} | ||
resultado = soma % 11 < 2 ? 0 : 11 - soma % 11; | ||
resultado = soma % 11 < 2 ? 0 : 11 - (soma % 11); | ||
if (resultado + '' !== digitos.charAt(0) + '') { | ||
@@ -249,3 +264,3 @@ return false; | ||
} | ||
resultado = soma % 11 < 2 ? 0 : 11 - soma % 11; | ||
resultado = soma % 11 < 2 ? 0 : 11 - (soma % 11); | ||
if (resultado + '' !== digitos.charAt(1) + '') { | ||
@@ -256,5 +271,6 @@ return false; | ||
return true; | ||
} | ||
}; | ||
const validate = (CNPJ) => CNPJ.length === 14 && not(isSameDigitsCNPJ(CNPJ)) && isValidCNPJ(CNPJ); | ||
const validate = (CNPJ) => | ||
CNPJ.length === 14 && not(isSameDigitsCNPJ(CNPJ)) && isValidCNPJ(CNPJ); | ||
@@ -269,4 +285,4 @@ return validate(value.replace(/(\.|\-|\/)/g, '')); | ||
return validateCNPJ(value.replace(/(\.|\-|\/)/g, '')); | ||
} | ||
} | ||
}; | ||
}, | ||
}); | ||
@@ -280,4 +296,4 @@ | ||
return v.length === 11 ? validateCPF(v) : validateCNPJ(v); | ||
} | ||
} | ||
}; | ||
}, | ||
}); | ||
@@ -289,9 +305,13 @@ | ||
return (value) => { | ||
const sumArrDigits = (array) => { | ||
return array.join('').split('').map(e => parseInt(e)) | ||
return array | ||
.join('') | ||
.split('') | ||
.map((e) => parseInt(e)); | ||
}; | ||
const validlen = (arr) => { | ||
return arr.length === 13 || arr.length === 15 || arr.length === 16 | ||
return ( | ||
arr.length === 13 || arr.length === 15 || arr.length === 16 | ||
); | ||
}; | ||
@@ -301,20 +321,27 @@ | ||
const selectOddValues = cardArray.filter((a, i) => i % 2 === 1); | ||
const selectEvenValues = cardArray.filter((a, i) => i % 2 === 0); | ||
const selectEvenValues = cardArray.filter( | ||
(a, i) => i % 2 === 0 | ||
); | ||
let arr1; | ||
let arr2; | ||
if (cardArray.length % 2 === 1) { | ||
arr1 = selectOddValues.map(e => e * 2); | ||
arr1 = selectOddValues.map((e) => e * 2); | ||
arr2 = selectEvenValues; | ||
} else { | ||
arr1 = selectEvenValues.map(e => e * 2); | ||
arr1 = selectEvenValues.map((e) => e * 2); | ||
arr2 = selectOddValues; | ||
} | ||
return { arr1, arr2 } | ||
return { arr1, arr2 }; | ||
}; | ||
const isValidCC = (cardNumber) => { | ||
const cardArray = cardNumber.toString().split('').map((e) => parseInt(e)) | ||
const cardArray = cardNumber | ||
.toString() | ||
.split('') | ||
.map((e) => parseInt(e)); | ||
validlen(cardArray); | ||
const splitArr = arrSplit(cardArray) | ||
const checksum = sumArrDigits(splitArr.arr1).reduce((a, c) => a + c) + splitArr.arr2.reduce((a, c) => a + c); | ||
const splitArr = arrSplit(cardArray); | ||
const checksum = | ||
sumArrDigits(splitArr.arr1).reduce((a, c) => a + c) + | ||
splitArr.arr2.reduce((a, c) => a + c); | ||
@@ -326,10 +353,9 @@ if (checksum % 10 === 0) { | ||
return false; | ||
} | ||
}; | ||
const validate = (cardNumber) => isValidCC(cardNumber); | ||
return validate(value.replace(/[^0-9]/g, '')); | ||
} | ||
} | ||
}; | ||
}, | ||
}); | ||
@@ -341,3 +367,2 @@ | ||
return (value) => { | ||
const isValidDate = (dateStr) => { | ||
@@ -349,4 +374,4 @@ if (!/^\d{2}\/\d{4}$/.test(dateStr)) { | ||
var [m, y] = dateStr.split('/'), | ||
cY = (new Date()).getFullYear(), | ||
cM = (new Date()).getMonth() + 1; | ||
cY = new Date().getFullYear(), | ||
cM = new Date().getMonth() + 1; | ||
@@ -356,3 +381,3 @@ if (parseInt(m, 10) < 1 || parseInt(m, 10) > 12) { | ||
} | ||
if (parseInt(y, 10) < cY || parseInt(y, 10) > (cY + 10)) { | ||
if (parseInt(y, 10) < cY || parseInt(y, 10) > cY + 10) { | ||
return false; | ||
@@ -364,10 +389,9 @@ } else if (parseInt(y, 10) === cY && parseInt(m, 10) < cM) { | ||
return true; | ||
} | ||
}; | ||
const validate = (dateStr) => isValidDate(dateStr); | ||
return validate(value); | ||
} | ||
} | ||
}; | ||
}, | ||
}); | ||
@@ -391,3 +415,6 @@ | ||
var renavamSemDigito = renavam.substring(0, 10); | ||
var renavamReversoSemDigito = renavamSemDigito.split('').reverse().join(''); | ||
var renavamReversoSemDigito = renavamSemDigito | ||
.split('') | ||
.reverse() | ||
.join(''); | ||
@@ -409,4 +436,7 @@ var soma = 0; | ||
var ultimoDigitoCalculado = 11 - mod11; | ||
ultimoDigitoCalculado = (ultimoDigitoCalculado >= 10 ? 0 : ultimoDigitoCalculado); | ||
var digitoRealInformado = parseInt(renavam.substring(renavam.length - 1, renavam.length)); | ||
ultimoDigitoCalculado = | ||
ultimoDigitoCalculado >= 10 ? 0 : ultimoDigitoCalculado; | ||
var digitoRealInformado = parseInt( | ||
renavam.substring(renavam.length - 1, renavam.length) | ||
); | ||
if (ultimoDigitoCalculado === digitoRealInformado) { | ||
@@ -417,8 +447,7 @@ return true; | ||
return false; | ||
}; | ||
return validate(value.replace(/[^0-9]/g, '')); | ||
} | ||
} | ||
}; | ||
}, | ||
}); | ||
@@ -443,6 +472,6 @@ | ||
return validate(value.replace(/[^0-9]/g, '')); | ||
} | ||
} | ||
}; | ||
}, | ||
}); | ||
export default v8n; |
@@ -5,6 +5,14 @@ import v8n from '../lib/v8n-99xp.esm.js'; | ||
test('valid dd/mm/yyyy > 11/11/2020', () => { | ||
expect(v8n().regex(/^(\d{2})\/(\d{2})\/(\d{4})$/).test('11/11/2020')).toBe(true); | ||
expect( | ||
v8n() | ||
.regex(/^(\d{2})\/(\d{2})\/(\d{4})$/) | ||
.test('11/11/2020') | ||
).toBe(true); | ||
}); | ||
test('invalid dd/mm/yyyy > 11/11', () => { | ||
expect(v8n().email(/^(\d{2})\/(\d{2})\/(\d{4})$/).test('11/11/2020')).toBe(false); | ||
expect( | ||
v8n() | ||
.email(/^(\d{2})\/(\d{2})\/(\d{4})$/) | ||
.test('11/11/2020') | ||
).toBe(false); | ||
}); | ||
@@ -35,2 +43,5 @@ | ||
}); | ||
test('valid fullname 2 > kaitlyn maria', () => { | ||
expect(v8n().fullname().test('kaitlyn maria')).toBe(true); | ||
}); | ||
test('invalid fullname > bruno', () => { | ||
@@ -42,12 +53,28 @@ expect(v8n().fullname().test('bruno')).toBe(false); | ||
test('passwords match', () => { | ||
expect(v8n().passwordMatch().test(['string123', 'password_1', { | ||
password: 'string123', | ||
password_1: 'string123' | ||
}])).toBe(false); | ||
expect( | ||
v8n() | ||
.passwordMatch() | ||
.test([ | ||
'string123', | ||
'password_1', | ||
{ | ||
password: 'string123', | ||
password_1: 'string123', | ||
}, | ||
]) | ||
).toBe(false); | ||
}); | ||
test('passwords not match', () => { | ||
expect(v8n().passwordMatch().test(['string123', 'password_1', { | ||
password: 'string1234', | ||
password_1: 'string123' | ||
}])).toBe(false); | ||
expect( | ||
v8n() | ||
.passwordMatch() | ||
.test([ | ||
'string123', | ||
'password_1', | ||
{ | ||
password: 'string1234', | ||
password_1: 'string123', | ||
}, | ||
]) | ||
).toBe(false); | ||
}); | ||
@@ -54,0 +81,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
694751
31
2002