src/models/Language.js
/**
* Model representing a language.
*/
class LanguageModel {
/**
* @param {Object} [response] - JSON formatted response of a single Language
* @param {Number} response.id - The id of the language
* @param {String} response.name - The language name, like 'English'
* @param {String} response.iso - The language iso, like 'en'
* @param {Boolean} response.is_default - Whether or not this language is the default language
* @param {Object} [response.icon] - The language icon object
*/
constructor(response = {}) {
const _response = response.data || response; // if json api is passed in directly
const attributes = _response.attributes || _response; // if json api is passed in directly
if (_response.id) {
/** @type {Number} */
this.id = parseInt(_response.id, 10);
}
/** @type {String} */
this.iso = attributes.iso;
/** @type {String} */
this.name = attributes.name;
/** @type {Boolean} */
this.isDefault = attributes.is_default;
/**
* @type {Object}
* @property {String} this.icon.original
* @property {Object} this.icon.thumb
*/
this.icon = attributes.icon;
}
}
export default LanguageModel;