SB-6.1-PRE
This commit is contained in:
1 parent
690169a409
commit
358a25f522
3760 files changed
+300059
-36
No files matched your search
+1
@@ -0,0 +1 @@
|
||||
github: ruimarinho
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
tags:
|
||||
- '*'
|
||||
pull_request:
|
||||
branches:
|
||||
- '*'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Run Tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 10
|
||||
- run: npm install
|
||||
- run: npm test
|
||||
publish:
|
||||
name: Publish Release
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 10
|
||||
registry-url: https://registry.npmjs.org/
|
||||
- run: npm install
|
||||
- run: npm publish
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
- uses: actions/create-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ github.ref }}
|
||||
release_name: ${{ github.ref }}
|
||||
body: |
|
||||
## Changelog
|
||||
draft: true
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
This package is licensed under MIT:
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Rui Marinho
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
--------
|
||||
|
||||
The bundled Google Closure Library is licensed under Apache 2.0:
|
||||
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
+345
@@ -0,0 +1,345 @@
|
||||
# google-libphonenumber
|
||||
|
||||
The up-to-date and reliable Google's libphonenumber package for node.js. Zero dependencies.
|
||||
|
||||
## Status
|
||||
|
||||
[![npm version][npm-image]][npm-url]
|
||||
[![build status][travis-image]][travis-url]
|
||||
[![install size][packagephobia-image]][packagephobia-url]
|
||||
|
||||
## Introduction
|
||||
|
||||
Google's [libphonenumber](https://github.com/googlei18n/libphonenumber) is a library that parses, formats, stores and validates international phone numbers. It is used by Android since version 4.0 and is a phenomenal repository of carrier metadata.
|
||||
|
||||
Although it compiles down to Java, C++ and JS, its JS port is tightly coupled to the Google Closure library. This makes it more difficult to directly require and use the code on a node.js project.
|
||||
|
||||
Google eventually started publishing [google-closure-library](https://www.npmjs.com/package/google-closure-library) directly to NPM, ending years of ill-maintained community packages. However, running the original library on node.js [remains a cumbersome process](https://github.com/googlei18n/libphonenumber/tree/master/javascript).
|
||||
|
||||
After all these years, Google's libphonenumber is still not officially available on NPM. What is the best way to use Google's libphonenumber on node.js then? If you're looking for a convenient and easy method, that's what this package is all about.
|
||||
|
||||
## Installation
|
||||
|
||||
Install the package via `npm`:
|
||||
|
||||
```sh
|
||||
npm install --save-prod google-libphonenumber
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
The following is a simple phone information extraction example similar to what can be viewed on the official demo page.
|
||||
|
||||
⚠️ _Most libphonenumber functions expect to receive an instance of `libphonenumber.PhoneNumber` which can be obtained by calling `phoneUtil.parse` or `phoneUtil.parseAndKeepRawInput` on a raw (string) number, otherwise it will throw errors like `TypeError: a.getCountryCodeOrDefault is not a function`._
|
||||
|
||||
This **will** work:
|
||||
|
||||
```js
|
||||
phoneUtil.isValidNumberForRegion(phoneUtil.parse('202-456-1414', 'US'), 'US');
|
||||
```
|
||||
|
||||
This **will not** work:
|
||||
|
||||
```js
|
||||
phoneUtil.isValidNumberForRegion('202-456-1414', 'US');
|
||||
```
|
||||
|
||||
More API examples after parsing the raw string:
|
||||
|
||||
```js
|
||||
// Require `PhoneNumberFormat`.
|
||||
const PNF = require('google-libphonenumber').PhoneNumberFormat;
|
||||
|
||||
// Get an instance of `PhoneNumberUtil`.
|
||||
const phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();
|
||||
|
||||
// Parse number with country code and keep raw input.
|
||||
const number = phoneUtil.parseAndKeepRawInput('202-456-1414', 'US');
|
||||
|
||||
// Print the phone's country code.
|
||||
console.log(number.getCountryCode());
|
||||
// => 1
|
||||
|
||||
// Print the phone's national number.
|
||||
console.log(number.getNationalNumber());
|
||||
// => 2024561414
|
||||
|
||||
// Print the phone's extension.
|
||||
console.log(number.getExtension());
|
||||
// =>
|
||||
|
||||
// Print the phone's extension when compared to i18n.phonenumbers.CountryCodeSource.
|
||||
console.log(number.getCountryCodeSource());
|
||||
// => FROM_DEFAULT_COUNTRY
|
||||
|
||||
// Print the phone's italian leading zero.
|
||||
console.log(number.getItalianLeadingZero());
|
||||
// => false
|
||||
|
||||
// Print the phone's raw input.
|
||||
console.log(number.getRawInput());
|
||||
// => 202-456-1414
|
||||
|
||||
// Result from isPossibleNumber().
|
||||
console.log(phoneUtil.isPossibleNumber(number));
|
||||
// => true
|
||||
|
||||
// Result from isValidNumber().
|
||||
console.log(phoneUtil.isValidNumber(number));
|
||||
// => true
|
||||
|
||||
// Result from isValidNumberForRegion().
|
||||
console.log(phoneUtil.isValidNumberForRegion(number, 'US'));
|
||||
// => true
|
||||
|
||||
// Result from getRegionCodeForNumber().
|
||||
console.log(phoneUtil.getRegionCodeForNumber(number));
|
||||
// => US
|
||||
|
||||
// Result from getNumberType() when compared to i18n.phonenumbers.PhoneNumberType.
|
||||
console.log(phoneUtil.getNumberType(number));
|
||||
// => FIXED_LINE_OR_MOBILE
|
||||
|
||||
// Format number in the E164 format.
|
||||
console.log(phoneUtil.format(number, PNF.E164));
|
||||
// => +12024561414
|
||||
|
||||
// Format number in the original format.
|
||||
console.log(phoneUtil.formatInOriginalFormat(number, 'US'));
|
||||
// => (202) 456-1414
|
||||
|
||||
// Format number in the national format.
|
||||
console.log(phoneUtil.format(number, PNF.NATIONAL));
|
||||
// => (202) 456-1414
|
||||
|
||||
// Format number in the international format.
|
||||
console.log(phoneUtil.format(number, PNF.INTERNATIONAL));
|
||||
// => +1 202-456-1414
|
||||
|
||||
// Format number in the out-of-country format from US.
|
||||
console.log(phoneUtil.formatOutOfCountryCallingNumber(number, 'US'));
|
||||
// => 1 (202) 456-1414
|
||||
|
||||
// Format number in the out-of-country format from CH.
|
||||
console.log(phoneUtil.formatOutOfCountryCallingNumber(number, 'CH'));
|
||||
// => 00 1 202-456-1414
|
||||
```
|
||||
|
||||
#### Using the "As You Type" Formatter
|
||||
|
||||
The "As You Type" formatter is a specialized tool that show the formatting *progress* as it attempts to discover the right format for the given number. It requires registering every keystroke (input digit) on a new instance of the `AsYouTypeFormatter` as shown below.
|
||||
|
||||
```js
|
||||
// Require `AsYouTypeFormatter`.
|
||||
const AsYouTypeFormatter = require('google-libphonenumber').AsYouTypeFormatter;
|
||||
const formatter = new AsYouTypeFormatter('US');
|
||||
|
||||
console.log(formatter.inputDigit('2')); // => 2
|
||||
console.log(formatter.inputDigit('0')); // => 20
|
||||
console.log(formatter.inputDigit('2')); // => 202
|
||||
console.log(formatter.inputDigit('-')); // => 202-
|
||||
console.log(formatter.inputDigit('4')); // => 202-4
|
||||
console.log(formatter.inputDigit('5')); // => 202-45
|
||||
console.log(formatter.inputDigit('6')); // => 202-456
|
||||
console.log(formatter.inputDigit('-')); // => 202-456-
|
||||
console.log(formatter.inputDigit('1')); // => 202-456-1
|
||||
console.log(formatter.inputDigit('4')); // => 202-456-14
|
||||
console.log(formatter.inputDigit('1')); // => 202-456-141
|
||||
console.log(formatter.inputDigit('4')); // => 202-456-1414
|
||||
|
||||
// Cleanup all input digits from instance.
|
||||
formatter.clear();
|
||||
```
|
||||
|
||||
## Methods
|
||||
|
||||
A quick glance at Google's libphonenumber rich API. Descriptions sourced from original files.
|
||||
|
||||
### i18n.phonenumbers.PhoneNumberUtil
|
||||
|
||||
The class that offers the main utilities to work with phone numbers, such as formatting, parsing and validating.
|
||||
|
||||
Highlights:
|
||||
|
||||
* **format(number, numberFormat)** - formats a phone number in the specified format using default rules.
|
||||
* **formatInOriginalFormat(number, regionCallingFrom)** - formats a phone number using the original phone number format that the number is parsed from.
|
||||
* **formatOutOfCountryCallingNumber(number, regionCallingFrom)** - formats a phone number for out-of-country dialing purposes.
|
||||
* **getNumberType(number)** - gets the type of a valid phone number.
|
||||
* **getRegionCodeForNumber(number)** - returns the region where a phone number is from.
|
||||
* **isPossibleNumber(number)** - returns true if the number is either a possible fully-qualified number (containing the area code and country code), or if the number could be a possible local number (with a country code, but missing an area code).
|
||||
* **isValidNumber(number)** - tests whether a phone number matches a valid pattern.
|
||||
* **isValidNumberForRegion(number, regionCode)** - tests whether a phone number is valid for a certain region.
|
||||
* **parseAndKeepRawInput(numberToParse, defaultRegion)** - parses a string and returns it in proto buffer format while keeping the raw input value.
|
||||
* **parse(numberToParse, defaultRegion)** - parses a string and returns it in proto buffer format.
|
||||
|
||||
### i18n.phonenumbers.PhoneNumber
|
||||
|
||||
The type of the phone returned after a string number has been parsed via `PhoneNumberUtil.parse()` or `PhoneNumberUtil.parseAndKeepRawInput()`.
|
||||
|
||||
Highlights:
|
||||
|
||||
* **getCountryCode()**
|
||||
* **getCountryCodeSource()**
|
||||
* **getExtension()**
|
||||
* **getItalianLeadingZero()**
|
||||
* **getNationalNumber()**
|
||||
* **getRawInput()**
|
||||
|
||||
## i18n.phonenumbers.CountryCodeSource
|
||||
|
||||
Lists the following enums in order to compare them with the output of `Phone.getCountryCodeSource()`:
|
||||
|
||||
* `CountryCodeSource.UNSPECIFIED`
|
||||
* `CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN`
|
||||
* `CountryCodeSource.FROM_NUMBER_WITH_IDD`
|
||||
* `CountryCodeSource.FROM_NUMBER_WITHOUT_PLUS_SIGN`
|
||||
* `CountryCodeSource.FROM_DEFAULT_COUNTRY`
|
||||
|
||||
## i18n.phonenumbers.PhoneNumberFormat
|
||||
|
||||
Lists the following enums in order to pass them to `PhoneNumberUtil.format()`:
|
||||
|
||||
* `PhoneNumberFormat.E164`
|
||||
* `PhoneNumberFormat.INTERNATIONAL`
|
||||
* `PhoneNumberFormat.NATIONAL`
|
||||
* `PhoneNumberFormat.RFC3966`
|
||||
|
||||
## i18n.phonenumbers.PhoneNumberType
|
||||
|
||||
Lists the following enums in order to compare them with the output of `PhoneNumberUtil.getNumberType()`:
|
||||
|
||||
* `PhoneNumberType.FIXED_LINE`
|
||||
* `PhoneNumberType.MOBILE`
|
||||
* `PhoneNumberType.FIXED_LINE_OR_MOBILE`
|
||||
* `PhoneNumberType.TOLL_FREE`
|
||||
* `PhoneNumberType.PREMIUM_RATE`
|
||||
* `PhoneNumberType.SHARED_COST`
|
||||
* `PhoneNumberType.VOIP`
|
||||
* `PhoneNumberType.PERSONAL_NUMBER`
|
||||
* `PhoneNumberType.PAGER`
|
||||
* `PhoneNumberType.UAN`
|
||||
* `PhoneNumberType.VOICEMAIL`
|
||||
* `PhoneNumberType.UNKNOWN`
|
||||
|
||||
### i18n.phonenumbers.ShortNumberInfo
|
||||
|
||||
Highlights:
|
||||
|
||||
* **connectsToEmergencyNumber(number, regionCode)** - tests whether the short number can be used to connect to emergency services when dialed from the given region.
|
||||
* **isPossibleShortNumber(number)** - tests whether a short number is a possible number.
|
||||
* **isPossibleShortNumberForRegion(number, regionDialingFrom)** - tests whether a short number is a possible number when dialed from the given region.
|
||||
* **isValidShortNumber(number)** - tests whether a short number is a possible number.
|
||||
* **isValidShortNumberForRegion(number, regionDialingFrom)** - tests whether a short number matches a valid pattern in a region.
|
||||
|
||||
```js
|
||||
// Get an instance of `ShortNumberInfo`.
|
||||
const shortInfo = require('google-libphonenumber').ShortNumberInfo.getInstance();
|
||||
|
||||
// Get an instance of `PhoneNumberUtil`.
|
||||
const phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();
|
||||
|
||||
// Result from connectsToEmergencyNumber().
|
||||
console.log(shortInfo.connectsToEmergencyNumber('911', 'US'));
|
||||
// => true
|
||||
|
||||
// Result from isPossibleShortNumber().
|
||||
console.log(shortInfo.isPossibleShortNumber(phoneUtil.parse('123456', 'FR')));
|
||||
// => true
|
||||
|
||||
// Result from isPossibleShortNumberForRegion().
|
||||
console.log(shortInfo.isPossibleShortNumberForRegion(phoneUtil.parse('123456', 'FR'), 'FR'));
|
||||
// => true
|
||||
```
|
||||
|
||||
### Unavailable methods and classes
|
||||
|
||||
The following methods or classes are unavailable on the original JS port of Google's libphonenumber:
|
||||
|
||||
* findNumbers - finds numbers in text (useful for highlighting or linking phone numbers inside text messages).
|
||||
* PhoneNumberOfflineGeocoder - provides geographical information related to a phone number.
|
||||
* PhoneNumberToCarrierMapper - provides carrier information related to a phone number.
|
||||
* PhoneNumberToTimeZonesMapper - provides timezone information related to a phone number.
|
||||
|
||||
## Notes
|
||||
|
||||
### Metadata issues
|
||||
|
||||
Most of the issues submitted to this repository are related to carrier metadata - things like unexpected phone validations, errors in formatting numbers, unknown carriers and so on.
|
||||
|
||||
First, try the same input using the [official demo page](http://libphonenumber.appspot.com). If the result is different, then it might mean that a metadata update is due on this package, as the demo page always runs on the latest and official metadata version.
|
||||
|
||||
If the result is the same, it means there might be an issue with the currently available metadata. In that case, you should report your issue in the original project's [issue tracker](https://issuetracker.google.com/issues?q=componentid:192347) ([moved out of GitHub on 05/12/2017](https://groups.google.com/forum/#!topic/libphonenumber-discuss/bcCh0175LME)).
|
||||
|
||||
This note will be posted on every issue regarding metadata troubles and it will be automatically closed.
|
||||
|
||||
### Differences from other packages
|
||||
|
||||
`google-libphonenumber` does not try to be more than what it really is - a pre-compiled Google libphonenumber bundle that works on node.js. It is a **1:1 mirror** of the original library without any further simplifications or optimizations.
|
||||
|
||||
* All classes available from `libphonenumber` are exported as-is. No magic methods.
|
||||
* Always based on the latest `google-closure` library version available from Google with performance and bug fixes.
|
||||
* Relies on a simplified and [well-documented update process](https://github.com/ruimarinho/google-libphonenumber/blob/master/bin/update.sh) to keep the underlying `libphonenumber` library always up-to-date.
|
||||
|
||||
If you're looking for a slightly simpler API, you should try [awesome-phonenumber](https://www.npmjs.com/package/awesome-phonenumber). It is based on the same concepts of this package but changes the API in order to make it more user friendly. You run the risk of bumping into [other](https://github.com/grantila/awesome-phonenumber/issues/14) [bugs](https://github.com/grantila/awesome-phonenumber/issues/17) and you'll have to [learn new API types](https://github.com/grantila/awesome-phonenumber#api-types), but that's the necessary trade-off that the author made for achieving a generally better looking API.
|
||||
|
||||
[libphonenumber-js](https://www.npmjs.com/package/libphonenumber-js) is a much more radical approach to Google's libphonenumber. It is a rewrite of the original library based on its source phone metadata but implemented without depending on the Google Closure library. It also offers a tool to reduce the metadata to a set of countries which might be useful for frontend projects. It has several [caveats](https://github.com/catamphetamine/libphonenumber-js#difference-from-googles-libphonenumber), many of which make a lot of sense depending on the project, but you will have to ascertain those yourself.
|
||||
|
||||
## Webpack
|
||||
|
||||
There have been some users reporting successful but also unsuccessful usage with Webpack. While I don't personally use it, I'm 100% supportive of pull requests adding modifications that allow this package to better interact with it.
|
||||
|
||||
### Chrome Extensions
|
||||
|
||||
Google Closure Compiler API, a serviced provided by Google to compile code online via its Closure library, may not always return fully compliant UTF-8-encoded output.
|
||||
|
||||
Loading extensions using this library on Google Chrome and other Chromium-based browsers may result in the following error when compiled with webpack:
|
||||
|
||||
`Could not load file 'file.js' for content script. It isn't UTF-8 encoded.`
|
||||
|
||||
While the local Java-based version supports a parameter which would let us workaround this issue at the source using `--charset=US-ASCII`, the online API version, which is a lot more convenient to use, does not offer support for an equivalent parameter (e.g. `output_charset=US-ASCII`).
|
||||
|
||||
In order to workaround this issue when using webpack, make sure to output US-ASCII characters only when defining `TerserPlugin` options, as demonstrated below:
|
||||
|
||||
```js
|
||||
optimization: {
|
||||
minimize: process.env.NODE_ENV !== 'development',
|
||||
minimizer: [
|
||||
new TerserPlugin({
|
||||
terserOptions: {
|
||||
output: {
|
||||
ascii_only: true
|
||||
}
|
||||
},
|
||||
}),
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Tests
|
||||
|
||||
A small subset of tests guarantees that the main library functions are working as expected and are correctly exported. The actual heavy lifting is done by `libphonenumber`'s extensive test suite.
|
||||
|
||||
```sh
|
||||
npm test
|
||||
```
|
||||
|
||||
## Release
|
||||
|
||||
```sh
|
||||
npm version [<newversion> | major | minor | patch] -m "Release %s"
|
||||
```
|
||||
|
||||
## Acknowledgments
|
||||
|
||||
The exceptional work on `libphonenumber` was made possible by these [committers and contributors](https://github.com/googlei18n/libphonenumber/graphs/contributors).
|
||||
|
||||
## Licenses
|
||||
|
||||
This package is licensed under MIT. The bundled [libphonenumber](https://github.com/googlei18n/libphonenumber/blob/master/LICENSE) library is licensed under Apache 2.0.
|
||||
|
||||
[npm-image]: https://flat.badgen.net/npm/v/google-libphonenumber
|
||||
[npm-url]: https://npmjs.org/package/google-libphonenumber
|
||||
[travis-image]: https://flat.badgen.net/travis/ruimarinho/google-libphonenumber
|
||||
[travis-url]: https://travis-ci.org/ruimarinho/google-libphonenumber
|
||||
[packagephobia-image]: https://flat.badgen.net/packagephobia/install/google-libphonenumber
|
||||
[packagephobia-url]: https://packagephobia.now.sh/result?p=google-libphonenumber
|
||||
+1206
File diff suppressed because it is too large.
Load diff
+84
@@ -0,0 +1,84 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"google-libphonenumber@3.2.15",
|
||||
"/Users/oliverbarr/Documents/Discord Bots/SupportBot"
|
||||
]
|
||||
],
|
||||
"_from": "google-libphonenumber@3.2.15",
|
||||
"_id": "google-libphonenumber@3.2.15",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-tbCIuzMoH34RdrbFRw5kijAZn/p6JMQvsgtr1glg2ugbwqrMPlOL8pHNK8cyGo9B6SXpcMm4hdyDqwomR+HPRg==",
|
||||
"_location": "/google-libphonenumber",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "google-libphonenumber@3.2.15",
|
||||
"name": "google-libphonenumber",
|
||||
"escapedName": "google-libphonenumber",
|
||||
"rawSpec": "3.2.15",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "3.2.15"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/class-validator"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/google-libphonenumber/-/google-libphonenumber-3.2.15.tgz",
|
||||
"_spec": "3.2.15",
|
||||
"_where": "/Users/oliverbarr/Documents/Discord Bots/SupportBot",
|
||||
"author": {
|
||||
"name": "Rui Marinho",
|
||||
"email": "ruipmarinho@gmail.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/ruimarinho/google-libphonenumber/issues"
|
||||
},
|
||||
"description": "The up-to-date and reliable Google's libphonenumber package for node.js.",
|
||||
"devDependencies": {
|
||||
"browserify": "^13.1.0",
|
||||
"eslint": "^7.13.0",
|
||||
"google-closure-compiler": "^20201102.0.1",
|
||||
"google-closure-library": "^20201006.0.0",
|
||||
"mocha": "^8.2.1",
|
||||
"should": "^11.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10"
|
||||
},
|
||||
"homepage": "https://ruimarinho.github.io/google-libphonenumber/",
|
||||
"keywords": [
|
||||
"browserify",
|
||||
"e164",
|
||||
"format",
|
||||
"formatting",
|
||||
"international",
|
||||
"libphonenumber",
|
||||
"number",
|
||||
"phone",
|
||||
"phonenumber",
|
||||
"rfc3966",
|
||||
"standardize",
|
||||
"wrapper"
|
||||
],
|
||||
"license": "(MIT AND Apache-2.0)",
|
||||
"main": "dist/libphonenumber.js",
|
||||
"name": "google-libphonenumber",
|
||||
"options": {
|
||||
"mocha": "--require should test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/ruimarinho/google-libphonenumber.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "bin/build.sh",
|
||||
"lint": "eslint src/index.js test",
|
||||
"prepare": "npm run build",
|
||||
"test": "npm run build && npm run testonly",
|
||||
"testonly": "mocha $npm_package_options_mocha",
|
||||
"update": "bin/update.sh",
|
||||
"version": "npm run build && git add -A dist"
|
||||
},
|
||||
"version": "3.2.15"
|
||||
}
|
||||
Reference in new issue
Block a user