question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exposing `PhoneNumberType` similar to google-libphonenumber

See original GitHub issue

We use google’s exported PhoneNumberType in a project I work on. We’d like to replace google’s large library with yours but it does not expose this property.

google-libphonenumber has an exported enum:

export enum PhoneNumberType {
    FIXED_LINE = 0,
    MOBILE = 1,
    FIXED_LINE_OR_MOBILE = 2,
    TOLL_FREE = 3,
    PREMIUM_RATE = 4,
    SHARED_COST = 5,
    VOIP = 6,
    PERSONAL_NUMBER = 7,
    PAGER = 8,
    UAN = 9,
    VOICEMAIL = 10,
    UNKNOWN = -1
}

Steps to reproduce

  1. Try importing NumberType from libphonenumber-js.

Observed result

Import is not the same as google-libphonenumber since NumberType in libphonenumber-js is just the typescript type and not a concrete value.

Expected result

libphonenumber-js should expose the phone number types as an array, map, or enum etc…

I can try to create a PR if necessary. Thanks for looking into this.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
catamphetaminecommented, Sep 22, 2020

Hmm, I guess we could export that. Something like:

export enum PhoneNumberType {
    FIXED_LINE = 'FIXED_LINE',
    MOBILE = 'MOBILE',
    FIXED_LINE_OR_MOBILE = 'FIXED_LINE_OR_MOBILE',
    TOLL_FREE = 'TOLL_FREE',
    PREMIUM_RATE = 'PREMIUM_RATE',
    SHARED_COST = 'SHARED_COST',
    VOIP = 'VOIP',
    PERSONAL_NUMBER = 'PERSONAL_NUMBER',
    PAGER = 'PAGER',
    UAN = 'UAN',
    VOICEMAIL = 'VOICEMAIL',
    UNKNOWN = 'UNKNOWN'
}

Would that work?

0reactions
maurer2commented, Jun 11, 2021

Hello, I believe this issue could be solved using const assertion in typescript 3.4+.

export const numberTypes = ['PREMIUM_RATE', 'TOLL_FREE', 'SHARED_COST', 'VOIP', 'PERSONAL_NUMBER', 'PAGER', 'UAN', 'VOICEMAIL', 'FIXED_LINE_OR_MOBILE', 'FIXED_LINE', 'MOBILE'] as const
export type NumberType = typeof numberTypes[number]

NumberType basically stays the same but is now derived from a readonly tuple. numberTypes can be exported and iterated over as proposed in https://github.com/catamphetamine/libphonenumber-js/issues/392#issuecomment-696700234.

Cheers

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using libphonenumber for International Phone Numbers
Libphonenumber is Google's formatting, parsing, and validation tool for international phone numbers. Learn how to use it in your global apps ...
Read more >
libphonenumber/PhoneNumberUtilTest.java at master - GitHub
Google's common Java, C++ and JavaScript library for parsing, formatting, and validating international phone numbers.
Read more >
How to use the google-libphonenumber.PhoneNumberType ...
To help you get started, we've selected a few google-libphonenumber.PhoneNumberType examples, based on popular ways it is used in public projects.
Read more >
google-libphonenumber - npm
Google's libphonenumber is a library that parses, formats, stores and validates international phone numbers. It is used by Android since ...
Read more >
Scheduled Calls Documentation - Setup & Data Integration
The LibPhoneNumber library exposes a subset of the google-libphonenumber library ... PhoneNumberType, PhoneNumberFormat, PhoneNumberUtil } = LibPhoneNumber; ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found