libphonenumber-js 1.10.41 → 1.10.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/libphonenumber-js.min.js +1 -1
- package/bundle/libphonenumber-js.min.js.map +1 -1
- package/bundle/libphonenumber-max.js +1 -1
- package/bundle/libphonenumber-max.js.map +1 -1
- package/bundle/libphonenumber-min.js +1 -1
- package/bundle/libphonenumber-min.js.map +1 -1
- package/bundle/libphonenumber-mobile.js +1 -1
- package/bundle/libphonenumber-mobile.js.map +1 -1
- package/metadata.full.json +1 -1
- package/metadata.full.json.js +1 -1
- package/metadata.max.json +1 -1
- package/metadata.max.json.js +1 -1
- package/metadata.min.json +1 -1
- package/metadata.min.json.js +1 -1
- package/metadata.mobile.json +1 -1
- package/metadata.mobile.json.js +1 -1
- package/package.json +2 -2
- package/types.d.cts +131 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libphonenumber-js",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.42",
|
|
4
4
|
"description": "A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript",
|
|
5
5
|
"main": "index.cjs",
|
|
6
6
|
"module": "index.js",
|
|
@@ -142,7 +142,7 @@
|
|
|
142
142
|
"build:commonjs:before-es-modules": "cross-env BABEL_ENV=commonjs babel ./source --out-dir ./build --source-maps --ignore test.js",
|
|
143
143
|
"build:commonjs:with-tests": "cross-env BABEL_ENV=commonjs babel ./source --out-dir ./build --source-maps",
|
|
144
144
|
"build:commonjs:package.json": "node runnable/create-commonjs-package-json.js",
|
|
145
|
-
"build:commonjs:create-typescript-definitions": "rimraf --verbose --glob ./*.d.cts ./!(node_modules)/**/*.d.cts && cpy **/{index,metadata*,examples
|
|
145
|
+
"build:commonjs:create-typescript-definitions": "rimraf --verbose --glob ./*.d.cts \"./!(node_modules)/**/*.d.cts\" && cpy **/{index,metadata*,examples*,types}.d.ts . --rename={{basename}}.cts && renamer --find d.cts.ts --replace d.cts ./*.d.cts.ts \"./!(node_modules)/**/*.d.cts.ts\"",
|
|
146
146
|
"build:modules:copy-typescript-definitions": "cpy --flat min/index.d.ts max && cpy --flat min/index.d.ts mobile",
|
|
147
147
|
"build:modules": "cross-env BABEL_ENV=es6 babel ./source --out-dir ./es6 --source-maps --ignore test.js",
|
|
148
148
|
"build:bundle": "rollup --config rollup.config.mjs",
|
package/types.d.cts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// The rationale for having a separate `CountryCode` type instead of just a `string`:
|
|
2
|
+
// https://github.com/catamphetamine/libphonenumber-js/issues/170#issuecomment-363156068
|
|
3
|
+
export type CountryCode = 'AC' | 'AD' | 'AE' | 'AF' | 'AG' | 'AI' | 'AL' | 'AM' | 'AO' | 'AR' | 'AS' | 'AT' | 'AU' | 'AW' | 'AX' | 'AZ' | 'BA' | 'BB' | 'BD' | 'BE' | 'BF' | 'BG' | 'BH' | 'BI' | 'BJ' | 'BL' | 'BM' | 'BN' | 'BO' | 'BQ' | 'BR' | 'BS' | 'BT' | 'BW' | 'BY' | 'BZ' | 'CA' | 'CC' | 'CD' | 'CF' | 'CG' | 'CH' | 'CI' | 'CK' | 'CL' | 'CM' | 'CN' | 'CO' | 'CR' | 'CU' | 'CV' | 'CW' | 'CX' | 'CY' | 'CZ' | 'DE' | 'DJ' | 'DK' | 'DM' | 'DO' | 'DZ' | 'EC' | 'EE' | 'EG' | 'EH' | 'ER' | 'ES' | 'ET' | 'FI' | 'FJ' | 'FK' | 'FM' | 'FO' | 'FR' | 'GA' | 'GB' | 'GD' | 'GE' | 'GF' | 'GG' | 'GH' | 'GI' | 'GL' | 'GM' | 'GN' | 'GP' | 'GQ' | 'GR' | 'GT' | 'GU' | 'GW' | 'GY' | 'HK' | 'HN' | 'HR' | 'HT' | 'HU' | 'ID' | 'IE' | 'IL' | 'IM' | 'IN' | 'IO' | 'IQ' | 'IR' | 'IS' | 'IT' | 'JE' | 'JM' | 'JO' | 'JP' | 'KE' | 'KG' | 'KH' | 'KI' | 'KM' | 'KN' | 'KP' | 'KR' | 'KW' | 'KY' | 'KZ' | 'LA' | 'LB' | 'LC' | 'LI' | 'LK' | 'LR' | 'LS' | 'LT' | 'LU' | 'LV' | 'LY' | 'MA' | 'MC' | 'MD' | 'ME' | 'MF' | 'MG' | 'MH' | 'MK' | 'ML' | 'MM' | 'MN' | 'MO' | 'MP' | 'MQ' | 'MR' | 'MS' | 'MT' | 'MU' | 'MV' | 'MW' | 'MX' | 'MY' | 'MZ' | 'NA' | 'NC' | 'NE' | 'NF' | 'NG' | 'NI' | 'NL' | 'NO' | 'NP' | 'NR' | 'NU' | 'NZ' | 'OM' | 'PA' | 'PE' | 'PF' | 'PG' | 'PH' | 'PK' | 'PL' | 'PM' | 'PR' | 'PS' | 'PT' | 'PW' | 'PY' | 'QA' | 'RE' | 'RO' | 'RS' | 'RU' | 'RW' | 'SA' | 'SB' | 'SC' | 'SD' | 'SE' | 'SG' | 'SH' | 'SI' | 'SJ' | 'SK' | 'SL' | 'SM' | 'SN' | 'SO' | 'SR' | 'SS' | 'ST' | 'SV' | 'SX' | 'SY' | 'SZ' | 'TA' | 'TC' | 'TD' | 'TG' | 'TH' | 'TJ' | 'TK' | 'TL' | 'TM' | 'TN' | 'TO' | 'TR' | 'TT' | 'TV' | 'TW' | 'TZ' | 'UA' | 'UG' | 'US' | 'UY' | 'UZ' | 'VA' | 'VC' | 'VE' | 'VG' | 'VI' | 'VN' | 'VU' | 'WF' | 'WS' | 'XK' | 'YE' | 'YT' | 'ZA' | 'ZM' | 'ZW';
|
|
4
|
+
|
|
5
|
+
// Seems like it doesn't work for some reason:
|
|
6
|
+
// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/94
|
|
7
|
+
//
|
|
8
|
+
// import metadata from './metadata.min.json'
|
|
9
|
+
// // Reads the list of ISO country codes from the JSON file.
|
|
10
|
+
// // https://github.com/catamphetamine/libphonenumber-js/issues/405#issuecomment-1447027961
|
|
11
|
+
// const getObjectKeys = Object.keys as <T>(object: T) => Array<keyof T>
|
|
12
|
+
// const CountryCodes = getObjectKeys(metadata.countries)
|
|
13
|
+
// // The `CountryCode` type is generated from the list of `CountryCodes`.
|
|
14
|
+
// // https://github.com/catamphetamine/libphonenumber-js/issues/405
|
|
15
|
+
// export type CountryCode = typeof CountryCodes[number];
|
|
16
|
+
|
|
17
|
+
export type CountryCallingCodes = {
|
|
18
|
+
[countryCallingCode: string]: CountryCode[];
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type Countries = {
|
|
22
|
+
// Metadata here is a compressed one,
|
|
23
|
+
// so a country's data is just an array of some properties
|
|
24
|
+
// instead of a JSON object of shape:
|
|
25
|
+
// {
|
|
26
|
+
// phone_code: string,
|
|
27
|
+
// idd_prefix: string,
|
|
28
|
+
// national_number_pattern: string,
|
|
29
|
+
// types: object,
|
|
30
|
+
// examples: object,
|
|
31
|
+
// formats: object[]?,
|
|
32
|
+
// possible_lengths: number[],
|
|
33
|
+
// ...
|
|
34
|
+
// }
|
|
35
|
+
//
|
|
36
|
+
// `in` operator docs:
|
|
37
|
+
// https://www.typescriptlang.org/docs/handbook/advanced-types.html#mapped-types
|
|
38
|
+
// `country in CountryCode` means "for each and every CountryCode".
|
|
39
|
+
[country in CountryCode]?: any[];
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type MetadataJson = {
|
|
43
|
+
country_calling_codes: CountryCallingCodes;
|
|
44
|
+
countries: Countries;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type Examples = {
|
|
48
|
+
// `in` operator docs:
|
|
49
|
+
// https://www.typescriptlang.org/docs/handbook/advanced-types.html#mapped-types
|
|
50
|
+
// `country in CountryCode` means "for each and every CountryCode".
|
|
51
|
+
[country in CountryCode]: NationalNumber;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type NumberFormat = 'NATIONAL' | 'INTERNATIONAL' | 'E.164' | 'RFC3966' | 'IDD';
|
|
55
|
+
export type NumberType = undefined | 'PREMIUM_RATE' | 'TOLL_FREE' | 'SHARED_COST' | 'VOIP' | 'PERSONAL_NUMBER' | 'PAGER' | 'UAN' | 'VOICEMAIL' | 'FIXED_LINE_OR_MOBILE' | 'FIXED_LINE' | 'MOBILE';
|
|
56
|
+
|
|
57
|
+
type Tagged<A, T> = A & { __tag?: T };
|
|
58
|
+
|
|
59
|
+
type E164Number = Tagged<string, "E164Number">;
|
|
60
|
+
type NationalNumber = Tagged<string, "NationalNumber">;
|
|
61
|
+
type Extension = Tagged<string, "Extension">;
|
|
62
|
+
type CarrierCode = Tagged<string, "CarrierCode">;
|
|
63
|
+
type CountryCallingCode = Tagged<string, "CountryCallingCode">;
|
|
64
|
+
|
|
65
|
+
type FormatExtension = (formattedNumber: string, extension: Extension, metadata: MetadataJson) => string
|
|
66
|
+
|
|
67
|
+
type FormatNumberOptionsWithoutIDD = {
|
|
68
|
+
v2?: boolean;
|
|
69
|
+
formatExtension?: FormatExtension;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
type FormatNumberOptions = {
|
|
73
|
+
v2?: boolean;
|
|
74
|
+
fromCountry?: CountryCode;
|
|
75
|
+
humanReadable?: boolean;
|
|
76
|
+
nationalPrefix?: boolean;
|
|
77
|
+
formatExtension?: FormatExtension;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// // https://stackoverflow.com/a/67026991
|
|
81
|
+
// type ArrayOfAtLeastOneCountryCode = [CountryCode, ...CountryCode[]];
|
|
82
|
+
|
|
83
|
+
export class PhoneNumber {
|
|
84
|
+
constructor(countryCallingCodeOrCountry: CountryCallingCode | CountryCode, nationalNumber: NationalNumber, metadata: MetadataJson);
|
|
85
|
+
countryCallingCode: CountryCallingCode;
|
|
86
|
+
country?: CountryCode;
|
|
87
|
+
nationalNumber: NationalNumber;
|
|
88
|
+
number: E164Number;
|
|
89
|
+
carrierCode?: CarrierCode;
|
|
90
|
+
ext?: Extension;
|
|
91
|
+
setExt(ext: Extension): void;
|
|
92
|
+
getPossibleCountries(): CountryCode[];
|
|
93
|
+
isPossible(): boolean;
|
|
94
|
+
isValid(): boolean;
|
|
95
|
+
getType(): NumberType;
|
|
96
|
+
format(format: NumberFormat, options?: FormatNumberOptions): string;
|
|
97
|
+
formatNational(options?: FormatNumberOptionsWithoutIDD): string;
|
|
98
|
+
formatInternational(options?: FormatNumberOptionsWithoutIDD): string;
|
|
99
|
+
getURI(options?: FormatNumberOptionsWithoutIDD): string;
|
|
100
|
+
isNonGeographic(): boolean;
|
|
101
|
+
isEqual(phoneNumber: PhoneNumber): boolean;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface NumberFound {
|
|
105
|
+
number: PhoneNumber;
|
|
106
|
+
startsAt: number;
|
|
107
|
+
endsAt: number;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface NumberFoundLegacy {
|
|
111
|
+
country: CountryCode;
|
|
112
|
+
phone: NationalNumber;
|
|
113
|
+
ext?: Extension;
|
|
114
|
+
startsAt: number;
|
|
115
|
+
endsAt: number;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export class ParseError {
|
|
119
|
+
message: string;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface NumberingPlan {
|
|
123
|
+
leadingDigits(): string | undefined;
|
|
124
|
+
possibleLengths(): number[];
|
|
125
|
+
IDDPrefix(): string;
|
|
126
|
+
defaultIDDPrefix(): string | undefined;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// The rationale for having a separate type for the result "enum" instead of just a `string`:
|
|
130
|
+
// https://github.com/catamphetamine/libphonenumber-js/issues/170#issuecomment-363156068
|
|
131
|
+
export type ValidatePhoneNumberLengthResult = 'INVALID_COUNTRY' | 'NOT_A_NUMBER' | 'TOO_SHORT' | 'TOO_LONG' | 'INVALID_LENGTH';
|