Country List, in Spanish
What is this?
Get the country name in Spanish for any ISO 3166-1 alpha-2 country code, and vice versa.
The full list of 262 country names and codes in this package is composed as follows:
- 249 officially assigned code elements.
- 12 exceptionally reserved code elements.
- 1 extra code element added for functionallity.
Installation
As with any other node package:
npm install country-list-spanish
Usage
The package exports four functions:
getCountry(code)
Arguments: 1, string
, an ISO 3166-1 alpha-2 code.
Returns: string
, a country name in Spanish.
If the code parameter is left empty or it's not in the list, returns undefined
.
Example
const getCountry = ; console; // logs 'San Pedro y Miquelón'console; // logs 'Islas Canarias'console; // logs undefined
getCode(country)
Arguments: 1, string
, a country name in Spanish.
Returns: string
, an ISO 3166-1 alpha-2 code.
If the country parameter is left empty or it's not in the list, returns undefined
.
Example
const getCode = ; console; // logs 'PM'console; // logs 'IC'console; // logs undefined
getCountries(config)
Arguments: 0 or 1, object
, a config object (see table below and examples).
Returns: array
(default) or object
, with all the countries in the list.
By default, the function returns an array with all 249 official country names in it.
If {object: true}
is passed as config, the function returns an object of code-country (key-value) pairs.
If {extended: true}
is passed, the exceptionally reserved codes are included in the response.
Example
const getCountries = ; console; // logs [Andorra, Emiratos Árabes Unidos, ...], an array of length 249console; // logs {AD: "Andorra", AE: "Emiratos Árabes Unidos", ...}, an object with 262 kay-value pairs
getCodes(config)
Arguments: 0 or 1, object
, a config object (see below).
Returns: array
(default) or object
, with all the codes in the list.
By default, the function returns an array with all 249 official codes in it.
If {object: true}
is passed as config, the function returns an object of country-code (key-value) pairs.
If {extended: true}
is passed, the exceptionally reserved codes are included in the response.
const getCodes = ; console; // logs {Andorra: "AD", Emiratos Árabes Unidos: "AE", ...}, an object with 249 kay-value pairs
Config object
param | type | default | feature |
---|---|---|---|
object | boolean |
false | Return an array or an object |
extended | boolean |
false | Include the 13 reserved/extra codes or not |