@pedidopago/ui 1.7.15 → 1.7.16
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.
|
@@ -40,6 +40,12 @@ export declare function phoneNineDigitParser(phone: string, remove?: boolean): s
|
|
|
40
40
|
export declare function verifyNineDigit(phone: string, { errorMessage, }: {
|
|
41
41
|
errorMessage?: string;
|
|
42
42
|
}): boolean | string;
|
|
43
|
+
/**
|
|
44
|
+
* Returns the DDI (international dialing code) of a phone number.
|
|
45
|
+
* @param {string} number - The phone number to get the DDI from.
|
|
46
|
+
* @returns {string|null} The DDI.
|
|
47
|
+
*/
|
|
48
|
+
export declare function getDDI(number?: string): string | undefined;
|
|
43
49
|
/**
|
|
44
50
|
* Returns a formatted phone number based on provided options.
|
|
45
51
|
* @param {string} phone - The phone number to be formatted.
|
|
@@ -51,10 +57,4 @@ export declare function formatedPhone(phone: string, options?: {
|
|
|
51
57
|
withDDI?: boolean;
|
|
52
58
|
keepDDI?: boolean;
|
|
53
59
|
}): string;
|
|
54
|
-
/**
|
|
55
|
-
* Returns the DDI (international dialing code) of a phone number.
|
|
56
|
-
* @param {string} number - The phone number to get the DDI from.
|
|
57
|
-
* @returns {string|null} The DDI.
|
|
58
|
-
*/
|
|
59
|
-
export declare function getDDI(number?: string): string | null;
|
|
60
60
|
//# sourceMappingURL=phone.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phone.d.ts","sourceRoot":"","sources":["../../../src/utils/formatters/phone.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,GAAE,MAAc,GAAG,MAAM,CAetE;AACD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,GAAE,MAAc,GAAG,MAAM,CAkCjF;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MA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;CAAE,GAC3B,OAAO,GAAG,MAAM,CAQlB;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,sBAWrC;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;IACP,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;CACd,UA2BP"}
|
|
@@ -132,6 +132,22 @@ function verifyNineDigit(phone, _ref) {
|
|
|
132
132
|
return firstDigitIsNineNumber || errorMessage;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Returns the DDI (international dialing code) of a phone number.
|
|
137
|
+
* @param {string} number - The phone number to get the DDI from.
|
|
138
|
+
* @returns {string|null} The DDI.
|
|
139
|
+
*/
|
|
140
|
+
function getDDI(number) {
|
|
141
|
+
if (number) {
|
|
142
|
+
// Removes everything except digits from the phone number.
|
|
143
|
+
var phone = number.replace(/\D/g, '');
|
|
144
|
+
// Gets the DDI using the phoneLib library.
|
|
145
|
+
var ddi = (0, _phone.default)('+' + phone);
|
|
146
|
+
return ddi.countryCode || undefined;
|
|
147
|
+
}
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
|
|
135
151
|
/**
|
|
136
152
|
* Returns a formatted phone number based on provided options.
|
|
137
153
|
* @param {string} phone - The phone number to be formatted.
|
|
@@ -141,7 +157,6 @@ function verifyNineDigit(phone, _ref) {
|
|
|
141
157
|
function formatedPhone(phone) {
|
|
142
158
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
143
159
|
var result = '';
|
|
144
|
-
|
|
145
160
|
// If phone is provided.
|
|
146
161
|
if (phone) {
|
|
147
162
|
// If withDDI option is enabled, gets the DDI from the phone number.
|
|
@@ -153,29 +168,14 @@ function formatedPhone(phone) {
|
|
|
153
168
|
result = phone.replace(/[^\d*]/g, '').replace(/^0*/, '');
|
|
154
169
|
|
|
155
170
|
// Formats the phone number based on the DDI.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
result = result.replace(/[^\d*-]/g, '');
|
|
171
|
+
if (options.ddi && options.ddi.replace('+', '') === '55' && !options.keepDDI) {
|
|
172
|
+
result = result.substring(2);
|
|
173
|
+
}
|
|
174
|
+
if (options.ddi && options.ddi.replace('+', '') === '55') {
|
|
175
|
+
result = result.replace(/^(\d{2}|\*{2})\B/, '($1) ').replace(/(\d{1}|\*{1})?(\d{4}|\*{4})(\d{4}|\*{4})/, '$1$2-$3');
|
|
162
176
|
}
|
|
163
177
|
}
|
|
164
178
|
|
|
165
179
|
// If keepDDI option is enabled, returns the formatted phone number with the DDI.
|
|
166
|
-
return options
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Returns the DDI (international dialing code) of a phone number.
|
|
171
|
-
* @param {string} number - The phone number to get the DDI from.
|
|
172
|
-
* @returns {string|null} The DDI.
|
|
173
|
-
*/
|
|
174
|
-
function getDDI(number) {
|
|
175
|
-
// Removes everything except digits from the phone number.
|
|
176
|
-
var phone = number === null || number === void 0 ? void 0 : number.replace(/\D/g, '');
|
|
177
|
-
|
|
178
|
-
// Gets the DDI using the phoneLib library.
|
|
179
|
-
var ddi = (0, _phone.default)('+' + phone);
|
|
180
|
-
return ddi.countryCode;
|
|
180
|
+
return options.keepDDI ? "".concat(options.ddi, " ").concat(result) : result;
|
|
181
181
|
}
|