9worphi-helpers

Helper functions used across many apps

Usage no npm install needed!

<script type="module">
  import worphiHelpers from 'https://cdn.skypack.dev/9worphi-helpers';
</script>

README

Helpers

checkType

Como utilizar

import { checkType } from '9worphi-helpers'
...
const type_to_be_checked = () => "I'm a function"

new checkType(type_to_be_checked).isFunction // returns true
new checkType(type_to_be_checked).isObject // returns false
new checkType(type_to_be_checked).isArray // returns false
new checkType(type_to_be_checked).isString // returns false
new checkType(type_to_be_checked).isNumber // returns false
new checkType(type_to_be_checked).getType // returns "function"

getAddressByCEP

Como utilizar

import { getAddressByCEP } from '9worphi-helpers'
...
getAddressByCEP("CEP AQUI").then(response => {
    if (response.error) {
        return alert("Endereço não encontrado")
    }
    // Executa algo utilizando a "response"
}).catch(error => console.log(error))

classnames

Como utilizar

import { classnames } from '9worphi-helpers'
...
const seIssoForVerdadeiro = true
...
<AlgumComponente className={classnames("classe-fixa", { "esta-classe-so-aparece": seIssoForVerdadeiro })} />
// Resulta className="classe-fixa esta-classe-so-aparece"

Random ID generator

Como utilizar

import { ID } from '9worphi-helpers'
...
ID() // retorna "id_3atyf3n"
ID(5, "teste_") // retorna "teste_kk194"

validateEmail

Como utilizar

import { validateEmail } from '9worphi-helpers'
...
validateEmail("e-mail aqui") // retorna true ou false

validatePhone

Como utilizar

import { validatePhone } from '9worphi-helpers'
...
validatePhone("telefone aqui") // retorna true ou false

validateCNPJ

Como utilizar

import { validateCNPJ } from '9worphi-helpers'
...
validateCNPJ("cnpj aqui") // retorna true ou false

validateCPF

Como utilizar

import { validateCPF } from '9worphi-helpers'
...
validateCPF("cpf aqui") // retorna true ou false

axiosErrorLog

Como utilizar

import { axiosErrorLog } from '9worphi-helpers'
...
axios.get("URL")
.then(response => {
    // tanto faz aqui
})
.catch(axiosErrorLog) // lida com a resposta de erros do axios