libphonenumber standalone (without masses of google dependencies)? Alternate lib?
Asked Answered
C

4

46

I am looking at using http://code.google.com/p/libphonenumber/ for a well-established project. Today the project does not use Google's libraries for JavaScript, favoring jQuery, jQueryUI, requirejs, and so on.

libphonenumber looks awesome ... except that the javascript version (svn co http://libphonenumber.googlecode.com/svn/trunk/javascript/ libphonenumber-js) is laced with goog.require calls. If one runs the demo (libphonenumber-js/i18n/phonenumbers/demo.html if you checked out as suggested) it pulls in tons of google libraries from closure-library.googlecode.com :

GET base.js
GET deps.js
GET error.js
GET string.js
GET asserts.js
GET array.js
GET useragent.js
GET browserfeature.js
GET tagname.js
GET classes.js
GET math.js
GET coordinate.js
GET size.js
GET object.js
GET dom.js
GET json.js
GET util.js
GET descriptor.js
GET fielddescriptor.js
GET message.js
GET serializer.js
GET objectserializer.js
GET stringbuffer.js
GET lazydeserializer.js
GET pbliteserializer.js

I believe if I compile this using the closure compiler ("If you give the use_closure_library parameter a value of true, the compiler looks for goog.require() statements in the source code and supplies the Closure Library code requested by any such statements.", https://developers.google.com/closure/compiler/docs/api-ref) I can cut down the raw number of requests, but this still seems like a rather excessive amount of content for a phone number parser, even a full-featured one.

My question has two possible answers:

  1. A way to use libphonenumber in JavaScript without having to pull in all the Google JavaScript base libraries
  2. An alternate standalone (as in doesn't have dozens of dependencies) first-class phone number processing library with both JavaScript and Java implementations

Any and all suggestions most appreciated.

Culdesac answered 17/7, 2012 at 17:48 Comment(1)
I stumbled across this answer and thought you might like it as well (should you still need it).Jonahjonas
F
9

I've got a custom build (currently 220KB) that I use for my International Telephone Input plugin, with plenty of helper functions exposed. Read the source for details.

Flyback answered 28/9, 2014 at 5:50 Comment(0)
T
5

You can also use my lib. https://github.com/Gilshallem/phoneparser

Its only got one method but you can do a lot with it

parsePhone("12025550104");
result: { countryCode:1, areaCode:202, number:5550104, countryISOCode:"US" }
Thunderstorm answered 1/7, 2014 at 10:15 Comment(2)
Thanks, that more helpful for validation purpose. The only problem, that it overwrites i18n, had to make a change in plugin(Friarbird
Why did you GPL that library when the libphonenumber you based it on uses the apache license?Signpost
A
3

Here are two implementations of Google libphonenumber in JavaScript that have zero dependencies and are implemented in a single file. I've used Nathan Hammond's version without issue but it is not on NPM. Rui Marinho's version is on NPM.

Alexaalexander answered 13/3, 2018 at 10:24 Comment(0)
H
1

I just spent 2 days figuring this out. For now, anyway, you can download a minified version of libphonenumber-js from here

drop it in place, with the usual

<script type="text/javascript" language="javascript" src="/static/js/libphonenumber-js.min.js"></script>

and get busy coding!

<script>
    $(".phone-format").keyup(function () {
            var val_old = $(this).val();
            var newString = new libphonenumber.AsYouType('US').input(val_old);
            $(this).focus().val('').val(newString);
    });
</script>
Harrisonharrod answered 10/8, 2018 at 21:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.