@open-tender/utils 0.0.25 → 0.0.27
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 +1 -0
- package/dist/cjs/utils/cart.js +32 -1
- package/dist/cjs/utils/favorites.d.ts +3 -2
- package/dist/cjs/utils/favorites.js +14 -1
- package/dist/esm/utils/cart.d.ts +1 -0
- package/dist/esm/utils/cart.js +30 -0
- package/dist/esm/utils/favorites.d.ts +3 -2
- package/dist/esm/utils/favorites.js +12 -0
- package/package.json +1 -1
package/dist/cjs/utils/cart.d.ts
CHANGED
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.makeUpsellItems = exports.checkAmountRemaining = exports.prepareOrder = exports.getDefaultTip = exports.validateCart = exports.makeSimpleCart = exports.decrementItem = exports.incrementItem = exports.removeItem = exports.addItem = exports.calcCartCounts = exports.makeFullAddress = exports.makeOrderAddress = exports.makeFavoritesLookup = exports.makeUniqueDisplayItems = exports.makeDisplayItems = exports.makeDisplayItem = exports.makeDisplayItemGroups = exports.makeCartItemSignature = exports.makeItemSignature = exports.makeItemImageUrl = exports.combineCarts = exports.makeGuestLookup = exports.rehydrateCheckoutForm = exports.rehydrateCart = exports.rehydrateOrderItem = exports.makeOrderItem = exports.calcPrices = exports.makeRevenueCenterMsg = exports.makeNotAcceptingOrdersMsg = exports.makeOrderTypeName = exports.makeServiceTypeName = exports.makeOrderTypeFromParam = exports.convertStringToArray = exports.makeModifierNames = exports.getItemOptions = exports.formatDollars = exports.formatQuantity = exports.addCommas = exports.makeDisplayPrice = exports.displayPrice = void 0;
|
|
3
|
+
exports.calcNutrition = exports.makeUpsellItems = exports.checkAmountRemaining = exports.prepareOrder = exports.getDefaultTip = exports.validateCart = exports.makeSimpleCart = exports.decrementItem = exports.incrementItem = exports.removeItem = exports.addItem = exports.calcCartCounts = exports.makeFullAddress = exports.makeOrderAddress = exports.makeFavoritesLookup = exports.makeUniqueDisplayItems = exports.makeDisplayItems = exports.makeDisplayItem = exports.makeDisplayItemGroups = exports.makeCartItemSignature = exports.makeItemSignature = exports.makeItemImageUrl = exports.combineCarts = exports.makeGuestLookup = exports.rehydrateCheckoutForm = exports.rehydrateCart = exports.rehydrateOrderItem = exports.makeOrderItem = exports.calcPrices = exports.makeRevenueCenterMsg = exports.makeNotAcceptingOrdersMsg = exports.makeOrderTypeName = exports.makeServiceTypeName = exports.makeOrderTypeFromParam = exports.convertStringToArray = exports.makeModifierNames = exports.getItemOptions = exports.formatDollars = exports.formatQuantity = exports.addCommas = exports.makeDisplayPrice = exports.displayPrice = void 0;
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
5
|
const datetimes_1 = require("./datetimes");
|
|
6
6
|
const helpers_1 = require("./helpers");
|
|
@@ -860,3 +860,34 @@ const makeUpsellItems = (itemIds, itemLookup) => {
|
|
|
860
860
|
});
|
|
861
861
|
};
|
|
862
862
|
exports.makeUpsellItems = makeUpsellItems;
|
|
863
|
+
const nutritionKeys = [
|
|
864
|
+
'calories',
|
|
865
|
+
'cholesterol',
|
|
866
|
+
'dietary_fiber',
|
|
867
|
+
'protein',
|
|
868
|
+
'saturated_fat',
|
|
869
|
+
'sodium',
|
|
870
|
+
'sugars',
|
|
871
|
+
'total_carbs',
|
|
872
|
+
'total_fat',
|
|
873
|
+
'trans_fat',
|
|
874
|
+
];
|
|
875
|
+
const calcNutrition = (item) => {
|
|
876
|
+
const { nutritionalInfo, groups } = item;
|
|
877
|
+
let nutrition = nutritionalInfo ? Object.assign({}, nutritionalInfo) : {};
|
|
878
|
+
const options = groups.reduce((arr, g) => {
|
|
879
|
+
var _a, _b;
|
|
880
|
+
return [...arr, ...((_b = (_a = g.options) === null || _a === void 0 ? void 0 : _a.filter((o) => { var _a; return ((_a = o.quantity) !== null && _a !== void 0 ? _a : 0) > 0; })) !== null && _b !== void 0 ? _b : [])];
|
|
881
|
+
}, []);
|
|
882
|
+
options.forEach((o) => {
|
|
883
|
+
nutritionKeys === null || nutritionKeys === void 0 ? void 0 : nutritionKeys.forEach((key) => {
|
|
884
|
+
const optionVal = o.nutritionalInfo
|
|
885
|
+
? parseInt(o.nutritionalInfo[key]) || 0
|
|
886
|
+
: 0;
|
|
887
|
+
const itemVal = parseInt(nutrition[key]) || 0;
|
|
888
|
+
nutrition = Object.assign(Object.assign({}, nutrition), { [key]: itemVal + optionVal });
|
|
889
|
+
});
|
|
890
|
+
});
|
|
891
|
+
return nutrition;
|
|
892
|
+
};
|
|
893
|
+
exports.calcNutrition = calcNutrition;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { CartItem, MenuCategories, MenuItem, SoldOut } from "@open-tender/types";
|
|
1
|
+
import { CartItem, FavoriteItem, Favorites, MenuCategories, MenuItem, SoldOut } from "@open-tender/types";
|
|
2
2
|
export declare const makeMenuItemLookup: (categories: MenuCategories) => any;
|
|
3
3
|
export declare const makeFeatured: (categories: MenuCategories) => any;
|
|
4
4
|
export declare const makeMenuGroupsLookup: (menuItem: MenuItem) => any;
|
|
5
|
-
export declare const makeRecents: (recents: Partial<CartItem>[], itemLookup: any, soldOut: SoldOut) => any;
|
|
5
|
+
export declare const makeRecents: (recents: Partial<CartItem & FavoriteItem>[], itemLookup: any, soldOut: SoldOut) => any;
|
|
6
|
+
export declare const makeFavorites: (favorites: Favorites, itemLookup: any, soldOut: SoldOut) => any;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeRecents = exports.makeMenuGroupsLookup = exports.makeFeatured = exports.makeMenuItemLookup = void 0;
|
|
3
|
+
exports.makeFavorites = exports.makeRecents = exports.makeMenuGroupsLookup = exports.makeFeatured = exports.makeMenuItemLookup = void 0;
|
|
4
4
|
const makeMenuItemLookup = (categories) => {
|
|
5
5
|
const cats = categories.reduce((arr, cat) => {
|
|
6
6
|
return [...arr, cat, ...(cat.children || [])];
|
|
@@ -81,3 +81,16 @@ const makeRecents = (recents, itemLookup, soldOut) => {
|
|
|
81
81
|
}, []);
|
|
82
82
|
};
|
|
83
83
|
exports.makeRecents = makeRecents;
|
|
84
|
+
const makeFavorites = (favorites, itemLookup, soldOut) => {
|
|
85
|
+
return favorites.reduce((arr, favorite) => {
|
|
86
|
+
var _a, _b;
|
|
87
|
+
if ((_a = favorite === null || favorite === void 0 ? void 0 : favorite.item) === null || _a === void 0 ? void 0 : _a.id) {
|
|
88
|
+
const menuItem = itemLookup[(_b = favorite === null || favorite === void 0 ? void 0 : favorite.item) === null || _b === void 0 ? void 0 : _b.id];
|
|
89
|
+
if (!menuItem)
|
|
90
|
+
return arr;
|
|
91
|
+
const isValid = validateFavorite(favorite.item, menuItem, soldOut);
|
|
92
|
+
return isValid ? [...arr, Object.assign(Object.assign({}, menuItem), { favorite })] : arr;
|
|
93
|
+
}
|
|
94
|
+
}, []);
|
|
95
|
+
};
|
|
96
|
+
exports.makeFavorites = makeFavorites;
|
package/dist/esm/utils/cart.d.ts
CHANGED
package/dist/esm/utils/cart.js
CHANGED
|
@@ -816,3 +816,33 @@ export const makeUpsellItems = (itemIds, itemLookup) => {
|
|
|
816
816
|
return (belowMin === null || belowMin === void 0 ? void 0 : belowMin.length) === 0;
|
|
817
817
|
});
|
|
818
818
|
};
|
|
819
|
+
const nutritionKeys = [
|
|
820
|
+
'calories',
|
|
821
|
+
'cholesterol',
|
|
822
|
+
'dietary_fiber',
|
|
823
|
+
'protein',
|
|
824
|
+
'saturated_fat',
|
|
825
|
+
'sodium',
|
|
826
|
+
'sugars',
|
|
827
|
+
'total_carbs',
|
|
828
|
+
'total_fat',
|
|
829
|
+
'trans_fat',
|
|
830
|
+
];
|
|
831
|
+
export const calcNutrition = (item) => {
|
|
832
|
+
const { nutritionalInfo, groups } = item;
|
|
833
|
+
let nutrition = nutritionalInfo ? Object.assign({}, nutritionalInfo) : {};
|
|
834
|
+
const options = groups.reduce((arr, g) => {
|
|
835
|
+
var _a, _b;
|
|
836
|
+
return [...arr, ...((_b = (_a = g.options) === null || _a === void 0 ? void 0 : _a.filter((o) => { var _a; return ((_a = o.quantity) !== null && _a !== void 0 ? _a : 0) > 0; })) !== null && _b !== void 0 ? _b : [])];
|
|
837
|
+
}, []);
|
|
838
|
+
options.forEach((o) => {
|
|
839
|
+
nutritionKeys === null || nutritionKeys === void 0 ? void 0 : nutritionKeys.forEach((key) => {
|
|
840
|
+
const optionVal = o.nutritionalInfo
|
|
841
|
+
? parseInt(o.nutritionalInfo[key]) || 0
|
|
842
|
+
: 0;
|
|
843
|
+
const itemVal = parseInt(nutrition[key]) || 0;
|
|
844
|
+
nutrition = Object.assign(Object.assign({}, nutrition), { [key]: itemVal + optionVal });
|
|
845
|
+
});
|
|
846
|
+
});
|
|
847
|
+
return nutrition;
|
|
848
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { CartItem, MenuCategories, MenuItem, SoldOut } from "@open-tender/types";
|
|
1
|
+
import { CartItem, FavoriteItem, Favorites, MenuCategories, MenuItem, SoldOut } from "@open-tender/types";
|
|
2
2
|
export declare const makeMenuItemLookup: (categories: MenuCategories) => any;
|
|
3
3
|
export declare const makeFeatured: (categories: MenuCategories) => any;
|
|
4
4
|
export declare const makeMenuGroupsLookup: (menuItem: MenuItem) => any;
|
|
5
|
-
export declare const makeRecents: (recents: Partial<CartItem>[], itemLookup: any, soldOut: SoldOut) => any;
|
|
5
|
+
export declare const makeRecents: (recents: Partial<CartItem & FavoriteItem>[], itemLookup: any, soldOut: SoldOut) => any;
|
|
6
|
+
export declare const makeFavorites: (favorites: Favorites, itemLookup: any, soldOut: SoldOut) => any;
|
|
@@ -74,3 +74,15 @@ export const makeRecents = (recents, itemLookup, soldOut) => {
|
|
|
74
74
|
}
|
|
75
75
|
}, []);
|
|
76
76
|
};
|
|
77
|
+
export const makeFavorites = (favorites, itemLookup, soldOut) => {
|
|
78
|
+
return favorites.reduce((arr, favorite) => {
|
|
79
|
+
var _a, _b;
|
|
80
|
+
if ((_a = favorite === null || favorite === void 0 ? void 0 : favorite.item) === null || _a === void 0 ? void 0 : _a.id) {
|
|
81
|
+
const menuItem = itemLookup[(_b = favorite === null || favorite === void 0 ? void 0 : favorite.item) === null || _b === void 0 ? void 0 : _b.id];
|
|
82
|
+
if (!menuItem)
|
|
83
|
+
return arr;
|
|
84
|
+
const isValid = validateFavorite(favorite.item, menuItem, soldOut);
|
|
85
|
+
return isValid ? [...arr, Object.assign(Object.assign({}, menuItem), { favorite })] : arr;
|
|
86
|
+
}
|
|
87
|
+
}, []);
|
|
88
|
+
};
|
package/package.json
CHANGED