libphonenumber-js 1.10.60 → 1.10.62

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libphonenumber-js",
3
- "version": "1.10.60",
3
+ "version": "1.10.62",
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",
package/source/isValid.js CHANGED
@@ -44,15 +44,6 @@ export default function isValidNumber(input, options, metadata)
44
44
 
45
45
  metadata = new Metadata(metadata)
46
46
 
47
- /**
48
- * Checks if a phone number is "possible" (basically just checks its length).
49
- *
50
- * @param {object|PhoneNumber} input — If `options.v2: true` flag is passed, the `input` should be a `PhoneNumber` instance. Otherwise, it should be an object of shape `{ phone: '...', country: '...' }`.
51
- * @param {object} [options]
52
- * @param {object} metadata
53
- * @return {string}
54
- */
55
-
56
47
  metadata.selectNumberingPlan(input.country, input.countryCallingCode)
57
48
 
58
49
  // By default, countries only have type regexps when it's required for
package/types.d.cts CHANGED
@@ -54,13 +54,45 @@ export type Examples = {
54
54
  export type NumberFormat = 'NATIONAL' | 'INTERNATIONAL' | 'E.164' | 'RFC3966' | 'IDD';
55
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
56
 
57
+ // "Tagged" types are used to introduce some degree of type safety when passing in arguments to the functions.
58
+ // https://medium.com/@ethanresnick/advanced-typescript-tagged-types-for-fewer-bugs-and-better-security-24db681d5721
59
+ //
60
+ // For example, if some function returns an `E164Number`, it can only be interpreted as
61
+ // either a `string` or an `E164Number` and it can't mistakenly be interpreted as
62
+ // a `NationalNumber` or an `Extension` or a `CarrierCode` or a `CountryCallingCode`.
63
+ //
64
+ // Example:
65
+ //
66
+ // import type { E164Number, CarrierCode } from 'libphonenumber-js'
67
+ // const number: E164Number = '+78005553535'
68
+ // const carrierCode: CarrierCode = number
69
+ //
70
+ // Shows an error:
71
+ // Type 'E164Number' is not assignable to type 'CarrierCode'.
72
+ //
73
+ // The `__tag` property is declared optional in order to allow passing a `string`
74
+ // in place of a `Tagged` argument to functions that receive such arguments.
75
+ // There currently are no such functions in this package, but in case there were any,
76
+ // in their arguments they'd accept both a `string` and the `Tagged` type of the argument.
77
+ //
78
+ // The `__tag` property could also be declared non-optional but what issue would it solve?
79
+ // It would disallow assigning a `string` to an `E164Number` variable, but what would be the props of such approach?
80
+ // For example, the following code wouldn't compile:
81
+ //
82
+ // const number: E164Number = "some random text"
83
+ //
84
+ // But in that case, how would one initialize an `E164Number` variable with a value received from outside?
85
+ // For example, a program reads an `E.164` number from a database in the form of a `string`.
86
+ // How would it cast it to an `E164Number`? Using `as` keyword?
87
+ // In that case it wouldn't really make any difference from allowing it to assign a `string` to a `E164Number` variable directly.
88
+ //
57
89
  type Tagged<A, T> = A & { __tag?: T };
58
90
 
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">;
91
+ export type E164Number = Tagged<string, "E164Number">;
92
+ export type NationalNumber = Tagged<string, "NationalNumber">;
93
+ export type Extension = Tagged<string, "Extension">;
94
+ export type CarrierCode = Tagged<string, "CarrierCode">;
95
+ export type CountryCallingCode = Tagged<string, "CountryCallingCode">;
64
96
 
65
97
  type FormatExtension = (formattedNumber: string, extension: Extension, metadata: MetadataJson) => string
66
98
 
package/types.d.ts CHANGED
@@ -54,13 +54,45 @@ export type Examples = {
54
54
  export type NumberFormat = 'NATIONAL' | 'INTERNATIONAL' | 'E.164' | 'RFC3966' | 'IDD';
55
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
56
 
57
+ // "Tagged" types are used to introduce some degree of type safety when passing in arguments to the functions.
58
+ // https://medium.com/@ethanresnick/advanced-typescript-tagged-types-for-fewer-bugs-and-better-security-24db681d5721
59
+ //
60
+ // For example, if some function returns an `E164Number`, it can only be interpreted as
61
+ // either a `string` or an `E164Number` and it can't mistakenly be interpreted as
62
+ // a `NationalNumber` or an `Extension` or a `CarrierCode` or a `CountryCallingCode`.
63
+ //
64
+ // Example:
65
+ //
66
+ // import type { E164Number, CarrierCode } from 'libphonenumber-js'
67
+ // const number: E164Number = '+78005553535'
68
+ // const carrierCode: CarrierCode = number
69
+ //
70
+ // Shows an error:
71
+ // Type 'E164Number' is not assignable to type 'CarrierCode'.
72
+ //
73
+ // The `__tag` property is declared optional in order to allow passing a `string`
74
+ // in place of a `Tagged` argument to functions that receive such arguments.
75
+ // There currently are no such functions in this package, but in case there were any,
76
+ // in their arguments they'd accept both a `string` and the `Tagged` type of the argument.
77
+ //
78
+ // The `__tag` property could also be declared non-optional but what issue would it solve?
79
+ // It would disallow assigning a `string` to an `E164Number` variable, but what would be the props of such approach?
80
+ // For example, the following code wouldn't compile:
81
+ //
82
+ // const number: E164Number = "some random text"
83
+ //
84
+ // But in that case, how would one initialize an `E164Number` variable with a value received from outside?
85
+ // For example, a program reads an `E.164` number from a database in the form of a `string`.
86
+ // How would it cast it to an `E164Number`? Using `as` keyword?
87
+ // In that case it wouldn't really make any difference from allowing it to assign a `string` to a `E164Number` variable directly.
88
+ //
57
89
  type Tagged<A, T> = A & { __tag?: T };
58
90
 
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">;
91
+ export type E164Number = Tagged<string, "E164Number">;
92
+ export type NationalNumber = Tagged<string, "NationalNumber">;
93
+ export type Extension = Tagged<string, "Extension">;
94
+ export type CarrierCode = Tagged<string, "CarrierCode">;
95
+ export type CountryCallingCode = Tagged<string, "CountryCallingCode">;
64
96
 
65
97
  type FormatExtension = (formattedNumber: string, extension: Extension, metadata: MetadataJson) => string
66
98