GithubHelp home page GithubHelp logo

catamphetamine / libphonenumber-js Goto Github PK

View Code? Open in Web Editor NEW
2.8K 30.0 217.0 10.73 MB

A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript

Home Page: https://catamphetamine.gitlab.io/libphonenumber-js/

License: MIT License

JavaScript 98.10% Shell 0.06% Batchfile 0.02% HTML 1.81%
phone number

libphonenumber-js's Issues

The getNumberType function return undefined

I have generated full size metadata.json :

> libphonenumber-generate-metadata app/metadata.min.json --extended

Metadata path: /Users/chaofeis/beary/pensieve/app/metadata.min.json
Include extra validation regular expressions
========================================
=       Metadata has been updated      =
========================================

and I run below codes:

 node
> var lib = require('libphonenumber-js');
undefined
> lib.getNumberType('13453965555', 'CN');
undefined
> lib.getNumberType('13453965555', 'CN') === 'MOBILE';
false
> lib.getNumberType('13453965555', 'CN') === undefined;
true

metadata update error under node version >= 7.0.3

Hi,

Just caught an error while building custom metadata:

> [email protected] postinstall /Users/user/Documents/Projects/secret-frontend
> libphonenumber-generate-metadata ./app/js/utils/libs/libphonenumber-metadata.json --countries RU --extended

Metadata path: /Users/user/Documents/Projects/secret-frontend/app/js/utils/libs/libphonenumber-metadata.json
Included countries: [ 'RU' ]
Include extra validation regular expressions
/Users/user/Documents/Projects/secret-frontend/node_modules/libphonenumber-js/bin/update-metadata.js:43
download('https://raw.githubusercontent.com/googlei18n/libphonenumber/master/resources/PhoneNumberMetadata.xml')
^

TypeError: download is not a function
    at Object.<anonymous> (/Users/user/Documents/Projects/secret-frontend/node_modules/libphonenumber-js/bin/update-metadata.js:43:1)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:420:7)
    at startup (bootstrap_node.js:139:9)
    at bootstrap_node.js:535:3

Fixed by adding .default to imports in bin/update-metadata:

var download = require('../build/tools/download').default
var generate = require('../build/tools/generate').default
var compress = require('../build/tools/compress').default

Command was called as:
"postinstall": "libphonenumber-generate-metadata ./app/js/utils/libs/libphonenumber-metadata.json --countries RU --extended"

Node:

10:secret-frontend user$ node -v
v7.3.0
10:secret-frontend user$ npm -v
4.0.5

Thank you for this lib very much!

angular2 and SystemJS import

After installing through npm in my angular 2 app and updating my SystemJS config.ts to include

'libphonenumber-js': 'npm:angular-libphonenumber/index.es6.js'

and including
import { parse, format, asYouType } from 'libphonenumber-js'; in my @directive and @NgModule, I'm still getting "Cannot find module 'libphonenumber-js'"

Do I need to do anything else specific to install this into my ng2 app?

is valid with 0 prefix

First off, let me say i LOVE your library, it's so easy to use and works amazing well. Thank you a million times over.

Not sure what i am doing wrong but i want to know how to handle the use case when a number has a 0 in the national portion like so:

+33 0 6 12 34 56 78 === this validates as valid but it really is not and also it does not get formatted properly

the correct number is

+33 6 12 34 56 78 which this time gets returned properly as +33-6-12-34-56-78

with the 0 the format is not applied but funny enough in the as you type function it shows the number properly formatted with the 0 removed.

For now i found a bypass method wher i reconstruct the number like so and it works nicely but i figured i would give you a shout:

                                 var tempPhoneNumber = '+' + formatter.country_phone_code + parse(phoneNumber).phone

and then:

                                tempPhoneNumber = format(tempPhoneNumber, parse(tempPhoneNumber).country, 'International')
				
				var regEx = new RegExp(' ', 'g') //remove the space and replace with "-" dash
				tempPhoneNumber = tempPhoneNumber.replace(regEx, '-')

asYouType returning null

Repro steps:

console.log(new asYouType('US').input('12')

Expected Output:
(12 )

Actual Output:
(null) 2 -

Make customized metadata work for TypeScript + Angular4 + WebPack2

Hi,

I'm using your library for my application which is built using TS+Angular4+WebPack2. I could use the library with default metadata.min.json without any issues. But, I see some issues while using a customized metadata of the library.

Details:

  1. I generated the metadata.min.json file using "libphonenumber-metadata": "libphonenumber-generate-metadata metadata.min.json --types mobile" and "npm run libphonenumber-metadata".
  2. I created a new TS file, metadata.ts. I have attached the file (as a .txt version).
  3. When I try to use asYouType like, this.inputPhoneNumber = new asYouTypeCustom('US').input(this.inputPhoneNumber);
    TypeScript compiler is throwing the error, property 'input' doesn't exist on type 'asYouType'.
  4. To avoid the error, I modified the line to, this.inputPhoneNumber = new asYouTypeCustom('US').input(this.inputPhoneNumber);
    It resolved the issue mentioned in the above step. But, I know that is not what is expected.
  5. Now, I see console errors saying metadata is not passed to asYouType(). This is happening is because the metadata that got imported from 'metadata.json' doesn't have any value and it is undefined.

To sum it up, I have two issues. One is 'input' isn't available on asYouType and 'metadata' variable doesn't have any data after importing from the JSON.

I'm not sure whether I'm using the customized version properly or the code doesn't support TypeScript.
Can you please help me out to resolve my issue?

Attached two files, metadata.txt and phone-number.txt.
metadata.txt
phone-number.txt

Thank you in advance.

Local swedish mobile phone numbers breaks the as you type formatter

Whats wrong
Typing a local Swedish mobile phone number (with default country set to: SE) in the as you type formatter in the demo makes the caret move unexpectedly.

How to reproduce
Entering a valid local mobile phone number, for example the prefix 077 followed by 1234567. This leads to the number being formatted as 077-123 46 75. The 5 is in the end instead of after 4.

The caret seems to jump when the dash-character moves and the spacing changes as you type 5.

Expected behaviour
The number should be formatted as 077-123 45 67.

asYouType incorrectly formats some NZ numbers

The as-you-type formatter could return incorrect values for inputs with less than 5 digits.

new asYouType("NZ").input("0212") returns 02-12, which is incorrect as there is no 02 area code in NZ. Should return 021 2.

new asYouType("NZ").input("02122") returns 021 22, which is correct

Whereas google's as-you-type formatter will correctly return 021 2.

See https://en.wikipedia.org/wiki/List_of_dialling_codes_in_New_Zealand

Edit: similar thing happens when inputting +64212; returns +64 2 12, when it should be +64 21 2

libphonenumber.isValidNumber not wirking as expected

libphonenumber.isValidNumber(mobile_number, country_code) returns true for invalid numbers as well.

For example, i enetered
country_code - DE
mobile number : 1755892292222222222
function returns true as a result, is there something wrong in the library?

Failed running script liphonenumber-generate-metadata

Hi I'm trying to create a custom metadata but I get the following error:

`

root@ip-172-31-5-150:/home/ubuntu/libphonenumber-js# npm run-script libphonenumber-metadata

> [email protected] libphonenumber-metadata /home/ubuntu/libphonenumber-js
> libphonenumber-generate-metadata metadata.min.json --extended

sh: 1: libphonenumber-generate-metadata: not found

npm ERR! Linux 3.13.0-112-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run-script" "libphonenumber-metadata"
npm ERR! node v7.8.0
npm ERR! npm  v4.2.0
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! [email protected] libphonenumber-metadata: `libphonenumber-generate-metadata metadata.min.json --extended`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the [email protected] libphonenumber-metadata script 'libphonenumber-generate-metadata metadata.min.json --extended'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the libphonenumber-js package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     libphonenumber-generate-metadata metadata.min.json --extended
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs libphonenumber-js
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls libphonenumber-js
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /root/.npm/_logs/2017-03-29T23_04_03_471Z-debug.log
root@ip-172-31-5-150:/home/ubuntu/libphonenumber-js#`

Add a release

Hello,

If the lib is ready to use, could you release one?

Thank you

Cheers,

Parse doesn't detect KZ country

At the demo page:
The number +7 702 211 1111
AsYouType detects KZ correctly
Parse doesn't detect any country
Format doesn't detect any country

Use a CDN

Hello,

It would be nice to be able to use libphonenumber through a CDN (like cdnjs).

What do you think?

Brazilian numbers not recognized

The brazilians numbers are not recognize, unless a zero is added in the beggining of the input.
In the demo page, if I put the number 11987654321 with country as BR, that number is not recognized. But if I add the zero in the beggining, the number is recognized and formatted as expected.

Parse Options Issue

Your js version is fantastic so far, so thank you =) However, I'm running in to one issue where I'm trying to parse a phone number but don't want to force a country code. I'd like it to figure out based on what is typed. But when I create the options object and pass it in to parse, I get this error:

Uncaught TypeError: Cannot read property 'default' of undefined
at e (libphonenumber-js.min.js:1)
at new e (libphonenumber-js.min.js:4)

I've tried multiple ways to create an object with different values for your two fields:

var options = {};
options.restrict = '';
options.default = 'US';

Thanks, Mike

Invalid phone number when it should be valid

Hello,

I was running tests with australian numbers when I found that "413071810" is not valid if there's no "0" before it i.e. "0413071810"

I verified that Google's Javascript demo does recognize "413071810" as a valid number for Australia(AU) https://rawgit.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/demo-compiled.html

In Australia is normal to use "04" or "4" for mobile numbers. Also Safari autofill feature adds Australian mobile numbers without the zero that's how I found this problem.

libphonenumber-metadata not so clear

{
"scripts": {
"libphonenumber-metadata": "libphonenumber-generate-metadata metadata.min.json --countries RU,DE --extended",
}
}

when we add the script to package.json and run the command as explained, there is an error it is not generating the json with extended data

npm browser-build fails

When I build using npm for browser, I get the following error log. I can send over npm-debug.log if needed.

> [email protected] browser-build /home/divick/work/external/libphonenumber-js
> WEBPACK_ENV=build webpack

/home/divick/work/external/libphonenumber-js/node_modules/webpack/lib/Compiler.js:324
					content = Buffer.from(content, "utf8");
					                 ^

TypeError: utf8 is not a function
    at Function.from (native)
    at Function.from (native)
    at Compiler.writeOut (/home/divick/work/external/libphonenumber-js/node_modules/webpack/lib/Compiler.js:324:23)
    at Compiler.<anonymous> (/home/divick/work/external/libphonenumber-js/node_modules/webpack/lib/Compiler.js:312:20)
    at /home/divick/work/external/libphonenumber-js/node_modules/webpack/node_modules/async/dist/async.js:3025:16
    at eachOfArrayLike (/home/divick/work/external/libphonenumber-js/node_modules/webpack/node_modules/async/dist/async.js:941:9)
    at eachOf (/home/divick/work/external/libphonenumber-js/node_modules/webpack/node_modules/async/dist/async.js:991:5)
    at Object.eachLimit (/home/divick/work/external/libphonenumber-js/node_modules/webpack/node_modules/async/dist/async.js:3089:3)
    at Compiler.emitFiles (/home/divick/work/external/libphonenumber-js/node_modules/webpack/lib/Compiler.js:301:20)
    at /home/divick/work/external/libphonenumber-js/node_modules/mkdirp/index.js:48:26
    at FSReqWrap.oncomplete (fs.js:82:15)

