UNPKG

@vendasta/store

Version:

Components and data for Store

73 lines (72 loc) 2.76 kB
import { File } from '../files/index'; import { CaseTransform } from './case-transform'; var COLOR_CODES = [ '#EF5350', '#42A5F5', '#66BB6A', '#FFA726', '#AB47BC', '#FFCA28', '#EC407A', '#26C6DA', '#FF7B57' ]; var DEFAULT_COLOR = '#808080'; var Product = /** @class */ (function () { function Product(data) { this.addons = []; data = data || {}; this.productId = data.productId; this.name = data.name; this.description = data.description; this.tagline = data.tagline; this.iconUrl = data.iconUrl; this.entryUrl = data.entryUrl; this.screenshotUrls = data.screenshotUrls; this.pdfUploadUrls = data.pdfUploadUrls; this.lmiCategories = data.lmiCategories; this.keySellingPoints = data.keySellingPoints; this.faqs = data.faqs; this.wholesalePrice = data.wholesalePrice; this.currency = data.currency; this.billingFrequency = data.billingFrequency; this.isArchived = data.isArchived; this.addons = data.addons; if (data.hasOwnProperty('pdfUploadUrls')) { this.files = this.pdfUploadUrls ? this.pdfUploadUrls.map(function (url) { return new File(url); }) : null; } } Product.fromApi = function (data) { var newProduct = {}; data = data || {}; for (var key in data) { if (data.hasOwnProperty(key)) { var newKey = CaseTransform.snakeToCamelCase(key); newProduct[newKey] = data[key]; } } return new Product(newProduct); }; Object.defineProperty(Product.prototype, "iconStyle", { get: function () { return this.iconUrl ? "url(\"" + this.iconUrl + "\") no-repeat center / 100% 100%" : null; }, enumerable: true, configurable: true }); Object.defineProperty(Product.prototype, "iconColor", { get: function () { // determine an icon color for a product with no icon by using the product name if (!this.name) { return DEFAULT_COLOR; } var nameSum = 0; for (var i = 0; i < this.name.length; i++) { nameSum += this.name[i].charCodeAt(0); } var index = nameSum % COLOR_CODES.length; return COLOR_CODES[index]; }, enumerable: true, configurable: true }); Product.prototype.getLmiCategoryNames = function () { var lmiCategories = this.lmiCategories || []; return lmiCategories.map(function (lmiCategory) { return CaseTransform.lowerToTitleCase(lmiCategory.toLowerCase().replace(/_/g, ' ')); }); }; return Product; }()); export { Product };