libphonenumber-js 1.10.40 → 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/min/package.json CHANGED
@@ -6,7 +6,6 @@
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {
9
- "types": "../min/index.d.ts",
10
9
  "import": "./index.js",
11
10
  "require": "./index.cjs"
12
11
  }
@@ -0,0 +1,102 @@
1
+ import {
2
+ MetadataJson,
3
+ Examples,
4
+ PhoneNumber,
5
+ E164Number,
6
+ CountryCallingCode,
7
+ CountryCode,
8
+ CarrierCode,
9
+ NationalNumber,
10
+ Extension,
11
+ ParseError,
12
+ NumberFoundLegacy,
13
+ NumberFound,
14
+ NumberType,
15
+ NumberFormat,
16
+ NumberingPlan,
17
+ ValidatePhoneNumberLengthResult
18
+ } from '../types.d.js';
19
+
20
+ // They say this re-export is required.
21
+ // https://github.com/catamphetamine/libphonenumber-js/pull/290#issuecomment-453281180
22
+ export {
23
+ MetadataJson,
24
+ Examples,
25
+ PhoneNumber,
26
+ E164Number,
27
+ CountryCallingCode,
28
+ CountryCode,
29
+ CarrierCode,
30
+ NationalNumber,
31
+ Extension,
32
+ ParseError,
33
+ NumberFoundLegacy,
34
+ NumberFound,
35
+ NumberType,
36
+ NumberFormat,
37
+ NumberingPlan,
38
+ ValidatePhoneNumberLengthResult
39
+ };
40
+
41
+ // `parsePhoneNumber()` named export has been renamed to `parsePhoneNumberWithError()`.
42
+ export function parsePhoneNumber(text: string, defaultCountry?: CountryCode): PhoneNumber;
43
+
44
+ export function parsePhoneNumberWithError(text: string, defaultCountry?: CountryCode): PhoneNumber;
45
+
46
+ // `parsePhoneNumberFromString()` named export is now considered legacy:
47
+ // it has been promoted to a default export due to being too verbose.
48
+ export function parsePhoneNumberFromString(text: string, defaultCountry?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string, extract?: boolean }): PhoneNumber | undefined;
49
+
50
+ export default parsePhoneNumberFromString;
51
+
52
+ export function isValidPhoneNumber(text: string, defaultCountry?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string }): boolean;
53
+ export function isPossiblePhoneNumber(text: string, defaultCountry?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string }): boolean;
54
+ export function validatePhoneNumberLength(text: string, defaultCountry?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string }): ValidatePhoneNumberLengthResult | undefined;
55
+
56
+ export function findNumbers(text: string, options?: CountryCode): NumberFoundLegacy[];
57
+ export function searchNumbers(text: string, options?: CountryCode): IterableIterator<NumberFoundLegacy>;
58
+
59
+ export function findNumbers(text: string, options?: { defaultCountry?: CountryCode, v2: true }): NumberFound[];
60
+ export function searchNumbers(text: string, options?: { defaultCountry?: CountryCode, v2: true }): IterableIterator<NumberFound>;
61
+
62
+ export function findPhoneNumbersInText(text: string, options?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string, extended?: boolean }): NumberFound[];
63
+ export function searchPhoneNumbersInText(text: string, options?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string, extended?: boolean }): IterableIterator<NumberFound>;
64
+
65
+ export class PhoneNumberMatcher {
66
+ constructor(text: string, options?: { defaultCountry?: CountryCode, v2: true });
67
+ hasNext(): boolean;
68
+ next(): NumberFound | undefined;
69
+ }
70
+
71
+ export function isSupportedCountry(countryCode: CountryCode): boolean;
72
+ export function getCountries(): CountryCode[];
73
+ export function getCountryCallingCode(countryCode: CountryCode): CountryCallingCode;
74
+ export function getExtPrefix(countryCode: CountryCode): string;
75
+
76
+ export function getExampleNumber(country: CountryCode, examples: Examples): PhoneNumber | undefined;
77
+
78
+ export function formatIncompletePhoneNumber(number: string, countryCode?: CountryCode): string;
79
+ export function parseIncompletePhoneNumber(text: string): string;
80
+ export function parsePhoneNumberCharacter(character: string): string;
81
+ export function parseDigits(character: string): string;
82
+
83
+ export class AsYouType {
84
+ constructor(defaultCountryCode?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string });
85
+ input(text: string): string;
86
+ reset(): void;
87
+ getNumber(): PhoneNumber | undefined;
88
+ getNumberValue(): E164Number | undefined;
89
+ getChars(): string;
90
+ getTemplate(): string;
91
+ getCallingCode(): string | undefined;
92
+ getCountry(): CountryCode | undefined;
93
+ isInternational(): boolean;
94
+ isPossible(): boolean;
95
+ isValid(): boolean;
96
+ }
97
+
98
+ export class Metadata {
99
+ constructor();
100
+ selectNumberingPlan(country: CountryCode): void;
101
+ numberingPlan?: NumberingPlan;
102
+ }
@@ -0,0 +1,102 @@
1
+ import {
2
+ MetadataJson,
3
+ Examples,
4
+ PhoneNumber,
5
+ E164Number,
6
+ CountryCallingCode,
7
+ CountryCode,
8
+ CarrierCode,
9
+ NationalNumber,
10
+ Extension,
11
+ ParseError,
12
+ NumberFoundLegacy,
13
+ NumberFound,
14
+ NumberType,
15
+ NumberFormat,
16
+ NumberingPlan,
17
+ ValidatePhoneNumberLengthResult
18
+ } from '../types.d.js';
19
+
20
+ // They say this re-export is required.
21
+ // https://github.com/catamphetamine/libphonenumber-js/pull/290#issuecomment-453281180
22
+ export {
23
+ MetadataJson,
24
+ Examples,
25
+ PhoneNumber,
26
+ E164Number,
27
+ CountryCallingCode,
28
+ CountryCode,
29
+ CarrierCode,
30
+ NationalNumber,
31
+ Extension,
32
+ ParseError,
33
+ NumberFoundLegacy,
34
+ NumberFound,
35
+ NumberType,
36
+ NumberFormat,
37
+ NumberingPlan,
38
+ ValidatePhoneNumberLengthResult
39
+ };
40
+
41
+ // `parsePhoneNumber()` named export has been renamed to `parsePhoneNumberWithError()`.
42
+ export function parsePhoneNumber(text: string, defaultCountry?: CountryCode): PhoneNumber;
43
+
44
+ export function parsePhoneNumberWithError(text: string, defaultCountry?: CountryCode): PhoneNumber;
45
+
46
+ // `parsePhoneNumberFromString()` named export is now considered legacy:
47
+ // it has been promoted to a default export due to being too verbose.
48
+ export function parsePhoneNumberFromString(text: string, defaultCountry?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string, extract?: boolean }): PhoneNumber | undefined;
49
+
50
+ export default parsePhoneNumberFromString;
51
+
52
+ export function isValidPhoneNumber(text: string, defaultCountry?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string }): boolean;
53
+ export function isPossiblePhoneNumber(text: string, defaultCountry?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string }): boolean;
54
+ export function validatePhoneNumberLength(text: string, defaultCountry?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string }): ValidatePhoneNumberLengthResult | undefined;
55
+
56
+ export function findNumbers(text: string, options?: CountryCode): NumberFoundLegacy[];
57
+ export function searchNumbers(text: string, options?: CountryCode): IterableIterator<NumberFoundLegacy>;
58
+
59
+ export function findNumbers(text: string, options?: { defaultCountry?: CountryCode, v2: true }): NumberFound[];
60
+ export function searchNumbers(text: string, options?: { defaultCountry?: CountryCode, v2: true }): IterableIterator<NumberFound>;
61
+
62
+ export function findPhoneNumbersInText(text: string, options?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string, extended?: boolean }): NumberFound[];
63
+ export function searchPhoneNumbersInText(text: string, options?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string, extended?: boolean }): IterableIterator<NumberFound>;
64
+
65
+ export class PhoneNumberMatcher {
66
+ constructor(text: string, options?: { defaultCountry?: CountryCode, v2: true });
67
+ hasNext(): boolean;
68
+ next(): NumberFound | undefined;
69
+ }
70
+
71
+ export function isSupportedCountry(countryCode: CountryCode): boolean;
72
+ export function getCountries(): CountryCode[];
73
+ export function getCountryCallingCode(countryCode: CountryCode): CountryCallingCode;
74
+ export function getExtPrefix(countryCode: CountryCode): string;
75
+
76
+ export function getExampleNumber(country: CountryCode, examples: Examples): PhoneNumber | undefined;
77
+
78
+ export function formatIncompletePhoneNumber(number: string, countryCode?: CountryCode): string;
79
+ export function parseIncompletePhoneNumber(text: string): string;
80
+ export function parsePhoneNumberCharacter(character: string): string;
81
+ export function parseDigits(character: string): string;
82
+
83
+ export class AsYouType {
84
+ constructor(defaultCountryCode?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string });
85
+ input(text: string): string;
86
+ reset(): void;
87
+ getNumber(): PhoneNumber | undefined;
88
+ getNumberValue(): E164Number | undefined;
89
+ getChars(): string;
90
+ getTemplate(): string;
91
+ getCallingCode(): string | undefined;
92
+ getCountry(): CountryCode | undefined;
93
+ isInternational(): boolean;
94
+ isPossible(): boolean;
95
+ isValid(): boolean;
96
+ }
97
+
98
+ export class Metadata {
99
+ constructor();
100
+ selectNumberingPlan(country: CountryCode): void;
101
+ numberingPlan?: NumberingPlan;
102
+ }
@@ -3,11 +3,9 @@
3
3
  "name": "libphonenumber-js/mobile",
4
4
  "main": "index.cjs",
5
5
  "module": "index.js",
6
- "types": "../min/index.d.ts",
7
6
  "type": "module",
8
7
  "exports": {
9
8
  ".": {
10
- "types": "../min/index.d.ts",
11
9
  "import": "./index.js",
12
10
  "require": "./index.cjs"
13
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libphonenumber-js",
3
- "version": "1.10.40",
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,10 +142,11 @@
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*}.d.ts . --rename={{basename}}.cts && renamer --find d.cts.ts --replace d.cts ./*.d.cts.ts ./!(node_modules)/**/*.d.cts.ts",
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
+ "build:modules:copy-typescript-definitions": "cpy --flat min/index.d.ts max && cpy --flat min/index.d.ts mobile",
146
147
  "build:modules": "cross-env BABEL_ENV=es6 babel ./source --out-dir ./es6 --source-maps --ignore test.js",
147
148
  "build:bundle": "rollup --config rollup.config.mjs",
148
- "build": "npm-run-all clean build:commonjs build:modules build:bundle",
149
+ "build": "npm-run-all clean build:modules:copy-typescript-definitions build:modules build:commonjs build:bundle",
149
150
  "prepublishOnly": "npm run metadata:generate && npm run generate-country-codes && crlf --set=LF metadata.*.json && npm-run-all build test"
150
151
  },
151
152
  "repository": {
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';