libphonenumber-js 1.10.61 → 1.11.0
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/CHANGELOG.md +5 -0
- 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 +1 -1
- package/types.d.cts +38 -6
- package/types.d.ts +38 -6
package/package.json
CHANGED
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
|
-
|
|
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
|
+
//
|
|
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
|
-
|
|
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
|
+
//
|
|
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
|
|