npm ERR! Linux 3.13.0-37-generic
npm ERR! argv "/home/divick/.nvm/versions/node/v5.0.0/bin/node" "/home/divick/.nvm/versions/node/v5.0.0/bin/npm" "run" "browser-build"
npm ERR! node v5.0.0
npm ERR! npm  v3.3.6
npm ERR! code ELIFECYCLE
npm ERR! [email protected] browser-build: `WEBPACK_ENV=build webpack`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] browser-build script 'WEBPACK_ENV=build webpack'.
npm ERR! This is most likely a problem with the libphonenumber-js package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     WEBPACK_ENV=build webpack
npm ERR! You can get their info via:
npm ERR!     npm owner ls libphonenumber-js
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/divick/work/external/libphonenumber-js/npm-debug.log

How to prevent entering next digit if the longest number is achieved?

Hello!
Could you please advise me how to prevent entering next digit if the longest number is achieved for the given country?
I can not rely on the validation result, for small length, it returns false too.
Maximum lengths for a country are different, so I can not just set it to 15.

UK National 03xxxxxxx landline not valid

Tried to run this number through the parser and it is supposedly invalid however the google libphonenumber demo says it's ok: 03300 881288. Just to confirm, it is a valid phone number :) Interestingly, replacing the 03 with +443 satisfies the parser.

Unable to generate custom metadata with example script "scriptlibphonenumber-metadata"

Hey Nikolay

I followed the new docs for generating a set of custom metadata but the example script provided in the docs fails to execute with the following error: sh: libphonenumber-generate-metadata: command not found. This is the script I've included into the package.js: "libphonenumber-metadata": "libphonenumber-generate-metadata metadata.min.json --countries DE --extended",.

What works for me though is the following script: "libphonenumber-metadata": "node bin/update-metadata metadata.min.json --countries DE --extended",.

npm metadata:update script broken

As per the instructions in the README to update the Metadata from Google's repo, I executed

$ npm run metadata:update

This downloaded the latest XML file but the script failed when it checked how many files had been modified. See here.

The problem is that the update.js script executes metadata:generate which regenerates all the metadata files including min, full, and mobile. So when update.js checks how many files have been modified, it fails because too many have been changed.

The way I see it, there's 2 ways to fix this depending on what the intent of the update.js script is.

  • If ALL the metadata files should be regenerated then update.js should be updated to expect at most 4 files to be changed

    • PhoneNumberMetadata.xml
    • metadata.full.json
    • metadata.min.json
    • metadata.mobile.json
  • If only the XML and min metadata files should be updated then update.js should execute metadata:generate:min instead.

I don't mind submitting a PR with either one of these changes, just let me know which one it should be.

Error in installing dependencies

Facing issue while installing libphonenumber-js dependencies to update metadata.

me@:libphonenumber-js$ node -v
v6.9.4
me@:libphonenumber-js$ npm -v
3.10.10

Below is the error-

Executing script: build-commonjs-modules

to be executed: babel ./source --out-dir ./build --source-maps 
source/as you type.js -> build/as you type.js
source/common.js -> build/common.js
source/format.js -> build/format.js
source/metadata.js -> build/metadata.js
SyntaxError: source/parse.js: Unexpected token (216:14)
  214 |         if (!options)
  215 |         {
> 216 |                 options = { ...default_options }
      |                             ^
  217 |         }
  218 | 
  219 |         // Validate country codes

Proper usage for AsYouType formatter

Hello!

Thank you for this great module!

However, I'm trying to use AsYouType formatter in order to format user input in my Angular 2 application.

I'm creating an instance of asYouType with the input component and I can feed new numbers to it by listening to the keyup event of the input element: input.value = formatter.input(event.key); and it works great. But, when I press backspace it continues to render previous value, because it doesn't know about removed character. So, how do I tell it to actually remove one character?

The only workaround I've found so far is to create new instance of the formatter on each keyup event and to feed entire input value to it. It works flawlessly, but it's terrible from the design perspective and probably performance (creating a new instance of the object and calling a function on it is probably a serious overkill).

How do I use it correctly and at the same time achieve better design and performance?

Thanks!

Inconsistency between isValidNumber and the valid property of asYouType

Hey!

First of all thank you for providing this alternative to the official library provided by Google.

isValidNumber() returns true for the invalid german phone number '123456' while the valid property of asYouType returns false as expected/desired. isValidNumber() uses parse() internally which strips the national prefix.

If this behavior is desired then I believe it must be documented more clearly in the README.md.

Some countries are missing

I was trying to use the getPhoneCode method for Bulgaria (country code 'BU') and the library have failed with an error breaking the page.

 error      TypeError: Cannot read property '0' of undefined
    at get_phone_code (eval at <anonymous> (), <anonymous>:31:25)
    at getPhoneCodeCustom (eval at <anonymous> (), <anonymous>:107:101)
    at Object.getPhoneCode [as a] (eval at <anonymous> (), <anonymous>:102:9)

I have noticed that the https://github.com/halt-hammerzeit/libphonenumber-js/blob/master/metadata.min.json does not include BU as a country.

I could go and regenerate the metadata file to get that country code from the Google library, but I think it would be nicer to have some kind of handling country codes that are not supported in a better way. Some examples are :

  1. Make the function return undefined
  2. Make the function throw an error with a message "BU is not a supported country"

Metadata loading fails

I'm trying to load the library like this: import { parse, format } from 'libphonenumber-js'; and gives me an error during build.

ERROR in ./~/libphonenumber-js/metadata.min.json
Module parse failed: ./node_modules/libphonenumber-js/metadata.min.json Unexpected token (1:34)
You may need an appropriate loader to handle this file type.

I'm using ES6+, babel and Vue 2 with Laravel as framework

Country names

do we get the country names along with the country codes?

Question: Is it possible to specify that you only want mobile numbers (without loading all other types via extend)?

Hi,

I'd like to only accept mobile numbers as input.
In the old libphonenumber code, I was checking through all the types, and only accepting the number if it was a mobile number. I could do the same with your library, but as you say, the resulting file size is considerably bigger if you want to support "number types".
My question is whether the library could be extended to to generate the metadata only for mobile number types, e.g. with flags as follows: --countries DE --number_types mobile
Then when parsing a number, and calling get_number_type, non-mobile numbers would report a type of "unknown" and valid mobile numbers would return type "mobile". I would assume there would be a size saving over using --extended option (which supports all phone number types).

If you have advice on how to achieve this, it would be greatly appreciated.

Thanks
Rob

invalid format Ghana phone numbers

numbers like this:
233111111111
it formats like:
233 233111111111

//test
import { format } from 'libphonenumber-js'

it('Ghana phone',()=>{
const phone = format('233111111111', 'GH', 'International')
expect(phone).toBe('+233111111111')
})

Consider documenting required webpack configuration

libphonenumbers-js needs:

  • the JSON loader: {test: /\.json$/, loader: 'json'} in config.module.rules

  • '.json' in config.resolve.extensions (perhaps it would be easier to just reference the data file with the full name .min.json)

Note -- this is a webpack2 configuration.

npm browser-build fails

When I build using npm for browser, I get the following error log. I can send over npm-debug.log if needed.
I tried installing various version of node/npm version combinations (including the latest).

[email protected] browser-build \JS_LIB\libphonenumber-js
npm run build-es6-modules && WEBPACK_ENV=build webpack

[email protected] build-es6-modules \JS_LIB\libphonenumber-js
better-npm-run build-es6-modules

running better-npm-run in \JS_LIB\libphonenumber-js
Executing script: build-es6-modules

to be executed: "babel ./source --out-dir ./es6 --source-maps"
source\as you type.js -> es6\as you type.js
source\common.js -> es6\common.js
source\format.js -> es6\format.js
source\metadata.js -> es6\metadata.js
source\parse.js -> es6\parse.js
source\tools\compress.js -> es6\tools\compress.js
source\tools\download.js -> es6\tools\download.js
source\tools\generate.js -> es6\tools\generate.js
source\validate.js -> es6\validate.js
'WEBPACK_ENV' is not recognized as an internal or external command,
operable program or batch file.

npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\Program Files\nodejs\node.exe" "AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js" "run" "browser-build"
npm ERR! node v5.10.1
npm ERR! npm v3.8.3
npm ERR! code ELIFECYCLE
npm ERR! [email protected] browser-build: npm run build-es6-modules && WE BPACK_ENV=build webpack
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] browser-build script 'npm run bui
ld-es6-modules && WEBPACK_ENV=build webpack'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the libphonenumber-js pac
kage,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! npm run build-es6-modules && WEBPACK_ENV=build webpack
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs libphonenumber-js
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls libphonenumber-js
npm ERR! There is likely additional logging output above.

Issue with Reunion

Hello again,

i hope i am not doing anything wrong, but i see nothing for reunion in 262 country code, is the issue just on my side?

getNumberType always return undefined for Indonesia Phone Number

Hi,
I try to check whether my input is an Indonesia Phone Number or not by using getNumberType function, but i always get "undefined" although I input my correct phone number,
Any idea or suggestion is really appreciated.

const numberType = getNumberType(value, 'ID');
  if( numberType !== 'MOBILE'){
    return errorMessage;
  }

bundle/browser build gives error `libphonenumber is not defined`

I'm trying to use this in the browser on codepen.io, but when I try to use the library with libphonenumber-js, it gives me an error Uncaught RferenceError: libphonenumber is not defined. It works if I instead do window['libphonenumber-js'].asYouType.

The name libphonenumber-js is a strange name to use in browser javascript. I get that it works well with es6 imports import {asYouType} from 'libphonenumber-js';; is there any way to support LibPhoneNumberJS in the browser build?

Problems in IE 11

Hi,
first, thanks for developing on this great library ;).

I detected a problem in Internet Explorer 11:
I get the following error if my App starts:

