@open-tender/utils 0.4.13 → 0.4.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/utils/cart.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Cart, CartItem, CartItemGroups, CartLevels, CartItemOption, CartOwner, CheckoutConfig, CheckoutFormAddress, CheckoutFormCustomer, CheckoutPromoCodes, CheckoutTenders, DisplayItem, DisplayItems, Favorites, GroupOrderGuest, GroupOrderGuests, MenuCategories, MenuItem, MenuItems, Money, NutritionalInfo, NutritionalInfoCalcs, Order, OrderCreate, OrderCreateDiscounts, OrderCreateSurcharges, OrderData, OrderItem, OrderItemGroups, Orders, SimpleCart, SimpleCartGroups, SimpleCartItem, SoldOut, Images, CartErrors, BaseItem, FavoritesLookup } from '@open-tender/types';
|
|
2
2
|
export declare const getItemOptions: <T extends BaseItem>(item: T) => BaseItem[];
|
|
3
3
|
export declare const makeModifierNames: <T extends BaseItem>(item: T) => string;
|
|
4
|
+
export declare const makeModifierNamesForGroups: (groups: CartItemGroups) => string;
|
|
4
5
|
export declare const hasGroupsBelowMin: (option: CartItemOption | null, groups: CartItemGroups) => boolean;
|
|
5
6
|
export declare const makeModifierGroups: (groups: CartItemGroups) => [CartItemGroups, CartLevels];
|
|
6
7
|
export declare const makeUpsellItems: (itemIds: number[], itemLookup: Record<string, MenuItem>) => (CartItemOption | CartItem)[];
|
package/dist/cjs/utils/cart.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeDeviceType = exports.checkAmountRemaining = exports.prepareOrder = exports.getDefaultTip = exports.validateCart = exports.makeSimpleCart = exports.decrementItem = exports.incrementItem = exports.removeItem = exports.addItem = exports.makeCartItemSignature = exports.makeItemSignature = exports.makeFavoritesLookup = exports.makeUniqueDisplayItems = exports.makeDisplayItems = exports.makeDisplayItem = exports.makeDisplayItemGroups = exports.makeItemImageUrl = exports.combineCarts = exports.compareCarts = exports.makeGuestLookup = exports.rehydrateCheckoutForm = exports.rehydrateCart = exports.rehydrateOrderItem = exports.calcCartCounts = exports.makeOrderItem = exports.checkSoldOut = exports.calcPrices = exports.calcNutritionalInfo = exports.calcNutrition = exports.makeUpsellItemsForCart = exports.makeUpsellItemIds = exports.makeUpsellItems = exports.makeModifierGroups = exports.hasGroupsBelowMin = exports.makeModifierNames = exports.getItemOptions = void 0;
|
|
3
|
+
exports.makeDeviceType = exports.checkAmountRemaining = exports.prepareOrder = exports.getDefaultTip = exports.validateCart = exports.makeSimpleCart = exports.decrementItem = exports.incrementItem = exports.removeItem = exports.addItem = exports.makeCartItemSignature = exports.makeItemSignature = exports.makeFavoritesLookup = exports.makeUniqueDisplayItems = exports.makeDisplayItems = exports.makeDisplayItem = exports.makeDisplayItemGroups = exports.makeItemImageUrl = exports.combineCarts = exports.compareCarts = exports.makeGuestLookup = exports.rehydrateCheckoutForm = exports.rehydrateCart = exports.rehydrateOrderItem = exports.calcCartCounts = exports.makeOrderItem = exports.checkSoldOut = exports.calcPrices = exports.calcNutritionalInfo = exports.calcNutrition = exports.makeUpsellItemsForCart = exports.makeUpsellItemIds = exports.makeUpsellItems = exports.makeModifierGroups = exports.hasGroupsBelowMin = exports.makeModifierNamesForGroups = exports.makeModifierNames = exports.getItemOptions = void 0;
|
|
4
4
|
const types_1 = require("@open-tender/types");
|
|
5
5
|
const helpers_1 = require("./helpers");
|
|
6
6
|
const favorites_1 = require("./favorites");
|
|
@@ -27,6 +27,22 @@ const makeModifierNames = (item) => {
|
|
|
27
27
|
.join(', ');
|
|
28
28
|
};
|
|
29
29
|
exports.makeModifierNames = makeModifierNames;
|
|
30
|
+
const makeModifierNamesForGroups = (groups) => {
|
|
31
|
+
return groups
|
|
32
|
+
.map(group => group.options.filter(option => option.quantity > 0))
|
|
33
|
+
.reduce((arr, i) => [...arr, ...i], [])
|
|
34
|
+
.map(i => {
|
|
35
|
+
const optionNames = (0, exports.makeModifierNamesForGroups)(i.groups);
|
|
36
|
+
const name = optionNames ? `${i.name} (${optionNames})` : i.name;
|
|
37
|
+
return Object.assign(Object.assign({}, i), { name });
|
|
38
|
+
})
|
|
39
|
+
.map(option => option.name)
|
|
40
|
+
.join(', ');
|
|
41
|
+
};
|
|
42
|
+
exports.makeModifierNamesForGroups = makeModifierNamesForGroups;
|
|
43
|
+
// export const makeModifierNames = <T extends BaseItem>(item: T): string => {
|
|
44
|
+
// return makeModifierNamesForGroups(item.groups)
|
|
45
|
+
// }
|
|
30
46
|
const hasGroupsBelowMin = (option, groups) => {
|
|
31
47
|
if (!groups || !groups.length)
|
|
32
48
|
return false;
|
|
@@ -86,8 +86,10 @@ const makeRecents = (recents, itemLookup, soldOut) => {
|
|
|
86
86
|
};
|
|
87
87
|
exports.makeRecents = makeRecents;
|
|
88
88
|
const makeRecentItems = (categories, soldOut, orders) => {
|
|
89
|
-
|
|
89
|
+
if (!orders.length)
|
|
90
|
+
return [];
|
|
90
91
|
const displayItems = (0, cart_1.makeUniqueDisplayItems)(orders);
|
|
92
|
+
const itemLookup = (0, exports.makeMenuItemLookup)(categories);
|
|
91
93
|
return (0, exports.makeRecents)(displayItems, itemLookup, soldOut);
|
|
92
94
|
};
|
|
93
95
|
exports.makeRecentItems = makeRecentItems;
|
|
@@ -109,6 +111,8 @@ const makeFavorites = (favorites, itemLookup, soldOut) => {
|
|
|
109
111
|
};
|
|
110
112
|
exports.makeFavorites = makeFavorites;
|
|
111
113
|
const makeFavoriteItems = (categories, soldOut, favorites) => {
|
|
114
|
+
if (!favorites.length)
|
|
115
|
+
return [];
|
|
112
116
|
const itemLookup = (0, exports.makeMenuItemLookup)(categories);
|
|
113
117
|
return (0, exports.makeFavorites)(favorites, itemLookup, soldOut);
|
|
114
118
|
};
|
package/dist/esm/utils/cart.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Cart, CartItem, CartItemGroups, CartLevels, CartItemOption, CartOwner, CheckoutConfig, CheckoutFormAddress, CheckoutFormCustomer, CheckoutPromoCodes, CheckoutTenders, DisplayItem, DisplayItems, Favorites, GroupOrderGuest, GroupOrderGuests, MenuCategories, MenuItem, MenuItems, Money, NutritionalInfo, NutritionalInfoCalcs, Order, OrderCreate, OrderCreateDiscounts, OrderCreateSurcharges, OrderData, OrderItem, OrderItemGroups, Orders, SimpleCart, SimpleCartGroups, SimpleCartItem, SoldOut, Images, CartErrors, BaseItem, FavoritesLookup } from '@open-tender/types';
|
|
2
2
|
export declare const getItemOptions: <T extends BaseItem>(item: T) => BaseItem[];
|
|
3
3
|
export declare const makeModifierNames: <T extends BaseItem>(item: T) => string;
|
|
4
|
+
export declare const makeModifierNamesForGroups: (groups: CartItemGroups) => string;
|
|
4
5
|
export declare const hasGroupsBelowMin: (option: CartItemOption | null, groups: CartItemGroups) => boolean;
|
|
5
6
|
export declare const makeModifierGroups: (groups: CartItemGroups) => [CartItemGroups, CartLevels];
|
|
6
7
|
export declare const makeUpsellItems: (itemIds: number[], itemLookup: Record<string, MenuItem>) => (CartItemOption | CartItem)[];
|
package/dist/esm/utils/cart.js
CHANGED
|
@@ -22,6 +22,21 @@ export const makeModifierNames = (item) => {
|
|
|
22
22
|
.map(option => option.name)
|
|
23
23
|
.join(', ');
|
|
24
24
|
};
|
|
25
|
+
export const makeModifierNamesForGroups = (groups) => {
|
|
26
|
+
return groups
|
|
27
|
+
.map(group => group.options.filter(option => option.quantity > 0))
|
|
28
|
+
.reduce((arr, i) => [...arr, ...i], [])
|
|
29
|
+
.map(i => {
|
|
30
|
+
const optionNames = makeModifierNamesForGroups(i.groups);
|
|
31
|
+
const name = optionNames ? `${i.name} (${optionNames})` : i.name;
|
|
32
|
+
return Object.assign(Object.assign({}, i), { name });
|
|
33
|
+
})
|
|
34
|
+
.map(option => option.name)
|
|
35
|
+
.join(', ');
|
|
36
|
+
};
|
|
37
|
+
// export const makeModifierNames = <T extends BaseItem>(item: T): string => {
|
|
38
|
+
// return makeModifierNamesForGroups(item.groups)
|
|
39
|
+
// }
|
|
25
40
|
export const hasGroupsBelowMin = (option, groups) => {
|
|
26
41
|
if (!groups || !groups.length)
|
|
27
42
|
return false;
|
|
@@ -79,8 +79,10 @@ export const makeRecents = (recents, itemLookup, soldOut) => {
|
|
|
79
79
|
}, []);
|
|
80
80
|
};
|
|
81
81
|
export const makeRecentItems = (categories, soldOut, orders) => {
|
|
82
|
-
|
|
82
|
+
if (!orders.length)
|
|
83
|
+
return [];
|
|
83
84
|
const displayItems = makeUniqueDisplayItems(orders);
|
|
85
|
+
const itemLookup = makeMenuItemLookup(categories);
|
|
84
86
|
return makeRecents(displayItems, itemLookup, soldOut);
|
|
85
87
|
};
|
|
86
88
|
export const makeFavorites = (favorites, itemLookup, soldOut) => {
|
|
@@ -100,6 +102,8 @@ export const makeFavorites = (favorites, itemLookup, soldOut) => {
|
|
|
100
102
|
}, []);
|
|
101
103
|
};
|
|
102
104
|
export const makeFavoriteItems = (categories, soldOut, favorites) => {
|
|
105
|
+
if (!favorites.length)
|
|
106
|
+
return [];
|
|
103
107
|
const itemLookup = makeMenuItemLookup(categories);
|
|
104
108
|
return makeFavorites(favorites, itemLookup, soldOut);
|
|
105
109
|
};
|
package/package.json
CHANGED