diff --git a/src/index.html b/src/index.html index 81adcff..e45b610 100644 --- a/src/index.html +++ b/src/index.html @@ -5,13 +5,13 @@ - + + - - - + + diff --git a/src/modules/product.js b/src/modules/product.js index f8f8bba..78e98ab 100644 --- a/src/modules/product.js +++ b/src/modules/product.js @@ -3,27 +3,37 @@ class Product { * Stwórz produkt o określonej nazwie i ikonie * @param {string} name * @param {string} icon - * @example const product = new Product('apple', 'fa-apple') + * @example const product = new Product('apple', 'fa-apple-alt') */ constructor(name, icon) { this.name = name; - this.icon = icon; + + const match = /^([a-z]+)-(.*)/.exec(icon); + if (match) { + const [_, prefix, iconName] = match; + const result = FontAwesome.findIconDefinition({ prefix, iconName }); + if (!result) + throw new Error('Font Awesome does NOT have this icon'); + this.icon = String.fromCodePoint(parseInt(result.icon[3], 16)); + } else { + this.icon = icon; + } } equals(other) { - return this.name === other.name + return this.name === other.name; } static get REGISTRY() { return { empty: new Product('', ''), - apple: new Product('apple', '\uf5d1'), - bacon: new Product('bacon', '\uf7e5'), - bone: new Product('bone', '\uf5d7'), - bread: new Product('bread', '\uf7ec'), - candyCane: new Product('candy cane', '\uf786'), - carrot: new Product('carrot', '\uf787'), - cheese: new Product('cheese', '\uf7ef') + apple: new Product('apple', 'fa-apple-alt'), + bacon: new Product('bacon', 'fa-bacon'), + bone: new Product('bone', 'fa-bone'), + bread: new Product('bread', 'fa-bread-slice'), + candyCane: new Product('candy cane', 'fa-candy-cane'), + carrot: new Product('carrot', 'fa-carrot'), + cheese: new Product('cheese', 'fa-cheese') }; }