{"version":3,"file":"../checkout-validation-brazilian-documents-326.min.js","sources":["checkout-validation-brazilian-documents-326.js"],"sourcesContent":["/**\n * Manage checkout front-end validation for: Brazilian Market for WooCommerce (by Claudio Sanches)\n *\n * DEPENDS ON:\n * - checkout-validation.js // Main checkout validation script from Fluid Checkout\n * \n * BASED ON:\n * - https://github.com/lourencorodrigo/validator-brazil\n */\n\n(function (root, factory) {\n\tif ( typeof define === 'function' && define.amd ) {\n\t\tdefine([], factory(root));\n\t} else if ( typeof exports === 'object' ) {\n\t\tmodule.exports = factory(root);\n\t} else {\n\t\troot.CheckoutValidationBrazilianDocuments = factory(root);\n\t}\n})(typeof global !== 'undefined' ? global : this.window || this.global, function (root) {\n\n\t'use strict';\n\n\tvar _hasInitialized = false;\n\tvar _publicMethods = { };\n\tvar _settings = {\n\t\ttypeCPFFieldSelector: '.validate-cpf',\n\t\ttypeCNPJFieldSelector: '.validate-cnpj',\n\t\tvalidateCPF: 'no',\n\t\tvalidateCNPJ: 'no',\n\t\tvalidationMessages: {\n\t\t\tcpf_invalid: 'The CPF number \"{cpf_number}\" is invalid.',\n\t\t\tcnpj_invalid: 'The CNPJ number \"{cpf_number}\" is invalid.',\n\t\t},\n\t};\n\tvar regexClearFormatting = /[\\.\\-\\/]+/g;\n\n\n\n\t/**\n\t * METHODS\n\t */\n\n\n\n\t/**\n\t * Check if form row is a CPF field.\n\t * @param {Field} field Field for validation.\n\t * @param {Element} formRow Form row element.\n\t * @param {String} validationEvent Event that triggered the validation.\n\t * @return {Boolean} Whether the field is a CPF field.\n\t */\n\tvar isCPFField = function( field, formRow, validationEvent ) {\n\t\t// Bail if not a CPF field\n\t\tif ( ! formRow.matches( _settings.typeCPFFieldSelector ) ) { return false; }\n\n\t\treturn true;\n\t};\n\n\t/**\n\t * Verify if a CPF value is valid.\n\t *\n\t * @param {string} cpf The CPF value, with or without formatting.\n\t *\n\t * @return {bool} `true` if CPF is valid, `false` otherwise.\n\t */\n\tvar isCPF = function( cpf ) {\n\t\t// Clear formatting\n\t\tcpf = cpf.replace( regexClearFormatting, '' );\n\n\t\t// Bail if value is empty\n\t\tif ( cpf == \"\" ) { return false };\n\n\t\t// Bail if it is a known invalid CPF value\n\t\tif (\n\t\t\tcpf.length != 11\n\t\t\t|| cpf == \"00000000000\"\n\t\t\t|| cpf == \"11111111111\"\n\t\t\t|| cpf == \"22222222222\"\n\t\t\t|| cpf == \"33333333333\"\n\t\t\t|| cpf == \"44444444444\"\n\t\t\t|| cpf == \"55555555555\"\n\t\t\t|| cpf == \"66666666666\"\n\t\t\t|| cpf == \"77777777777\"\n\t\t\t|| cpf == \"88888888888\"\n\t\t\t|| cpf == \"99999999999\"\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tvar add = 0;\n\n\t\t// Check first verification digit\n\t\tfor ( var i = 0; i < 9; i++ ) {\n\t\t\tadd += parseInt( cpf.charAt( i ) ) * ( 10 - i );\n\t\t}\n\t\tvar rev = 11 - ( add % 11 );\n\t\tif ( rev == 10 || rev == 11 ) { rev = 0; }\n\n\t\t// Maybe return `false` if verification digit is invalid\n\t\tif ( rev != parseInt( cpf.charAt( 9 ) ) ) { return false; }\n\t \n\t\tadd = 0;\n\t \n\t\t// Check second verification digit\n\t\tfor ( var i = 0; i < 10; i++ ) {\n\t\t\tadd += parseInt( cpf.charAt( i ) ) * ( 11 - i );\n\t\t}\n\t\trev = 11 - ( add % 11 );\n\t\tif ( rev == 10 || rev == 11 ) rev = 0;\n\n\t\t// Maybe return `false` if verification digit is invalid\n\t\tif ( rev != parseInt( cpf.charAt( 10 ) ) ) { return false; }\n\n\t\t// Return `true` otherwise\n\t\treturn true;\n\t}\n\n\t/**\n\t * Validate CPF field.\n\t * @param {Field} field Field for validation.\n\t * @param {Element} formRow Form row element.\n\t * @param {String} validationEvent Event that triggered the validation.\n\t * @return {Boolean} Whether the field has a valid CPF value.\n\t */\n\tvar validateCPFField = function( field, formRow, validationEvent ) {\n\t\t// Bail if field does not have a value, return as \"null\" to skip validation and let the required validation handle it\n\t\tif ( ! CheckoutValidation.hasValue( field ) ) { return { valid: null }; }\n\n\t\t// Clear formatting\n\t\tvar fieldValue = field.value.replace( regexClearFormatting, '' );\n\n\t\t// Bail if user is still typing and field has not reached the minimum length, return as \"null\" to avoid showing error messages\n\t\tif ( 'input' === validationEvent && fieldValue.length < 11 ) { return { valid: null }; }\n\n\t\t// Bail if invalid CPF number\n\t\tif ( ! isCPF( field.value ) ) { return { valid: false, message: _settings.validationMessages.cpf_invalid.replace( '{cpf_number}', field.value ) } }\n\n\t\t// Field is valid\n\t\treturn { valid: true };\n\t};\n\n\n\n\t/**\n\t * Check if form row is a CNPJ field.\n\t * @param {Field} field Field for validation.\n\t * @param {Element} formRow Form row element.\n\t * @param {String} validationEvent Event that triggered the validation.\n\t * @return {Boolean} Whether the field is a CNPF field.\n\t */\n\tvar isCNPJField = function( field, formRow, validationEvent ) {\n\t\t// Bail if not a CNPJ field\n\t\tif ( ! formRow.matches( _settings.typeCNPJFieldSelector ) ) { return false; }\n\n\t\treturn true;\n\t};\n\n\t/**\n\t * Verify if a CNPJ value is valid.\n\t *\n\t * @param {string} cnpj The CNPJ value, with or without formatting.\n\t *\n\t * @return {bool} `true` if CNPJ is valid, `false` otherwise.\n\t */\n\tvar isCNPJ = function( cnpj ) {\n\t\t// Clear formatting\n\t\tcnpj = cnpj.replace( regexClearFormatting, '' );\n\n\t\t// Bail if empty\n\t\tif ( cnpj == \"\" ) { return false; }\n\n\t\t// Bail if invalid length\n\t\tif ( cnpj.length != 14 ) { return false; }\n\n\t\t// Bail if it is a known invalid number\n\t\tif (\n\t\t\tcnpj == \"00000000000000\"\n\t\t\t|| cnpj == \"11111111111111\"\n\t\t\t|| cnpj == \"22222222222222\"\n\t\t\t|| cnpj == \"33333333333333\"\n\t\t\t|| cnpj == \"44444444444444\"\n\t\t\t|| cnpj == \"55555555555555\"\n\t\t\t|| cnpj == \"66666666666666\"\n\t\t\t|| cnpj == \"77777777777777\"\n\t\t\t|| cnpj == \"88888888888888\"\n\t\t\t|| cnpj == \"99999999999999\"\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Check first verification digit\n\t\tvar size = cnpj.length - 2;\n\t\tvar numbers = cnpj.substring( 0, size );\n\t\tvar digits = cnpj.substring( size );\n\t\tvar sum = 0;\n\t\tvar pos = size - 7;\n\t\tfor ( var i = size; i >= 1; i-- ) {\n\t\t\tsum += numbers.charAt( size - i ) * pos--;\n\t\t\tif ( pos < 2 ) { pos = 9; }\n\t\t}\n\t\tvar result = sum % 11 < 2 ? 0 : 11 - ( sum % 11 );\n\t\t\n\t\t// Bail if first verification digit is invalid\n\t\tif ( result != digits.charAt( 0 ) ) { return false; }\n\n\t\t// Check second verification digit\n\t\tsize = size + 1;\n\t\tnumbers = cnpj.substring( 0, size );\n\t\tsum = 0;\n\t\tpos = size - 7;\n\t\tfor ( var i = size; i >= 1; i-- ) {\n\t\t\tsum += numbers.charAt( size - i ) * pos--;\n\t\t\tif ( pos < 2 ) { pos = 9; }\n\t\t}\n\t\tresult = sum % 11 < 2 ? 0 : 11 - ( sum % 11 );\n\t\t\n\t\t// Bail if second verification digit is invalid\n\t\tif ( result != digits.charAt( 1 ) ) { return false; }\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Validate CNPJ field value.\n\t * @param {Field} field Field for validation.\n\t * @param {Element} formRow Form row element.\n\t * @param {String} validationEvent Event that triggered the validation.\n\t * @return {Boolean} Whether the field has a valid CPF value.\n\t */\n\tvar validateCNPJField = function( field, formRow, validationEvent ) {\n\t\t// Bail if field does not have a value, return as \"null\" to skip validation and let the required validation handle it\n\t\tif ( ! CheckoutValidation.hasValue( field ) ) { return { valid: null }; }\n\n\t\t// Clear formatting\n\t\tvar fieldValue = field.value.replace( regexClearFormatting, '' );\n\n\t\t// Bail if user is still typing and field has not reached the minimum length, return as \"null\" to avoid showing error messages\n\t\tif ( 'input' === validationEvent && fieldValue.length < 14 ) { return { valid: null }; }\n\n\t\t// Bail if invalid CNPJ number\n\t\tif ( ! isCNPJ( field.value ) ) { return { valid: false, message: _settings.validationMessages.cnpj_invalid.replace( '{cnpj_number}', field.value ) } }\n\n\t\t// Field is valid\n\t\treturn { valid: true };\n\t};\n\n\n\n\t/**\n\t * Register validation types.\n\t */\n\tvar registerValidationTypes = function() {\n\t\t// Maybe register CPF validation type\n\t\tif ( 'yes' === _settings.validateCPF ) {\n\t\t\tCheckoutValidation.registerValidationType( 'cpf_invalid', 'cpf', isCPFField, validateCPFField );\n\t\t}\n\n\t\t// Maybe register CNPJ validation type\n\t\tif ( 'yes' === _settings.validateCNPJ ) {\n\t\t\tCheckoutValidation.registerValidationType( 'cnpj_invalid', 'cnpj', isCNPJField, validateCNPJField );\n\t\t}\n\t}\n\n\n\n\t/**\n\t * Initialize component and set related handlers.\n\t */\n\t_publicMethods.init = function( options ) {\n\t\tif ( _hasInitialized ) return;\n\n\t\t// Bail if `CheckoutValidation` is not available\n\t\tif ( ! window.CheckoutValidation ) { return; }\n\n\t\t// Merge settings\n\t\t_settings = FCUtils.extendObject( _settings, options );\n\n\t\t// Register validation types\n\t\tregisterValidationTypes();\n\n\t\t_hasInitialized = true;\n\t};\n\n\n\t\n\t//\n\t// Public APIs\n\t//\n\treturn _publicMethods;\n\n});\n"],"names":["root","factory","define","amd","exports","module","CheckoutValidationBrazilianDocuments","global","this","window","isCPFField","field","formRow","validationEvent","matches","_settings","typeCPFFieldSelector","validateCPFField","fieldValue","CheckoutValidation","hasValue","value","replace","regexClearFormatting","length","valid","isCPF","message","validationMessages","cpf_invalid","isCNPJField","typeCNPJFieldSelector","validateCNPJField","isCNPJ","cnpj_invalid","_hasInitialized","_publicMethods","validateCPF","validateCNPJ","cpf","add","i","parseInt","charAt","rev","cnpj","size","numbers","substring","digits","sum","pos","init","options","FCUtils","extendObject","registerValidationType"],"mappings":"CAUA,CAAWA,EAAMC,KACO,YAAlB,OAAOC,QAAyBA,OAAOC,IAC3CD,OAAO,GAAID,EAAY,CAAC,EACM,UA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