workie
A utility package with multiple pre made functions
Last updated 2 months ago by knewitzgui .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install workie 
SYNC missed versions from official npm registry.

Workie

Installation

Install with npm:

npm install workie

Install with yarn:

yarn add workie

Usage

Format CPF and CNPJ:

  • Input type number.
  • Call formatCpfCnpj(number).
  • *Cannot contain special characters, only numbers.

Format phone:

  • Input type number.
  • Call formatPhone(number).
  • *Cannot contain special characters, only numbers.

Format CEP:

  • Input type number.
  • Call formatCep(number).
  • *Cannot contain special characters, only numbers.

Perform a search using consultaCep

Cep search module use the cep-promise wich is multiprovider, the lib will resolve the Promise with the provider wich reply faster.

import {consultaCep} from 'workie'

consultaCep('93315400')
  .then(console.log)

  // {
  //   "cep":  "93315400",
  //   "state":  "RS",
  //   "city":  "Novo Hamburgo",
  //   "street":  "Rua Visconde de Ouro Preto",
  //   "neighborhood":  "Operário",
  // }

Case CEP wasn't found

In this case will return a "service_error", the lib will only reject the Promise when all the providers reply negative.

import {consultaCep} from 'workie'

consultaCep('99999999')
  .catch(console.log)

  // {
  //     name: 'CepPromiseError',
  //     message: 'Todos os serviços de CEP retornaram erro.',
  //     type: 'service_error',
  //     errors: [{
  //       message: 'CEP NAO ENCONTRADO',
  //       service: 'correios'
  //     }, {
  //       message: 'CEP não encontrado na base do ViaCEP.',
  //       service: 'viacep'
  //     }]
  // }

Case CEP have an invalid format

In this case will return a "validation_error", the lib will immediately reject the Promise, without call a provider.

import {consultaCep} from 'workie'

consultaCep('123456789123456789')
  .catch(console.log)

  // {
  //     name: 'CepPromiseError',
  //     message: 'CEP deve conter exatamente 8 caracteres.',
  //     type: 'validation_error',
  //     errors: [{
  //       message: 'CEP informado possui mais do que 8 caracteres.',
  //       service: 'cep_validation'
  //     }]
  // }

Dependencies:

"cep-promise": "^3.0.9"

License

MIT © Guilherme Maier Knewitz

Current Tags

  • 1.2.2                                ...           latest (2 months ago)

7 Versions

  • 1.2.2                                ...           2 months ago
  • 1.2.1                                ...           2 months ago
  • 1.2.0                                ...           2 months ago
  • 1.1.7                                ...           2 months ago
  • 1.1.4                                ...           2 months ago
  • 1.1.3                                ...           2 months ago
  • 1.1.2                                ...           2 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |