Coder Social home page Coder Social logo

phone-numbers's Introduction

Phone-Numbers

A library for handling phone numbers in Purescript. Given a countries name or ISO2, and an unformatted string containing a phone number, a formatted number can be produced.

Usage

format takes a Country and a string containing the phone number and outputs a Maybe String containing either the formatted phone number including the country code or Nothing. The unformatted phone number may include the country code either beginning with "00" or "+". Characters other than digits will be removed from the number and the function returns Nothing if the phone number doesn't consist of more than the country code.

    format Germany "30901820" == Just "+49 309 01820"
    
    format Germany "+4930901820" == Just "+49 309 01820"

    format Vietnam "0084 098432347" == Just "+84 098432347"

    format Vietnam "0084 0984 32 3- 4-7" == Just "+84 098432347"

    format Vietnam "0084" == Nothing

extractNums takes a String as an argument and returns a Just String containing only the digits if the argument contained digits, otherwise it returns Nothing.

    extractNums "+49 30 901820" == Just "4930901820"

stringToCountry takes a String and produces a Country. This can be used in combination with format:

    format  (stringToCountry "Germany") "30901820" == Just "+49 309 01820"

codeStringToCountry can be used in a similar manner using the desired country's ISO2 code as an argument. This can be used in combination with format:

    format  (codeStringToCountry "DE") "30901820" == Just "+49 309 01820"

Credits

The inspiration for this library came from react-phone-input

phone-numbers's People

Contributors

andreleblanc avatar

Watchers

James Cloos avatar  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.