• Home
Name Date Size #Lines LOC

..--

i18n/phonenumbers/12-May-2024-37,72330,556

README.mdD12-May-20243.4 KiB8454

build.xmlD12-May-20246.1 KiB146135

README.md

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
21If you don't checkout the dependencies next to libphonenumber:
22
231. Change the path of the `<script src="">` in the html pages to point to wherever base.js is located
242. Update `javascript/build.xml` with the correct paths
25
263. Run the unit tests to make sure everything is working. Open the following pages with your web browser:
27  `javascript/i18n/phonenumbers/phonenumberutil_test.html`
28  `javascript/i18n/phonenumbers/asyoutypeformatter_test.html`
29
304. Run the demo: `javascript/i18n/phonenumbers/demo.html`
31
32
33How to compile:
34===============
351. Build Closure's compiler.jar:
36  `mvn -DskipTests`
37
382. Compile the demo.js and all its dependencies to one file: `demo-compiled.js`:
39  `ant -f javascript/build.xml compile-demo`
40
413. Run the compiled demo: `javascript/i18n/phonenumbers/demo-compiled.html`
42
43
44How to use:
45===========
46To 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.
47
48
49How to update:
50==============
51The JavaScript library is ported from the Java implementation.
52When the Java project gets updated follow these steps to update the JavaScript
53project:
54
551. If the protocol buffers (phonemetadata.proto and phonenumber.proto) have changed:
56  * Manually update the .pb.js files with the changes of the .proto files.
57  * Manually update the toJsArray() Java methods in tools/java/java-build/src/com/google/i18n/phonenumbers/BuildMetadataJsonFromXml.java
58  * 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`
59
602. 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`:
61
62  `ant -f java/build.xml build-js-metadata`
63
643. Manually port any changes of the Java code to the JavaScript code:
65  * PhoneNumberUtil.java => phonenumberutil.js
66  * AsYouTypeFormatter.java => asyoutypeformatter.js
67  * PhoneNumberUtilTest.java => phonenumberutil_test.js
68  * AsYouTypeFormatterTest.java => asyoutypeformatter_test.js
69
704. Run the Closure Compiler to get your changes syntax and type checked. This will also generate `demo-compiled.js` used by `demo-compiler.html`
71
72  `ant -f javascript/build.xml compile`
73
745. Run the Closure Linter to lint the JavaScript files:
75
76  `ant -f javascript/build.xml lint`
77
78
79Missing functionality:
80=====
811. JS port does not support extracting phone-numbers from text (findNumbers).
822. JS port does not have an offline phone number geocoder.
833. JS port of PhoneNumberUtil does not handle all digits, only a subset (JavaScript has no equivalent to the Java Character.digit).
84