@open-tender/utils 0.1.149 → 0.1.151

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.
@@ -10,7 +10,6 @@ export declare const serialize: (obj: Record<string | number, string | number |
10
10
  export declare const capitalize: (s: string) => string;
11
11
  export declare const cleanPhone: (phone: string) => string;
12
12
  export declare const makePhone: (phone: string) => string;
13
- export declare const isPhone: (value: string) => boolean;
14
13
  export declare const validatePhone: (phone: string) => boolean;
15
14
  export declare const makeBirthDate: (birthDate: string) => string | null;
16
15
  export declare const slashesToDashes: (birthDate: string) => DateString | null;
@@ -43,7 +42,7 @@ export declare const formatQuantity: (n: string) => string;
43
42
  export declare const formatDollars: (str: string, space?: string, decimals?: number) => string;
44
43
  export declare const convertStringToArray: (str: string | null) => string[];
45
44
  export declare const hasEntities: <T extends unknown[]>(reducer: {
46
- entities: T;
45
+ entities: T | null;
47
46
  loading: RequestStatus;
48
47
  error: RequestError;
49
48
  }) => number | false;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasEntities = exports.convertStringToArray = exports.formatDollars = exports.formatQuantity = exports.addCommas = exports.displayPrice = exports.makeSlides = exports.makeImageUrl = exports.makeImageMap = exports.getHeight = exports.getWidth = exports.makeRandomNumberString = exports.checkNotFound = exports.checkGuestData = exports.checkEmpty = exports.validateEmail = exports.dashesToSlashes = exports.slashesToDashes = exports.makeBirthDate = exports.validatePhone = exports.isPhone = exports.makePhone = exports.cleanPhone = exports.capitalize = exports.serialize = exports.stripTags = exports.slugify = exports.contains = exports.isNum = exports.isEmpty = exports.isObject = exports.isString = void 0;
3
+ exports.hasEntities = exports.convertStringToArray = exports.formatDollars = exports.formatQuantity = exports.addCommas = exports.displayPrice = exports.makeSlides = exports.makeImageUrl = exports.makeImageMap = exports.getHeight = exports.getWidth = exports.makeRandomNumberString = exports.checkNotFound = exports.checkGuestData = exports.checkEmpty = exports.validateEmail = exports.dashesToSlashes = exports.slashesToDashes = exports.makeBirthDate = exports.validatePhone = exports.makePhone = exports.cleanPhone = exports.capitalize = exports.serialize = exports.stripTags = exports.slugify = exports.contains = exports.isNum = exports.isEmpty = exports.isObject = exports.isString = void 0;
4
4
  const isString = (str) => {
5
5
  return typeof str === 'string';
6
6
  };
@@ -74,10 +74,6 @@ const makePhone = (phone) => {
74
74
  return p;
75
75
  };
76
76
  exports.makePhone = makePhone;
77
- const isPhone = (value) => {
78
- return /^\d+$/.test(value.replace('-', ''));
79
- };
80
- exports.isPhone = isPhone;
81
77
  const validatePhone = (phone) => {
82
78
  var _a;
83
79
  if (!phone)
@@ -200,6 +196,8 @@ const hasEntities = (reducer) => {
200
196
  if (!reducer)
201
197
  return false;
202
198
  const { entities, loading, error } = reducer;
199
+ if (!entities)
200
+ return false;
203
201
  if (loading === 'pending' && !entities.length)
204
202
  return false;
205
203
  return !error && entities.length;
@@ -1,4 +1,4 @@
1
- import { MenuCategories, MenuDisplayedSections } from '@open-tender/types';
1
+ import { MenuCategories, MenuDisplayedSections, ThemeImagePosition } from '@open-tender/types';
2
2
  export declare const getBinaryArr: <T>(arr: T[]) => T[][];
3
3
  export declare const makeItemChunks: <T extends {
4
4
  id: number;
@@ -104,3 +104,8 @@ export declare const makeFlatCategories: (categories: MenuCategories) => {
104
104
  slug: string;
105
105
  small_image_url: string | null;
106
106
  }[];
107
+ export declare const makeMenuItemLayout: (position: ThemeImagePosition) => {
108
+ hideImage: boolean;
109
+ flexDirection: string;
110
+ alignItems: string;
111
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeFlatCategories = exports.makeOtherMenuSections = exports.makeItemChunks = exports.getBinaryArr = void 0;
3
+ exports.makeMenuItemLayout = exports.makeFlatCategories = exports.makeOtherMenuSections = exports.makeItemChunks = exports.getBinaryArr = void 0;
4
4
  const helpers_1 = require("./helpers");
5
5
  const getBinaryArr = (arr) => {
6
6
  const result = [];
@@ -45,3 +45,38 @@ const makeFlatCategories = (categories) => {
45
45
  .map(c => (Object.assign(Object.assign({}, c), { key: (0, helpers_1.slugify)(c.name), data: c.items.map((i, idx) => (Object.assign(Object.assign({}, i), { key: `${(0, helpers_1.slugify)(c.name)}-${i.id}-${idx}` }))) })));
46
46
  };
47
47
  exports.makeFlatCategories = makeFlatCategories;
48
+ const makeMenuItemLayout = (position) => {
49
+ switch (position) {
50
+ case 'HIDDEN':
51
+ return {
52
+ hideImage: true,
53
+ flexDirection: 'column',
54
+ alignItems: 'stretch'
55
+ };
56
+ case 'LEFT':
57
+ return {
58
+ hideImage: false,
59
+ flexDirection: 'row',
60
+ alignItems: 'flex-start'
61
+ };
62
+ case 'RIGHT':
63
+ return {
64
+ hideImage: false,
65
+ flexDirection: 'row-reverse',
66
+ alignItems: 'flex-start'
67
+ };
68
+ case 'BOTTOM':
69
+ return {
70
+ hideImage: false,
71
+ flexDirection: 'column-reverse',
72
+ alignItems: 'stretch'
73
+ };
74
+ default:
75
+ return {
76
+ hideImage: false,
77
+ flexDirection: 'column',
78
+ alignItems: 'stretch'
79
+ };
80
+ }
81
+ };
82
+ exports.makeMenuItemLayout = makeMenuItemLayout;
@@ -10,7 +10,6 @@ export declare const serialize: (obj: Record<string | number, string | number |
10
10
  export declare const capitalize: (s: string) => string;
11
11
  export declare const cleanPhone: (phone: string) => string;
12
12
  export declare const makePhone: (phone: string) => string;
13
- export declare const isPhone: (value: string) => boolean;
14
13
  export declare const validatePhone: (phone: string) => boolean;
15
14
  export declare const makeBirthDate: (birthDate: string) => string | null;
16
15
  export declare const slashesToDashes: (birthDate: string) => DateString | null;
@@ -43,7 +42,7 @@ export declare const formatQuantity: (n: string) => string;
43
42
  export declare const formatDollars: (str: string, space?: string, decimals?: number) => string;
44
43
  export declare const convertStringToArray: (str: string | null) => string[];
45
44
  export declare const hasEntities: <T extends unknown[]>(reducer: {
46
- entities: T;
45
+ entities: T | null;
47
46
  loading: RequestStatus;
48
47
  error: RequestError;
49
48
  }) => number | false;
@@ -60,9 +60,6 @@ export const makePhone = (phone) => {
60
60
  }
61
61
  return p;
62
62
  };
63
- export const isPhone = (value) => {
64
- return /^\d+$/.test(value.replace('-', ''));
65
- };
66
63
  export const validatePhone = (phone) => {
67
64
  var _a;
68
65
  if (!phone)
@@ -166,6 +163,8 @@ export const hasEntities = (reducer) => {
166
163
  if (!reducer)
167
164
  return false;
168
165
  const { entities, loading, error } = reducer;
166
+ if (!entities)
167
+ return false;
169
168
  if (loading === 'pending' && !entities.length)
170
169
  return false;
171
170
  return !error && entities.length;
@@ -1,4 +1,4 @@
1
- import { MenuCategories, MenuDisplayedSections } from '@open-tender/types';
1
+ import { MenuCategories, MenuDisplayedSections, ThemeImagePosition } from '@open-tender/types';
2
2
  export declare const getBinaryArr: <T>(arr: T[]) => T[][];
3
3
  export declare const makeItemChunks: <T extends {
4
4
  id: number;
@@ -104,3 +104,8 @@ export declare const makeFlatCategories: (categories: MenuCategories) => {
104
104
  slug: string;
105
105
  small_image_url: string | null;
106
106
  }[];
107
+ export declare const makeMenuItemLayout: (position: ThemeImagePosition) => {
108
+ hideImage: boolean;
109
+ flexDirection: string;
110
+ alignItems: string;
111
+ };
@@ -38,3 +38,37 @@ export const makeFlatCategories = (categories) => {
38
38
  .filter(c => c.items.length)
39
39
  .map(c => (Object.assign(Object.assign({}, c), { key: slugify(c.name), data: c.items.map((i, idx) => (Object.assign(Object.assign({}, i), { key: `${slugify(c.name)}-${i.id}-${idx}` }))) })));
40
40
  };
41
+ export const makeMenuItemLayout = (position) => {
42
+ switch (position) {
43
+ case 'HIDDEN':
44
+ return {
45
+ hideImage: true,
46
+ flexDirection: 'column',
47
+ alignItems: 'stretch'
48
+ };
49
+ case 'LEFT':
50
+ return {
51
+ hideImage: false,
52
+ flexDirection: 'row',
53
+ alignItems: 'flex-start'
54
+ };
55
+ case 'RIGHT':
56
+ return {
57
+ hideImage: false,
58
+ flexDirection: 'row-reverse',
59
+ alignItems: 'flex-start'
60
+ };
61
+ case 'BOTTOM':
62
+ return {
63
+ hideImage: false,
64
+ flexDirection: 'column-reverse',
65
+ alignItems: 'stretch'
66
+ };
67
+ default:
68
+ return {
69
+ hideImage: false,
70
+ flexDirection: 'column',
71
+ alignItems: 'stretch'
72
+ };
73
+ }
74
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.1.149",
3
+ "version": "0.1.151",
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",