• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1Info:
2=====
3Google's JavaScript library for parsing, formatting, and validating
4international phone numbers.
5
6
7How to setup:
8=============
91.  Checkout closure-library, closure-compiler, closure-linter and python-gflags next to libphonenumber:
10
11* `git clone https://github.com/google/libphonenumber/`
12
13* `git clone https://github.com/google/closure-library/`
14
15* `git clone https://github.com/google/closure-compiler.git`
16
17* `git clone https://github.com/google/closure-linter.git`
18
19* `git clone https://github.com/google/python-gflags.git`
20
211.  We officially support only these versions of these dependencies:
22
23* Closure library: v20190415
24
25* Closure compiler: v20140407
26
27* Closure linter: v2.3.19
28
29* Python gflags: 3.1.2
30
31Note: We were to build at latest versions of these dependencies, however, we cannot promise that
32we continue to support newer version of these dependencies. We learned that newer Closure binaries
33deprecate older apis earlier, leading to build breakages.
34
35If you don't checkout the dependencies next to libphonenumber:
36
371. Change the path of the `<script src="">` in the html pages to point to wherever base.js is located
382. Update `javascript/build.xml` with the correct paths
39
403. Run the unit tests to make sure everything is working. Open the following pages with your web browser:
41  `javascript/i18n/phonenumbers/phonenumberutil_test.html`
42  `javascript/i18n/phonenumbers/asyoutypeformatter_test.html`
43
444. Run the demo: `javascript/i18n/phonenumbers/demo.html`
45
46
47How to compile:
48===============
491. Build the Closure Compiler JAR file by following the directions on the
50   [Closure Compiler README](https://github.com/google/closure-compiler/tree/master/README.md).
51   If this step doesn't work, try updating your local copy of each of the
52   repositories listed above before filing an issue.
53
542. Compile the demo.js and all its dependencies to one file: `demo-compiled.js`:
55  `ant -f javascript/build.xml compile-demo`
56
573. Run the compiled demo: `javascript/i18n/phonenumbers/demo-compiled.html`
58
59
60How to use:
61===========
62To use and compile the library in your own project, use the `javascript/i18n/phonenumbers/demo.js` as an example. You will need to goog.exportSymbol all the methods you use in your html so that the compiler won't rename them. You can then invoke the compiler similarly to how the compile-demo ant target in `javascript/build.xml` invokes it.
63
64
65How to update:
66==============
67The JavaScript library is ported from the Java implementation.
68When the Java project gets updated follow these steps to update the JavaScript
69project:
70
711. If the protocol buffers (phonemetadata.proto and phonenumber.proto) have changed:
72  * Manually update the .pb.js files with the changes of the .proto files.
73  * Manually update the toJsArray() Java methods in tools/java/java-build/src/com/google/i18n/phonenumbers/BuildMetadataJsonFromXml.java
74  * Build `tools/java/java-build/target/java-build-1.0-SNAPSHOT-jar-with-dependencies.jar` by running: `mvn -f tools/java/java-build/pom.xml package`
75
762. If the phone number metadata in the XML format has changed `resources/PhoneNumberMetadata.xml` run the following commands to regenerate `metadata.js` and `metadatafortesting.js`:
77
78  `ant -f java/build.xml build-js-metadata`
79
803. Manually port any changes of the Java code to the JavaScript code:
81  * PhoneNumberUtil.java => phonenumberutil.js
82  * AsYouTypeFormatter.java => asyoutypeformatter.js
83  * PhoneNumberUtilTest.java => phonenumberutil_test.js
84  * AsYouTypeFormatterTest.java => asyoutypeformatter_test.js
85
864. Run the Closure Compiler to get your changes syntax and type checked. This will also generate `demo-compiled.js` used by `demo-compiler.html`
87
88  `ant -f javascript/build.xml compile`
89
905. Run the Closure Linter to lint the JavaScript files:
91
92  `ant -f javascript/build.xml lint`
93
94
95Missing functionality:
96=====
971. JS port does not support extracting phone-numbers from text (findNumbers).
982. JS port does not have an offline phone number geocoder.
993. JS port of PhoneNumberUtil does not handle all digits, only a subset (JavaScript has no equivalent to the Java Character.digit).
100