Last active
May 1, 2024 20:57
-
-
Save molavec/0a78d86af71df43573060b684c1949dd to your computer and use it in GitHub Desktop.
[Corrector de teléfonos] Corrector de teléfonos para zapier.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Corrector de teléfonos | |
* | |
* Nota: Este código está pensado para ser utilizado en Zapier | |
**/ | |
//Tarea: Ajusta el número de teléfono | |
// objeto para almacenar variantes del telefono completo. | |
var phone = { | |
"complete": null, | |
"no_plus": null | |
} | |
// si no es nulo continúa | |
if(inputData.phone != null) { | |
// elimina los espacios. | |
var phoneString = inputData.phone.replace(/ /g,''); | |
// Si ya incluye el '+' | |
if(phoneString.charAt(0) === '+') { | |
phone = { | |
"complete": phoneString, | |
"no_plus": phoneString.substr(1) | |
} | |
// Si ya incluye el '56' | |
} else if (phoneString.substr(0,2) === '56') { | |
phone = { | |
"complete": "+" + phoneString, | |
"no_plus": phoneString | |
} | |
// Si no incluye el '+56' | |
} else if (phoneString.length === 9 ) { | |
phone = { | |
"complete": "+56" + phoneString, | |
"no_plus": phoneString | |
} | |
// Si no incluye el '+569' | |
} else if (phoneString.length === 8 ) { | |
phone = { | |
"complete": "+569" + phoneString, | |
"no_plus": phoneString | |
} | |
// En cualquier otro caso mantiene el número ingresado. | |
} else { | |
phone = { | |
"complete": null, | |
"no_plus": phoneString | |
} | |
} | |
} | |
//Salida | |
output = [{ | |
phone: phone, | |
}]; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment