Biblioteca para validar facilmente telefones brasileiros
npm install telefoneBiblioteca para validar e formatar facilmente telefones brasileiros
O objetivo desta biblioteca é ser leve e oferecer métodos simples e garantidos para validação e formatação básica de telefones brasileiros.
```
npm i telefone
`js
const parse = require('telefone/parse');
// ou
const { parse } = require('telefone');
// ou
const parse = require('telefone').parse;
const format = require('telefone/format');
// ou
const { format } = require('telefone');
// ou
const format = require('telefone').format;
`
`js`
const parse = require('telefone/parse');
console.log(parse("+55 (21) 97864-2213")); //retorna 21978642213
console.log(parse("(21) 00000-0000")); //retorna null, pois o telefone é inválido
console.log(parse("+55 (21) 97864-2213", { apenasFixo: true })); //retorna null, pois o telefone não é fixo
console.log(parse("+55 (21) 4002-8922", { apenasCelular: true })); //retorna null, pois o telefone não é celular
console.log(parse("+55 (21) 4002-8922", { apenasDDD: [ '11', '24' ] })); //retorna null, pois o telefone não é de um dos DDDs informados
`js``
const format = require('telefone/format');
console.log(format("+55 2197864 2213")); //retorna (21) 97864-2213
console.log(format("+5521 4002 8922")); //retorna (21) 4002-8922
console.log(format("2140028922")); //retorna (21) 4002-8922
MIT License
Copyright (c) 2019-2025 Patrick Pissurno
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.