carvalhoviniciusluiz / cpf-cnpj-validator

Valida e formata strings de CPF ou CNPJ.
MIT License
206 stars 27 forks source link

Must be invoked on a Joi instance. #8

Closed dmytropanontko closed 4 years ago

dmytropanontko commented 5 years ago

Hi, I try to use your package on front-end and get the following error image

I imported the package in following way:

import validator from 'cpf-cnpj-validator';
const Joi = require('@hapi/joi').extend(validator);
hugolomas commented 4 years ago

I'm getting the same error

lincolnlemos commented 4 years ago

Same here using Vuejs

import { cpf, cnpj } from 'cpf-cnpj-validator';

const validateCpfCnpj = function (value) {
  if (value.length == 11 && cpf.isValid(value)) {    
    return true;
  } else if (value.length == 14 && cnpj.isValid(value)) {
    return true;
  } else {
    return false;
  }  
}
carvalhoviniciusluiz commented 4 years ago

I made a correction, you can try like this

import J from '@hapi/joi';
import { validator } from 'cpf-cnpj-validator';

const Joi = J.extend(validator);