Skip to content

Instantly share code, notes, and snippets.

@molavec
Last active May 1, 2024 20:57
Show Gist options
  • Save molavec/0a78d86af71df43573060b684c1949dd to your computer and use it in GitHub Desktop.
Save molavec/0a78d86af71df43573060b684c1949dd to your computer and use it in GitHub Desktop.
[Corrector de teléfonos] Corrector de teléfonos para zapier.
/**
* 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