UNPKG

@malga-checkout-full/core

Version:
20 lines (19 loc) 1.01 kB
import { cleanTextOnlyNumbers } from '@malga-checkout/utils'; export const normalizeValidationErrors = (errors) => { const normalizedErrors = errors.reduce((accumulatorErrors, currentError) => (Object.assign(Object.assign({}, accumulatorErrors), { [currentError.path]: currentError.message })), {}); return normalizedErrors; }; export const getIdentificationMask = (identification) => { const normalizedIdentification = cleanTextOnlyNumbers(identification); if (!normalizedIdentification) return ''; const cnpjMask = '99.999.999/9999-99'; const cpfMask = '999.999.999-999'; return normalizedIdentification.length > 11 ? cnpjMask : cpfMask; }; export const validAddressAutocomplete = (address) => { const parsedAddress = Object.entries(address); const filteredAddress = parsedAddress.filter(([, value]) => value); const reducedAddress = filteredAddress.reduce((accumulator, [field]) => (Object.assign(Object.assign({}, accumulator), { [field]: undefined })), {}); return reducedAddress; };