Last active
November 29, 2019 18:43
-
-
Save porfidev/1b7443fd63c65f68cfae76c1a7d9d7d2 to your computer and use it in GitHub Desktop.
Javascript ISO códigos de estados de México a Nombre. Este funciona con código ISO completo 'MX-XYZ' o código de tres letras 'XYZ' (referencia de códigos de: https://www.iso.org/obp/ui/#iso:code:3166:MX)
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
const isoStatesCodes = [ | |
{ | |
code: 'MX-AGU', | |
name: 'Aguascalientes', | |
}, | |
{ | |
code: 'MX-BCN', | |
name: 'Baja California', | |
}, | |
{ | |
code: 'MX-BCS', | |
name: 'Baja California Sur', | |
}, | |
{ | |
code: 'MX-CAM', | |
name: 'Campeche', | |
}, | |
{ | |
code: 'MX-CHP', | |
name: 'Chiapas', | |
}, | |
{ | |
code: 'MX-CHH', | |
name: 'Chihuahua', | |
}, | |
{ | |
code: 'MX-CMX', | |
name: 'Ciudad de México', | |
}, | |
{ | |
code: 'MX-COA', | |
name: 'Coahuila de Zaragoza', | |
variant: 'Coahuila', | |
}, | |
{ | |
code: 'MX-COL', | |
name: 'Colima', | |
}, | |
{ | |
code: 'MX-DUR', | |
name: 'Durango', | |
}, | |
{ | |
code: 'MX-GUA', | |
name: 'Guanajuato', | |
}, | |
{ | |
code: 'MX-GRO', | |
name: 'Guerrero', | |
}, | |
{ | |
code: 'MX-HID', | |
name: 'Hidalgo', | |
}, | |
{ | |
code: 'MX-JAL', | |
name: 'Jalisco', | |
}, | |
{ | |
code: 'MX-MEX', | |
name: 'México', | |
}, | |
{ | |
code: 'MX-MIC', | |
name: 'Michoacán de Ocampo', | |
variant: 'Michoacán', | |
}, | |
{ | |
code: 'MX-MOR', | |
name: 'Morelos', | |
}, | |
{ | |
code: 'MX-NAY', | |
name: 'Nayarit', | |
}, | |
{ | |
code: 'MX-NLE', | |
name: 'Nuevo León', | |
}, | |
{ | |
code: 'MX-OAX', | |
name: 'Oaxaca', | |
}, | |
{ | |
code: 'MX-PUE', | |
name: 'Puebla', | |
}, | |
{ | |
code: 'MX-QUE', | |
name: 'Querétaro', | |
}, | |
{ | |
code: 'MX-ROO', | |
name: 'Quintana Roo', | |
}, | |
{ | |
code: 'MX-SLP', | |
name: 'San Luis Potosí', | |
}, | |
{ | |
code: 'MX-SIN', | |
name: 'Sinaloa', | |
}, | |
{ | |
code: 'MX-SON', | |
name: 'Sonora', | |
}, | |
{ | |
code: 'MX-TAB', | |
name: 'Tabasco', | |
}, | |
{ | |
code: 'MX-TAM', | |
name: 'Tamaulipas', | |
}, | |
{ | |
code: 'MX-TLA', | |
name: 'Tlaxcala', | |
}, | |
{ | |
code: 'MX-VER', | |
name: 'Veracruz de Ignacio de la Llave', | |
variant: 'Veracruz', | |
}, | |
{ | |
code: 'MX-YUC', | |
name: 'Yucatán', | |
}, | |
{ | |
code: 'MX-ZAC', | |
name: 'Zacatecas', | |
}, | |
]; | |
function stateIsoToStateName(isoCode) { | |
const found = isoStatesCodes.find(iso => | |
iso.code.includes(isoCode.toUpperCase()), | |
); | |
if (found) { | |
return found.variant || found.name; | |
} else { | |
return isoCode; | |
} | |
} | |
export default stateIsoToStateName; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment