catamphetamine / libphonenumber-js

A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript
https://catamphetamine.gitlab.io/libphonenumber-js/
MIT License
2.77k stars 218 forks source link

Difference between `parsePhoneNumber` and `parsePhoneNumberFromString` ? #411

Closed popod closed 3 years ago

popod commented 3 years ago

In the readme parsePhoneNumber and parsePhoneNumberFromString are used, but only parsePhoneNumberFromString is describe in the API section.

What is the difference between this two functions ?

I've done some tests and it seems that parsePhoneNumber need a try/catch block to catch errors and that parsePhoneNumberFromString return an empty response in case of error..

Thank you for reply

catamphetamine commented 3 years ago

There doesn't seem to be anywhere in the README where parsePhoneNumber named export is used.

popod commented 3 years ago

here for example : https://github.com/catamphetamine/libphonenumber-js#use

catamphetamine commented 3 years ago

It's not a named export

popod commented 3 years ago

Thank you for reply, but this is not clear..

import parsePhoneNumber from 'libphonenumber-js' seems to works the same as import parsePhoneNumberWithError from 'libphonenumber-js' but not like import parsePhoneNumberFromString from 'libphonenumber-js' ?

What does or how works : import parsePhoneNumber from 'libphonenumber-js' (this is not documented)

I think that this could be better explained in the doc ?

catamphetamine commented 3 years ago

You seem to be confusing "default" exports and "named" exports. https://medium.com/@etherealm/named-export-vs-default-export-in-es6-affb483a0910

popod commented 3 years ago

thank you for reply.. yes this is my bad.. I understand "default" and "named" exports.. but in my tests I'm using require..

const libphonenumber = require('libphonenumber-js')

libphonenumber.parsePhoneNumber() // seems to works like parsePhoneNumberWithError()
libphonenumber.parsePhoneNumberFromString()

This two functions doesn't works the same.. and this is because of that that I ask a parsePhoneNumber documentation.

But this is okey and all works when using import. Sorry for that !

catamphetamine commented 3 years ago

libphonenumber.parsePhoneNumber is a named import and is not covered in the README. It used to exist in legacy versions.