Class

Country

Country(options)

Create a new country information instance. Instances of this class encode information about country name.

The options can contain any of the following properties:

  • locale - specify the locale for this instance. Country names are provided in the language of this locale.
  • onLoad - a callback function to call when the country name data is fully loaded. When the onLoad option is given, this class will attempt to load any missing locale data using the ilib loader callback. When the constructor is done (even if the data is already preassembled), the onLoad function is called with the current instance as a parameter, so this callback can be used with preassembled or dynamic loading or a mix of the two.
  • sync - tell whether to load any missing locale data synchronously or asynchronously. If this option is given as "false", then the "onLoad" callback must be given, as the instance returned from this constructor will not be usable for a while.
  • loadParams - an object containing parameters to pass to the loader callback function when locale data is missing. The parameters are not interpretted or modified in any way. They are simply passed along. The object may contain any property/value pairs as long as the calling code is in agreement with the loader callback function as to what those parameters mean.

If the locale is not set, the default locale(en-US) will be used.

Constructor

# new Country(options)

Parameters:
Name Type Description
options Object

a set of properties to govern how this instance is constructed.

View Source Country.js, line 63

Methods

# getCode(ctryname) → {string}

Return the country code corresponding to the country name given. If the country name is given, but it is not found in the list of known countries, this method will throw an exception.

Parameters:
Name Type Description
ctryname string

The country name in the language of the locale of this instance

View Source Country.js, line 180

"Country xx is unknown" when the given country name is not in the list of known country names. xx is replaced with the requested country name.

the country code corresponding to the country name

string

# getLocale() → {Locale}

Return the locale for this country. If the options to the constructor included a locale property in order to find the country that is appropriate for that locale, then the locale is returned here. If the options did not include a locale, then this method returns undefined.

View Source Country.js, line 211

the locale used in the constructor of this instance, or undefined if no locale was given in the constructor

Locale

# getName(code) → {string}

Return the country name corresponding to the country code given. If the code is given, but it is not found in the list of known countries, this method will throw an exception.

Parameters:
Name Type Description
code string

The country code to get the country name

View Source Country.js, line 196

"Country xx is unknown" when the given country code is not in the list of known country codes. xx is replaced with the requested country code.

the country name in the language of the locale of this instance

string

# static getAvailableCode() → {Object}

Return an array of the ids for all ISO 3166-1 alpha-2 code that this copy of ilib knows about.

View Source Country.js, line 124

an object of country code that this copy of ilib knows about.

Object

# static getAvailableCountry() → {Object}

Return an array of country names that this copy of ilib knows about.

View Source Country.js, line 138

an object of country code that this copy of ilib knows about.

Object