Giter Club home page Giter Club logo

numbering-plan's Introduction

CircleCI

numbering-plan

This library helps you migrate exiting phone numbers format to new phone number formats.

Usage

First you start by defining the migration rules for you country

val ivoryCoastPlanFactory: CountryPlan = CountryPlan.Builder()
    .setOldPhoneNumberSize(8)
    .setInternationalCallingCode("225")
    .setDigitMapperPosition(Position.START) // Position.END
    .setMigrationType(MigrationType.PREFIX) // MigrationType.POSTFIX
    .setPrefixesMapper(
      mapOf(
        "07" to "07", // Orange
        "08" to "07", // eg: 08 XX XX XX => 07 08 XX XX XX (if MigrationType.prefix is used) => 08 XX XX XX 07 (if MigrationType.postfix is used)
        "09" to "07",
        "04" to "05", // MTN
        "05" to "05",
        "06" to "05",
        "01" to "01", // MOOV
        "02" to "01",
        "03" to "01"
      )
    ).build()

Then you pass those rules to NumberingPlan and you can start the migration:

val ivoryCoastPlanFactory: CountryPlan = ...
val numberingPlan = NumberingPlan(ivoryCoastPlanFactory)
val newPhoneNumbers = numberingPlan.migrate(mapOf(
  "userId-1" to listOf("08060709"),
  "userId-2" to listOf("06060709"),
  "userId-6" to listOf("zezae/03-060-701", "01020304"),
  "userId-3" to listOf("03060701"),
  "userId-4" to listOf(" 03 060 701 "),
  "userId-5" to listOf(" 03-060-701"),
  "userId-7" to listOf(")'.03-060-701")
))

After the migration newPhoneNumbers will be equal to:

mapOf(
  "userId-1" to listOf("002250708060709"),
  "userId-2" to listOf("002250506060709"),
  "userId-6" to listOf("", "002250101020304"),
  "userId-3" to listOf("002250103060701"),
  "userId-4" to listOf("002250103060701"),
  "userId-5" to listOf("002250103060701"),
  "userId-7" to listOf("")
)

Invalid phone numbers are replaced by empty string.

Download

Download the latest JAR or grab via Gradle:

implementation 'com.ouattararomuald:numbering:2.0.1'

or Maven:

<dependency>
  <groupId>com.ouattararomuald</groupId>
  <artifactId>numbering</artifactId>
  <version>2.0.1</version>
</dependency>

Snapshots of the development version are available in Sonatype's snapshots repository.

Known limitations

  • Migrates only valid phone numbers.
  • Can add new digits before or after the old phone number. We decided to not handle in between insertions.
  • Can only look for digits to replace at the start, or the end of old phone numbers. We think this shouldn’t be a problem (generally) but as of now we decided to not handle such cases.
  • It is synchronous. This is a choice that will let you pick the any library you want to handle async tasks.

Contributing

Contributions you say? Yes please!

Bug report?

If at all possible, please attach a minimal sample project or code which reproduces the bug. Screenshots are also a huge help if the problem is visual.

Send a pull request!

If you're fixing a bug, please add a failing test or code that can reproduce the issue.

License

Copyright 2020 Ouattara Gninlikpoho Romuald

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

numbering-plan's People

Contributors

ouattararomuald avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

numbering-plan's Issues

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.