Javascript libphonenumber[Js]仅获取国家代码

Javascript libphonenumber[Js]仅获取国家代码,javascript,node.js,parsing,libphonenumber,Javascript,Node.js,Parsing,Libphonenumber,我在用这个 我的问题是: // Get an instance of `PhoneNumberUtil`. var phoneUtil = require('googlelibphonenumber').PhoneNumberUtil.getInstance(); phoneUtil.parse('+44') // throws exception phoneUtil.parse('+44234') // gives me an object to work with 我需要能够解析一个是

我在用这个

我的问题是:

// Get an instance of `PhoneNumberUtil`. 
var phoneUtil = require('googlelibphonenumber').PhoneNumberUtil.getInstance();

phoneUtil.parse('+44') // throws exception
phoneUtil.parse('+44234') // gives me an object to work with
我需要能够解析一个是否完整的数字。在最坏的情况下,它将是国家代码。在这种情况下,我希望能够得到国家的支持


有没有办法做到这一点?API没有很好的文档记录,我只是在查看源代码的同时尝试REPL。

你不能总是找到给定电话代码的国家,因为,比如说,美国和加拿大都有
1
代码

对于不完整的数字,您可以尝试使用
asyotype
,然后访问
.country
属性,如下所述:


尝试了一段时间后,我们决定采用另一种解决方案。尽管如此,我认为您的答案是正确的:我也在使用
asyotype
方法执行检查