Git Product home page Git Product logo

front.phone's Introduction

front.phone

Build Status

front.phone is a Javascript library that identifies, validates and formats phone numbers.

Demo

The main goal of this project is to create a trustful component to input phone numbers and extract information from it. We can currently extract the phone's country code, national destination number, it's number and in some cases if it is a mobile number. The recommended input for it's use is in international notation.

We are compliant to the E.123 notation.

Countries

We currently cover these countries.

Didn't find your own? Feel free to contribute!

Usage

Getting Phone's Info

This functions extracts info from a number in international or national notation and also validate. You can pass the country code and national destination number (in this order) as a param, if you already know them.

var Phone = require("@vtex/phone");
var brazil = require("@vtex/phone/countries/BRA");

// you can relax about usage of hiphens and other special characters, we'll strip 
//it down internally later ;)
var number = "5521989898989";
var phone = Phone.getPhoneInternational(number);
console.log(phone); // { countryCode: "55", nationalDestinationCode: "21", 
//number: "998986565", isMobile: true, isValid: true }
var Phone = require("@vtex/phone");
var brazil = require("@vtex/phone/countries/BRA");

var number = "5521989898989";
var phone = Phone.getPhoneNational(number, "55"); // if you use this function,
//you MUST give the phone's countryCode
console.log(phone); // { countryCode: "55", nationalDestinationCode: "21",
//number: "998986565", isMobile: true, isValid: true }

Validation

This function is a bit different from the above function, it's a bit faster and uses only a big regex to validate the number, returning true or false.

var Phone = require("@vtex/phone");
var brazil = require("@vtex/phone/countries/BRA");

// Given a phone number in international notation
var number = "+552189898989";
var result = Phone.validate(number);
console.log(result); // true

If you already know the phone's country code you may include in a new param.

var Phone = require("@vtex/phone");
var brazil = require("@vtex/phone/countries/BRA");

// Given a phone number in international notation
var number = "+552189898989";
var result = Phone.validate(number, "55");
console.log(result); // true

Formatting

For the use of this function you need first to get the phone's info. You can get formatted in three different notations: international, national or local. Remember that all of them follows E.123.

var Phone = require("@vtex/phone");
var brazil = require("@vtex/phone/countries/BRA");

var number = "552189898989";
var phone = Phone.getPhoneInternational(number);
var result = Phone.format(phone, Phone.INTERNATIONAL);
console.log(result); // +55 21 8989 8989
var Phone = require("@vtex/phone");
var brazil = require("@vtex/phone/countries/BRA");

var number = "552189898989";
var phone = Phone.getPhoneInternational(number);
var result = Phone.format(phone, Phone.NATIONAL);
console.log(result); // (21) 8989-8989
var Phone = require("@vtex/phone");
var brazil = require("@vtex/phone/countries/BRA");

var number = "552189898989";
var phone = Phone.getPhoneInternational(number);
var result = Phone.format(phone, Phone.LOCAL);
console.log(result); // 8989-8989

Angular Filter

Use the filter like this:

{{ user.phoneNumber | phone }}
or
{{ '552189898989' | phone }}
->
+55 21 8989 8989

It also has two optional parameters:

  • the format to be converted. One of 'international', 'national', 'local'.
  • the national number, if needed. It's blank by default.
{{ '2189898989' | phone:'international':55 }}
->
+55 21 8989 8989

Building and Testing

We use Grunt as a task runner. Before you start, make sure to npm install -g grunt-cli and npm install.

Use grunt to build and test, and rebuild whenever a file is changed.

Use grunt dist to build, test and prepare files to npm.

Contributing

Anyone is welcome to contribute to this project. We now are urging for pull requests of new countries' phones. But before you do, please read the guidelines for contributing.

License

Licensed under the MIT License

front.phone's People

Contributors

caetano1 avatar camilavcoutinho avatar danialvino avatar dependabot[bot] avatar dk-cicd[bot] avatar gabrielfelipeg avatar gabrielgodoy-zz avatar garrucho avatar gberger avatar gmbarroso avatar guifromrio avatar jeffersontuc avatar kaio-donadelli avatar kevinch avatar klzns avatar lucasecdb avatar natavmelo avatar omninando avatar sheilagomes avatar wdsrocha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

front.phone's Issues

Canada and the USA share a country code

I was looking at adding support for Canada, when I realized that currently, countries are indexed by countryCode. Canada and the USA are both countryCode 1 (they are both members of http://www.nanpa.com/).

Should there be instead a northamerica.coffee that handles both countries?

Other Angular Filters

While front.phone has three utilities (format, validate, getInfo), there is only one Angular filter: 'phone', which formats.

Redesign gh-pages

  • Hero and footer
  • Single column example
  • Easier call to actions
  • Github buttons
  • Responsiveness

Include new Mexico area code

Include new Mexico area code 56, valid since Oct/2018: https://en.wikipedia.org/wiki/Area_code_56_(Mexico)

"33", "55", "81", "221", "222","223","224","225","226","227","228","229","231","232","233","235","236","237","238","241","243","244","245","246","247","248","249","271","272","273","274","275","276","278","279","281","282","283","284","285","287","288","294","296","297","311","312","313","314","315","316","317","318","319","321","322","323","324","325","326","327","328","329","341","342","343","344","345","346","347","348","349","351","352","353","354","355","356","357","358","359","371","372","373","374","375","376","377","378","379","381","382","383","384","385","386","387","388","389","391","392","393","394","395","411","412","413","414","415","417","418","419","421","422","423","424","425","426","427","428","429","431","432","433","434","435","436","437","438","441","442","443","444","445","447","448","449","451","452","453","454","455","456","457","458","459","461","462","463","464","465","466","467","468","469","471","472","473","474","475","476","477","478","481","482","483","485","486","487","488","489","492","493","494","495","496","498","499","588","591","592","593","594","595","596","597","599","612","613","614","615","616","618","621","622","623","624","625","626","627","628","629","631","632","633","634","635","636","637","638","639","641","642","643","644","645","646","647","648","649","651","652","653","656","658","659","661","662","664","665","667","668","669","671","672","673","674","675","676","677","686","687","694","695","696","697","698","711","712","713","714","715","716","717","718","719","721","722","723","724","725","726","727","728","729","731","732","733","734","735","736","737","738","739","741","742","743","744","745","746","747","748","749","751","753","754","755","756","757","758","759","761","762","763","764","765","766","767","768","769","771","772","773","774","775","776","777","778","779","781","782","783","784","785","786","789","791","797","821","823","824","825","826","827","828","829","831","832","833","834","835","836","841","842","844","845","846","861","862","864","866","867","868","869","871","872","873","877","878","891","892","894","897","899","913","914","916","917","918","919","921","922","923","924","932","933","934","936","937","938","951","953","954","958","961","962","963","964","965","966","967","968","969","971","972","981","982","983","984","985","986","987","988","991","992","993","994","995","996","997","998","999"

Better Angular Filter

We now have this:

{{ '552189898989' | phone }}

I want to do this, specifying the output format:

{{ '552189898989' | phone:vtex.phone.INTERNATIONAL }}

Etc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.