Unhandled rejection Error: Nicht genügend Stackspeicher.
   at __symbol:iterator0.51182658601296831.set (http://localhost/HelpdeskApp/assets/vendor.js:83134:12)
   at __symbol:iterator0.51182658601296831.set (http://localhost/HelpdeskApp/assets/vendor.js:83134:12)
   at __symbol:iterator0.51182658601296831.set (http://localhost/HelpdeskApp/assets/vendor.js:83134:12)
   at __symbol:iterator0.51182658601296831.set (http://localhost/HelpdeskApp/assets/vendor.js:83134:12)
   at __symbol:iterator0.51182658601296831.set (http://localhost/HelpdeskApp/assets/vendor.js:83134:12)
   at __symbol:iterator0.51182658601296831.set (http://localhost/HelpdeskApp/assets/vendor.js:83134:12)
   at __symbol:iterator0.51182658601296831.set (http://localhost/HelpdeskApp/assets/vendor.js:83134:12)
   at __symbol:iterator0.51182658601296831.set (http://localhost/HelpdeskApp/assets/vendor.js:83134:12)
   at __symbol:iterator0.51182658601296831.set (http://localhost/HelpdeskApp/assets/vendor.js:83134:12)
   at __symbol:iterat

This only happens in IE, not in Chrome. I think is is a problem with the metadata.min.json which cannot be handled or loaded from IE. Maybe it's too big.

I use Webpack 1 for Bundling the application.

Thanks for your investigation.

Loader Problem

screenshot 2017-01-10 17 53 57

I am just importing parse and asyoutype!
And this is the error I get while compiling!
I have added json-loader as suggested but still the problem persists!

Some GB numbers showing invalid

This is a number I stumbled across while testing, it's for the Park Plaza Westminster Bridge London hotel and it shows as invalid

isValidNumber('+44 844 415 6790', 'GB') == false

Different output when parsing

Hello,

I tried to check the validity of +33169454850 like this:

var libphonenumber = window['libphonenumber-js'];
document.body.innerText = libphonenumber.isValidNumber('+33169454850');

demo

And got "false", but "true" when I try on the official project demo.

What did I miss?

Thank you!

The bundle folder for libphonenumber-js.min.js not created when running "npm run browser-build"

I've given it another try but the "bundle" folder is not created after running command: npm run browser-build
No error though. Just be sure, I'm trying to generate the standalone libphonenumber-js.min.js file.

Here a CMD extract:

C:\JS_LIB02\libphonenumber-js>npm run browser-build

[email protected] browser-build C:\JS_LIB02\libphonenumber-js
better-npm-run browser-build

running better-npm-run in C:\JS_LIB02\libphonenumber-js
Executing script: browser-build

to be executed: "npm run build-es6-modules"

[email protected] build-es6-modules C:\JS_LIB02\libphonenumber-js
better-npm-run build-es6-modules

running better-npm-run in C:\JS_LIB02\libphonenumber-js
Executing script: build-es6-modules

to be executed: "babel ./source --out-dir ./es6 --source-maps"
source\as you type.js -> es6\as you type.js
source\common.js -> es6\common.js
source\format.js -> es6\format.js
source\metadata.js -> es6\metadata.js
source\parse.js -> es6\parse.js
source\tools\compress.js -> es6\tools\compress.js
source\tools\download.js -> es6\tools\download.js
source\tools\generate.js -> es6\tools\generate.js
source\validate.js -> es6\validate.js

C:\JS_LIB02\libphonenumber-js>

Return also country_phone_code from parse

First of all, thanks for the nice library!

One small improvement came into my mind: why not return also country_phone_code from parse(), i.e. instead of:

let parse = require('libphonenumber-js').parse
parse('+358401234567')
// { country: 'FI', phone: '401234567' }
parse('0401234567', 'FI')
// { country: 'FI', phone: '401234567' }

we'd get this:

let parse = require('libphonenumber-js').parse
parse('+358401234567')
// { country: 'FI', phone: '401234567', country_phone_code: '358' }
parse('0401234567', 'FI')
// { country: 'FI', phone: '401234567', country_phone_code: '358' }

Ok, I am aware that you could do it with asYouType:

let asYouType = require('libphonenumber-js').asYouType
let formatter = new asYouType()
formatter.input('+358401234567')
// '+358 40 1234567'
formatter.country
// 'FI'
formatter.country_phone_code
// '358'
formatter.national_number
// '401234567'

but for me it would make sense to include the country_phone_code also to parse() result.

If you feel this would be a welcome addition to the library, I'm more than happy to provide a pull request that would provide this functionality!

Issue with asYouType and invalid phone numbers

Hi there, I've been using this library in my project and it's been working great. Thanks for making it available.

There's however one issue with the asYouType functionality that I have not been able to work around.

If I enter a sequence of digits followed by a plus sign (e.g. 1234+) the formatter returns just the numbers (1234). Then any subsequent digit entered will result in an empty string (1234+5 => empty)

My expectation is that the moment the input starts looking like an invalid number, the formatter should just return the original input. At least this is how the dialpad on iPhone works.

Some questions

Hi @halt-hammerzeit,
first, thank you that you are working on this library!!

I've some questions to you:

  • The files inside source/tools seems to be helper scripts and not part of the library at runtime, right?
  • This means that "bluebird", "minimist" and "xml2js" should be devDependencies?
  • Do you think, that there's a way that babel-runtime does not become a runtime dependency? (I use this lib in a typescript project without any dependencies to babel)
  • Is it possible to split the metadata.min.json to single json files for each supported language to reduce the bundle size in projects which use this library?

General:

  • bin/update-metadata.js and the contents of runnable seems to be helper scripts too?
  • There are different Promise implementations used (native in download.js, Bluebird in generate.js)

Thanks!!

Add findNumbers functionality from libphonenumber

Hi,
we are currently using this awesome port for parsing and formatting phone numbers.
Is there a plan to also implement the findNumbers functionality from libphonenumber?

I can help with implementing if that's on the plan... 🍻

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.