@open-tender/utils 0.1.6 → 0.1.7

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.
@@ -1,10 +1,11 @@
1
- import { UnpreparedOrderData, Money, Order, Tender, CheckoutConfig, SoldOut, MenuCategories, Address, MenuItem, CartItem, OrderItem, Cart, Favorites, Orders, CartItemGroups, Customer, CartItemOption, CartOwner, SimpleCartItem, MenuItems, SimpleCart, SimpleCartGroups, OrderItemGroups, NutritionalInfoCalcs, OrderItemImages, DisplayItems, DisplayItem, GroupOrderGuests, GroupOrderGuest, CartLevels } from '@open-tender/types';
1
+ import { UnpreparedOrderData, Money, Order, Tender, CheckoutConfig, SoldOut, MenuCategories, Address, MenuItem, CartItem, OrderItem, Cart, Favorites, Orders, CartItemGroups, Customer, CartItemOption, CartOwner, SimpleCartItem, MenuItems, SimpleCart, SimpleCartGroups, OrderItemGroups, NutritionalInfoCalcs, OrderItemImages, DisplayItems, DisplayItem, GroupOrderGuests, GroupOrderGuest, CartLevels, NutritionalInfo } from '@open-tender/types';
2
2
  export declare const getItemOptions: (item: Partial<CartItem>) => CartItemOption[];
3
3
  export declare const makeModifierNames: (item: CartItem) => string;
4
4
  export declare const hasGroupsBelowMin: (option: CartItemOption | null, groups: CartItemGroups) => boolean;
5
5
  export declare const makeModifierGroups: (groups: CartItemGroups) => [CartItemGroups, CartLevels];
6
6
  export declare const makeUpsellItems: (itemIds: number[], itemLookup: Record<string, MenuItem>) => (CartItem | CartItemOption)[];
7
7
  export declare const calcNutrition: (item: CartItem | CartItemOption) => NutritionalInfoCalcs;
8
+ export declare const calcNutritionalInfo: (item: CartItem | CartItemOption) => NutritionalInfo;
8
9
  export declare const calcPrices: (item: CartItem | CartItemOption) => CartItem | CartItemOption;
9
10
  export declare const checkSoldOut: (id: number, suspendUntil: number | null, soldOut?: number[]) => boolean;
10
11
  export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?: SoldOut, simpleItem?: SimpleCartItem, hasPoints?: boolean) => CartItem | CartItemOption;
@@ -32,7 +33,7 @@ export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Simp
32
33
  max: number;
33
34
  min: number;
34
35
  name: string;
35
- nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
36
+ nutritionalInfo: NutritionalInfo | null;
36
37
  points: number | null;
37
38
  price: number;
38
39
  quantity: number;
