Initial content

This commit is contained in:
Adam Freeman
2024-05-29 18:54:49 +01:00
parent 2dbc1a8088
commit 5215a1d919
1944 changed files with 203378 additions and 0 deletions
@@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.countCartItems = void 0;
const countCartItems = (cart) => cart.lines.reduce((total, line) => total + line.quantity, 0);
exports.countCartItems = countCartItems;
@@ -0,0 +1,70 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.currency = exports.highlight = exports.categoryButtons = exports.pageSizeOptions = exports.pageButtons = exports.escapeUrl = exports.navigationUrl = void 0;
const handlebars_1 = __importDefault(require("handlebars"));
const querystring_1 = require("querystring");
const querystring_2 = require("querystring");
const getData = (options) => {
return { ...options.data.root, ...options.hash };
};
const navigationUrl = (options) => {
const { page, pageSize, category, searchTerm } = getData(options);
return "/?" + (0, querystring_1.stringify)({ page, pageSize, category, searchTerm });
};
exports.navigationUrl = navigationUrl;
const escapeUrl = (url) => (0, querystring_2.escape)(url);
exports.escapeUrl = escapeUrl;
const pageButtons = (options) => {
const { page, pageCount } = getData(options);
let output = "";
for (let i = 1; i <= pageCount; i++) {
output += options.fn({
page, pageCount, index: i, selected: i === page
});
}
return output;
};
exports.pageButtons = pageButtons;
const pageSizeOptions = (options) => {
const { pageSize } = getData(options);
let output = "";
[3, 6, 9].forEach(size => {
output += options.fn({ size,
selected: pageSize === size ? "selected" : "" });
});
return output;
};
exports.pageSizeOptions = pageSizeOptions;
const categoryButtons = (options) => {
const { category, categories } = getData(options);
let output = "";
for (let i = 0; i < categories.length; i++) {
output += options.fn({
id: categories[i].id,
name: categories[i].name,
selected: category === categories[i].id
});
}
return output;
};
exports.categoryButtons = categoryButtons;
const highlight = (value, options) => {
const { searchTerm } = getData(options);
if (searchTerm && searchTerm !== "") {
const regexp = new RegExp(searchTerm, "ig");
const mod = value.replaceAll(regexp, "<strong>$&</strong>");
return new handlebars_1.default.SafeString(mod);
}
return value;
};
exports.highlight = highlight;
const formatter = new Intl.NumberFormat("en-us", {
style: "currency", currency: "USD"
});
const currency = (value) => {
return formatter.format(value);
};
exports.currency = currency;
@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isDevelopment = void 0;
const config_1 = require("../config");
const isDevelopment = (value) => {
return (0, config_1.getEnvironment)() === config_1.Env.Development;
};
exports.isDevelopment = isDevelopment;
@@ -0,0 +1,44 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTemplates = void 0;
const config_1 = require("../config");
const express_handlebars_1 = require("express-handlebars");
const env_helpers = __importStar(require("./env"));
const catalog_helpers = __importStar(require("./catalog_helpers"));
const cart_helpers = __importStar(require("./cart_helpers"));
const order_helpers = __importStar(require("./order_helpers"));
const location = (0, config_1.getConfig)("templates:location");
const config = (0, config_1.getConfig)("templates:config");
const createTemplates = (app) => {
app.set("views", location);
app.engine("handlebars", (0, express_handlebars_1.engine)({
...config,
helpers: { ...env_helpers, ...catalog_helpers, ...cart_helpers,
...order_helpers }
}));
app.set("view engine", "handlebars");
};
exports.createTemplates = createTemplates;
@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.get = exports.getValue = exports.lower = exports.toArray = void 0;
const toArray = (...args) => args.slice(0, -1);
exports.toArray = toArray;
const lower = (val) => val.toLowerCase();
exports.lower = lower;
const getValue = (val, prop) => val?.[prop.toLowerCase()] ?? {};
exports.getValue = getValue;
const get = (val) => val ?? {};
exports.get = get;