Code Monkey home page Code Monkey logo

phony's Introduction


Coverage Status

Phony

Disclaimer: Phony works with international numbers only, such as +61 412 345 678!

The (admittedly crazy) goal of this Gem is to be able to normalize/format/split all phone numbers in the world.

Used in: airbnb.com, socialcam.com, zendesk.com (and many, many others).

Runtime Memory Usage

According to memory_profiler, the Phony gem uses roughly 1 MB of memory per Ruby process.
Usage was generated using: ruby -e 'require "memory_profiler"; MemoryProfiler.report(allow_files: "phony"){ require "phony" }.pretty_print'

Description

This gem normalizes, formats and splits E164 phone numbers. A valid E164 phone number must include a country code.

E164 numbers are international numbers with a country dial prefix, usually an area code and a subscriber number. For example, the Australian number +61 412 345 678 can be broken down into the following components:

  • Country Code (CC): a country code of 61
  • National Destination Code (NDC): a mobile number denoted by the 4 (specific to Australia)
  • Local Number Part: a subscriber number of 12 345 678

It currently handles the countries listed at the end of this README.

It is covered by roughly 2,000 tests (January 2016).
If it doesn’t work, please enter an issue or better, fork and send a pull request.

Installation

With Rails? Check out: https://github.com/joost/phony_rails.

With Bundler: Append gem 'phony' to your Gemfile and bundle install it.

Without Bundler: Run gem install phony from your command line.

Usage docs

Phony uses qed as docs and to run its functional tests. Start here for usage docs: Usage index.

Phony.normalize(number)

Normalize intelligently removes all non-numeric characters of a number. Do it before storing a number in a DB.

Phony.normalize docs

Phony.normalize('1-888-407-4747').assert == '18884074747'

Phony.format(number, options = {})

Format formats a normalized number according to a country’s predominant formatting. Lots of options for int’l, national, local formatting.

Phony.format docs

Phony.format('41443643532').assert == '+41 44 364 35 32'

Phony.plausible?(number, options = {})

Is a number plausible?

Phony.plausible? docs

Phony.assert.plausible?('+41 44 111 22 33')

Phony.split(number)

Split a number into its parts: CC, NDC, local.

Phony.split docs

Phony.split('3928061371').assert == ['39', '2', '806', '1371']

NB If a country does not have an NDC, #split will return false in the NDC position, for example for Denmark:

Phony.split('4512121212').assert == ['45', false, '12', '12', '12', '12']

List of Handled Countries

Mildly unmaintained list: Abhas, Afghan, Algerian, Argentina, Austrian, Australian, Azerbaijani, Belgian, Brazilian, Cambodian, Chilean, Chinese, Croatian, Cuban, Cypriot, Czech, Danish, Dutch, Egyptian, El Salvadorian, Estonian, French, German, Ghanan, Gibraltar, Greek, Haiti, Hong Kong, Hungarian, Indian, Iran, Irish, Israel, Italian, Kazakh, Liberian, Lithuanian, Luxembourgian, Malaysian, Malta, Mexican, Monaco, Morocco, New Zealand, Nigerian, Norwegian, Peruvian, Polish, Romanian, Russian, Rwandan, Seychelles, Singapore, Slovakian, South African, South Korean, South Osetian, Spanish, Sri Lankan, Sudan, Swedish, Swiss, Thailand, Tunisian, Turkish, Liechtenstein, UK, US, Venezuelan, Vietnamese, and Zambian numbers.

License

MIT.
See LICENSE file.

phony's People

Contributors

floere avatar slike9 avatar jcfischer avatar dwilkie avatar g1smd avatar kbingman avatar tpena avatar andi avatar franckverrot avatar weppos avatar isqad avatar bibendi avatar toxix avatar c1n1c avatar imhouston avatar gerard76 avatar eduardofiorezi avatar emily avatar marcboquet avatar baxter avatar sconstantinides avatar pmor avatar uelb avatar samda avatar mrchucho avatar marshall-lee avatar nashby avatar ream88 avatar onmyway133 avatar gpmatias avatar

Watchers

 avatar James Cloos avatar

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.