@@ -91,7 +92,7 @@ export declare const combineCarts: (cart: Cart, guestCart: SimpleCart, cartOwner
91
92
  max: number;
92
93
  min: number;
93
94
  name: string;
94
- nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
95
+ nutritionalInfo: NutritionalInfo | null;
95
96
  points: number | null;
96
97
  price: number;
97
98
  quantity: number;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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.makeGuestLookup = exports.rehydrateCheckoutForm = exports.rehydrateCart = exports.rehydrateOrderItem = exports.calcCartCounts = exports.makeOrderItem = exports.checkSoldOut = exports.calcPrices = exports.calcNutrition = exports.makeUpsellItems = exports.makeModifierGroups = exports.hasGroupsBelowMin = exports.makeModifierNames = exports.getItemOptions = void 0;
3
+ 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.makeGuestLookup = exports.rehydrateCheckoutForm = exports.rehydrateCart = exports.rehydrateOrderItem = exports.calcCartCounts = exports.makeOrderItem = exports.checkSoldOut = exports.calcPrices = exports.calcNutritionalInfo = exports.calcNutrition = exports.makeUpsellItems = exports.makeModifierGroups = exports.hasGroupsBelowMin = exports.makeModifierNames = exports.getItemOptions = void 0;
4
4
  const helpers_1 = require("./helpers");
5
5
  // TODO: refactor for nested mods
6
6
  const getItemOptions = (item) => {
@@ -92,6 +92,12 @@ const calcNutrition = (item) => {
92
92
  return nutrition;
93
93
  };
94
94
  exports.calcNutrition = calcNutrition;
95
+ const calcNutritionalInfo = (item) => {
96
+ const nutrition = (0, exports.calcNutrition)(item);
97
+ const { serving_size = '0.00' } = item.nutritionalInfo || {};
98
+ return Object.assign(Object.assign({}, nutrition), { serving_size });
99
+ };
100
+ exports.calcNutritionalInfo = calcNutritionalInfo;
95
101
  const calcPrices = (item) => {
96
102
  const groups = item.groups.map(g => {
97
103
  let groupQuantity = 0;
@@ -1,10 +1,11 @@
1
- import { UnpreparedOrderData, Money, Order, Tender, CheckoutConfig, SoldOut, MenuCategories, Address, MenuItem, CartItem, OrderItem, Cart, Favorites, Orders, CartItemGroups, Customer, CartItemOption, CartOwner, SimpleCartItem, MenuItems, SimpleCart, SimpleCartGroups, OrderItemGroups, NutritionalInfoCalcs, OrderItemImages, DisplayItems, DisplayItem, GroupOrderGuests, GroupOrderGuest, CartLevels } from '@open-tender/types';
1
+ import { UnpreparedOrderData, Money, Order, Tender, CheckoutConfig, SoldOut, MenuCategories, Address, MenuItem, CartItem, OrderItem, Cart, Favorites, Orders, CartItemGroups, Customer, CartItemOption, CartOwner, SimpleCartItem, MenuItems, SimpleCart, SimpleCartGroups, OrderItemGroups, NutritionalInfoCalcs, OrderItemImages, DisplayItems, DisplayItem, GroupOrderGuests, GroupOrderGuest, CartLevels, NutritionalInfo } from '@open-tender/types';
2
2
  export declare const getItemOptions: (item: Partial<CartItem>) => CartItemOption[];
3
3
  export declare const makeModifierNames: (item: CartItem) => string;
4
4
  export declare const hasGroupsBelowMin: (option: CartItemOption | null, groups: CartItemGroups) => boolean;
5
5
  export declare const makeModifierGroups: (groups: CartItemGroups) => [CartItemGroups, CartLevels];
6
6
  export declare const makeUpsellItems: (itemIds: number[], itemLookup: Record<string, MenuItem>) => (CartItem | CartItemOption)[];
7
7
  export declare const calcNutrition: (item: CartItem | CartItemOption) => NutritionalInfoCalcs;
8
+ export declare const calcNutritionalInfo: (item: CartItem | CartItemOption) => NutritionalInfo;
8
9
  export declare const calcPrices: (item: CartItem | CartItemOption) => CartItem | CartItemOption;
9
10
  export declare const checkSoldOut: (id: number, suspendUntil: number | null, soldOut?: number[]) => boolean;
10
11
  export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?: SoldOut, simpleItem?: SimpleCartItem, hasPoints?: boolean) => CartItem | CartItemOption;
@@ -32,7 +33,7 @@ export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Simp
32
33
  max: number;
33
34
  min: number;
34
35
  name: string;
35
- nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
36
+ nutritionalInfo: NutritionalInfo | null;
36
37
  points: number | null;
37
38
  price: number;
38
39
  quantity: number;
@@ -91,7 +92,7 @@ export declare const combineCarts: (cart: Cart, guestCart: SimpleCart, cartOwner
91
92
  max: number;
92
93
  min: number;
93
94
  name: string;
94
- nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
95
+ nutritionalInfo: NutritionalInfo | null;
95
96
  points: number | null;
96
97
  price: number;
97
98
  quantity: number;
@@ -83,6 +83,11 @@ export const calcNutrition = (item) => {
83
83
  });
84
84
  return nutrition;
85
85
  };
86
+ export const calcNutritionalInfo = (item) => {
87
+ const nutrition = calcNutrition(item);
88
+ const { serving_size = '0.00' } = item.nutritionalInfo || {};
89
+ return Object.assign(Object.assign({}, nutrition), { serving_size });
90
+ };
86
91
  export const calcPrices = (item) => {
87
92
  const groups = item.groups.map(g => {
88
93
  let groupQuantity = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "A library of utils for use with Open Tender applications that utilize our cloud-based Order API.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",