Giter VIP home page Giter VIP logo

raf's Introduction

What's it?

Open-source library for generating valid phone numbers in the E.164 format based on upgraded metadata from libphonenumber

Why not just use the libphonenumber?

There are several reasons for this:

  • The libphonenumber doesn't provide an API for generating valid phone numbers by default. Using getExampleNumber, you can only get one example for each type of phone number in each region.
  • The regexs from libphonenumber cannot be used as is due to errors inside them. For example, the problem with the premium rate phone numbers in Belarus has not yet been fixed.
  • Unnecessary duplication of patterns or parts of patterns in regions with the same country code. For example, the JE national part pattern for personal phone numbers (701511\d{4}) is a subset of the GB national part pattern for personal phone numbers (70\d{8}) in libphonenumber 8.13.5

Ok, fine, how to use it?

First, find out which version is needed by looking at VERSIONS.md.

‼️ The version of libphonenumber in your project SHOULD BE EQUAL to the version of libphonenumber in the raf library. Otherwise there is no guarantee that the generated phones will be correctly parsed by libphonenumber. Be very careful here! ‼️

Then, add the following dependency:

// rafVersion is the version that you found in the previous step
"io.github.mr-tolmach" %% "raf-generators" % rafVersion

Finally, use it in your code:

import io.github.mr_tolmach.generators.E164Generators
import io.github.mr_tolmach.metadata.model.Regions
import io.github.mr_tolmach.metadata.model.PhoneNumberTypes

// for scalatest + scalacheck property-based testing
forAll(E164Generators.phoneNumberGen(Regions.AW))(check)

// to generate valid phone numbers for the AC region with any type of phone number
E164Generators.phoneNumberGen(Regions.AC).sample

// to generate valid fixed-line phone numbers for the US region
E164Generators.phoneNumberGen(Regions.US, PhoneNumberTypes.FixedLine).sample

raf's People

Contributors

mr-tolmach avatar msinton 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.