telefone

Biblioteca 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.
Install
npm i telefone
Como importar
const parse = require('telefone/parse');
const { parse } = require('telefone');
const parse = require('telefone').parse;
const format = require('telefone/format');
const { format } = require('telefone');
const format = require('telefone').format;
parse(str)
const parse = require('telefone/parse');
console.log(parse("+55 (21) 97864-2213"));
console.log(parse("(21) 00000-0000"));
console.log(parse("+55 (21) 97864-2213", { apenasFixo: true }));
console.log(parse("+55 (21) 4002-8922", { apenasCelular: true }));
console.log(parse("+55 (21) 4002-8922", { apenasDDD: [ '11', '24' ] }));
format(str)
const format = require('telefone/format');
console.log(format("+55 2197864 2213"));
console.log(format("+5521 4002 8922"));
console.log(format("2140028922"));
Posso usar em produção?
Deve. Essa biblioteca tem uma política estrita de 100% de cobertura. Além disso, ela tem sido usada internamente em produção desde 2019.
Licença
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.