eai-frontend-components 2.0.46 → 2.0.47
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/dist/index.d.ts +19 -17
- package/dist/index.esm.js +13 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +13 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -791,23 +791,33 @@ const removeMaskNumber = (value) => {
|
|
|
791
791
|
* Automatically detects landline vs mobile format.
|
|
792
792
|
*
|
|
793
793
|
* @param telefone - Raw phone number string
|
|
794
|
-
* @param
|
|
794
|
+
* @param removeDDD - Whether to remove DDD (area code) from the formatted output
|
|
795
|
+
* @param removeCountryCode - Whether to remove country code (55) if present
|
|
795
796
|
* @returns Formatted phone number string
|
|
796
797
|
*
|
|
797
798
|
* @example
|
|
798
799
|
* ```tsx
|
|
799
800
|
* formatPhone('11987654321') // '(11) 9 8765-4321'
|
|
800
801
|
* formatPhone('1134567890') // '(11) 3456-7890'
|
|
802
|
+
* formatPhone('11987654321', true) // '9 8765-4321'
|
|
801
803
|
* ```
|
|
802
804
|
*/
|
|
803
|
-
function formatPhone(telefone,
|
|
805
|
+
function formatPhone(telefone, removeDDD = false, removeCountryCode = true) {
|
|
804
806
|
if (!telefone)
|
|
805
807
|
return '';
|
|
806
808
|
let numberPhone = telefone.replace(/\D/g, '');
|
|
807
809
|
// Remover código do país apenas se ele começar com '55'
|
|
808
|
-
if (
|
|
810
|
+
if (removeCountryCode && numberPhone.startsWith('55')) {
|
|
809
811
|
numberPhone = numberPhone.substring(2);
|
|
810
812
|
}
|
|
813
|
+
// Se removeDDD for true, remover os dois primeiros dígitos (DDD)
|
|
814
|
+
if (removeDDD && numberPhone.length >= 10) {
|
|
815
|
+
const phoneWithoutDDD = numberPhone.substring(2);
|
|
816
|
+
// Aplicar máscara sem DDD
|
|
817
|
+
const isMobile = phoneWithoutDDD.length === 9;
|
|
818
|
+
const mask = isMobile ? { mask: '_ ____-____', replacement: { _: /\d/ } } : { mask: '____-_____', replacement: { _: /\d/ } };
|
|
819
|
+
return mask$1.format(phoneWithoutDDD, mask);
|
|
820
|
+
}
|
|
811
821
|
return mask$1.format(numberPhone, maskPhone(numberPhone));
|
|
812
822
|
}
|
|
813
823
|
// CPF/CNPJ
|