@open-tender/utils 0.1.0 → 0.1.1

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,4 +1,4 @@
1
- export declare const useImage: (src: string) => {
1
+ export declare const useImage: (src: string | null | undefined) => {
2
2
  hasLoaded: boolean;
3
3
  hasError: boolean;
4
4
  hasStartedInitialFetch: boolean;
@@ -12,7 +12,8 @@ const useImage = (src) => {
12
12
  setHasLoaded(false);
13
13
  setHasError(false);
14
14
  const image = new Image();
15
- image.src = src;
15
+ if (src)
16
+ image.src = src;
16
17
  const handleError = () => {
17
18
  setHasError(true);
18
19
  };
@@ -605,16 +605,14 @@ const makeItemLookup = (categories, itemIds) => {
605
605
  const itemLookup = {};
606
606
  categories.forEach(category => {
607
607
  category.items.forEach(item => {
608
- var _a, _b;
609
- if (itemIds.includes((_a = item.id) !== null && _a !== void 0 ? _a : 0)) {
610
- itemLookup[(_b = item.id) !== null && _b !== void 0 ? _b : 0] = (0, exports.makeOrderItem)(item, true);
608
+ if (itemIds.includes(item.id)) {
609
+ itemLookup[item.id] = (0, exports.makeOrderItem)(item, true);
611
610
  }
612
611
  });
613
612
  category.children.forEach(child => {
614
613
  child.items.forEach(item => {
615
- var _a, _b;
616
- if (itemIds.includes((_a = item.id) !== null && _a !== void 0 ? _a : 0)) {
617
- itemLookup[(_b = item.id) !== null && _b !== void 0 ? _b : 0] = (0, exports.makeOrderItem)(item, true);
614
+ if (itemIds.includes(item.id)) {
615
+ itemLookup[item.id] = (0, exports.makeOrderItem)(item, true);
618
616
  }
619
617
  });
620
618
  });
@@ -623,18 +621,14 @@ const makeItemLookup = (categories, itemIds) => {
623
621
  };
624
622
  // TODO: refactor for nested modifiers
625
623
  const makeGroupsLookup = (item) => {
626
- var _a;
627
- return (_a = item.groups) === null || _a === void 0 ? void 0 : _a.reduce((grpObj, i) => {
628
- var _a;
629
- const options = (_a = i.options) === null || _a === void 0 ? void 0 : _a.reduce((optObj, o) => {
624
+ return item.groups.reduce((grpObj, i) => {
625
+ const options = i.options.reduce((optObj, o) => {
630
626
  if (o.id) {
631
627
  optObj[o.id] = o;
632
628
  }
633
629
  return optObj;
634
630
  }, {});
635
- if (i.id) {
636
- grpObj[i.id] = Object.assign(Object.assign({}, i), { options });
637
- }
631
+ grpObj[i.id] = Object.assign(Object.assign({}, i), { options });
638
632
  return grpObj;
639
633
  }, {});
640
634
  };
@@ -658,9 +652,9 @@ const validateCart = (cart, categories, soldOut) => {
658
652
  const invalidOptions = [];
659
653
  const newGroups = makeGroupsLookup(newItem);
660
654
  // check if any required groups for the new item are missing from the old item
661
- const newRequiredGroups = Object.values(newGroups).filter((i) => i.min > 0);
655
+ const newRequiredGroups = Object.values(newGroups).filter(i => i.min > 0);
662
656
  const oldGroupIds = (_a = oldItem.groups) === null || _a === void 0 ? void 0 : _a.map(i => i.id);
663
- missingGroups = newRequiredGroups.filter((i) => !(oldGroupIds === null || oldGroupIds === void 0 ? void 0 : oldGroupIds.includes(i.id)));
657
+ missingGroups = newRequiredGroups.filter(i => !(oldGroupIds === null || oldGroupIds === void 0 ? void 0 : oldGroupIds.includes(i.id)));
664
658
  const newEmptyGroups = Object.values(newGroups)
665
659
  .filter((i) => {
666
660
  return i.min === 0 && !(oldGroupIds === null || oldGroupIds === void 0 ? void 0 : oldGroupIds.includes(i.id));
@@ -1,4 +1,4 @@
1
- export declare const useImage: (src: string) => {
1
+ export declare const useImage: (src: string | null | undefined) => {
2
2
  hasLoaded: boolean;
3
3
  hasError: boolean;
4
4
  hasStartedInitialFetch: boolean;
@@ -9,7 +9,8 @@ export const useImage = (src) => {
9
9
  setHasLoaded(false);
10
10
  setHasError(false);
11
11
  const image = new Image();
12
- image.src = src;
12
+ if (src)
13
+ image.src = src;
13
14
  const handleError = () => {
14
15
  setHasError(true);
15
16
  };
@@ -574,16 +574,14 @@ const makeItemLookup = (categories, itemIds) => {
574
574
  const itemLookup = {};
575
575
  categories.forEach(category => {
576
576
  category.items.forEach(item => {
577
- var _a, _b;
578
- if (itemIds.includes((_a = item.id) !== null && _a !== void 0 ? _a : 0)) {
579
- itemLookup[(_b = item.id) !== null && _b !== void 0 ? _b : 0] = makeOrderItem(item, true);
577
+ if (itemIds.includes(item.id)) {
578
+ itemLookup[item.id] = makeOrderItem(item, true);
580
579
  }
581
580
  });
582
581
  category.children.forEach(child => {
583
582
  child.items.forEach(item => {
584
- var _a, _b;
585
- if (itemIds.includes((_a = item.id) !== null && _a !== void 0 ? _a : 0)) {
586
- itemLookup[(_b = item.id) !== null && _b !== void 0 ? _b : 0] = makeOrderItem(item, true);
583
+ if (itemIds.includes(item.id)) {
584
+ itemLookup[item.id] = makeOrderItem(item, true);
587
585
  }
588
586
  });
589
587
  });
@@ -592,18 +590,14 @@ const makeItemLookup = (categories, itemIds) => {
592
590
  };
593
591
  // TODO: refactor for nested modifiers
594
592
  const makeGroupsLookup = (item) => {
595
- var _a;
596
- return (_a = item.groups) === null || _a === void 0 ? void 0 : _a.reduce((grpObj, i) => {
597
- var _a;
598
- const options = (_a = i.options) === null || _a === void 0 ? void 0 : _a.reduce((optObj, o) => {
593
+ return item.groups.reduce((grpObj, i) => {
594
+ const options = i.options.reduce((optObj, o) => {
599
595
  if (o.id) {
600
596
  optObj[o.id] = o;
601
597
  }
602
598
  return optObj;
603
599
  }, {});
604
- if (i.id) {
605
- grpObj[i.id] = Object.assign(Object.assign({}, i), { options });
606
- }
600
+ grpObj[i.id] = Object.assign(Object.assign({}, i), { options });
607
601
  return grpObj;
608
602
  }, {});
609
603
  };
@@ -627,9 +621,9 @@ export const validateCart = (cart, categories, soldOut) => {
627
621
  const invalidOptions = [];
628
622
  const newGroups = makeGroupsLookup(newItem);
629
623
  // check if any required groups for the new item are missing from the old item
630
- const newRequiredGroups = Object.values(newGroups).filter((i) => i.min > 0);
624
+ const newRequiredGroups = Object.values(newGroups).filter(i => i.min > 0);
631
625
  const oldGroupIds = (_a = oldItem.groups) === null || _a === void 0 ? void 0 : _a.map(i => i.id);
632
- missingGroups = newRequiredGroups.filter((i) => !(oldGroupIds === null || oldGroupIds === void 0 ? void 0 : oldGroupIds.includes(i.id)));
626
+ missingGroups = newRequiredGroups.filter(i => !(oldGroupIds === null || oldGroupIds === void 0 ? void 0 : oldGroupIds.includes(i.id)));
633
627
  const newEmptyGroups = Object.values(newGroups)
634
628
  .filter((i) => {
635
629
  return i.min === 0 && !(oldGroupIds === null || oldGroupIds === void 0 ? void 0 : oldGroupIds.includes(i.id));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
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",