@open-tender/utils 0.4.35 → 0.4.37
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/LICENSE.md +21 -21
- package/README.md +2 -2
- package/dist/cjs/__tests__/utils/helpers.test.d.ts +1 -1
- package/dist/cjs/__tests__/utils/helpers.test.js +96 -96
- package/dist/cjs/__tests__/utils/theme.test.d.ts +1 -1
- package/dist/cjs/__tests__/utils/theme.test.js +37 -37
- package/dist/cjs/hooks/index.d.ts +35 -35
- package/dist/cjs/hooks/index.js +38 -38
- package/dist/cjs/hooks/types.d.ts +4 -4
- package/dist/cjs/hooks/types.js +2 -2
- package/dist/cjs/hooks/useAccordion.d.ts +22 -22
- package/dist/cjs/hooks/useAccordion.js +56 -56
- package/dist/cjs/hooks/useAddressForm.d.ts +12 -12
- package/dist/cjs/hooks/useAddressForm.js +83 -83
- package/dist/cjs/hooks/useAllergenForm.d.ts +10 -10
- package/dist/cjs/hooks/useAllergenForm.js +58 -58
- package/dist/cjs/hooks/useBuilder.d.ts +14 -14
- package/dist/cjs/hooks/useBuilder.js +144 -144
- package/dist/cjs/hooks/useCartGuestForm.d.ts +12 -12
- package/dist/cjs/hooks/useCartGuestForm.js +58 -58
- package/dist/cjs/hooks/useCartPoints.d.ts +13 -13
- package/dist/cjs/hooks/useCartPoints.js +74 -74
- package/dist/cjs/hooks/useCommunicationPreferences.js +1 -1
- package/dist/cjs/hooks/useCreditCard.d.ts +13 -13
- package/dist/cjs/hooks/useCreditCard.js +63 -63
- package/dist/cjs/hooks/useCreditCardForm.d.ts +10 -10
- package/dist/cjs/hooks/useCreditCardForm.js +71 -71
- package/dist/cjs/hooks/useCurbside.d.ts +9 -9
- package/dist/cjs/hooks/useCurbside.js +39 -39
- package/dist/cjs/hooks/useDineInForm.d.ts +11 -11
- package/dist/cjs/hooks/useDineInForm.js +56 -56
- package/dist/cjs/hooks/useDonationForm.d.ts +28 -28
- package/dist/cjs/hooks/useDonationForm.js +172 -172
- package/dist/cjs/hooks/useFirstTimes.d.ts +18 -18
- package/dist/cjs/hooks/useFirstTimes.js +81 -81
- package/dist/cjs/hooks/useGiftCardAssignForm.d.ts +14 -14
- package/dist/cjs/hooks/useGiftCardAssignForm.js +57 -57
- package/dist/cjs/hooks/useGiftCardAssignOtherForm.d.ts +14 -14
- package/dist/cjs/hooks/useGiftCardAssignOtherForm.js +50 -50
- package/dist/cjs/hooks/useGiftCardForm.d.ts +12 -12
- package/dist/cjs/hooks/useGiftCardForm.js +74 -74
- package/dist/cjs/hooks/useGiftCardsForm.d.ts +31 -31
- package/dist/cjs/hooks/useGiftCardsForm.js +195 -195
- package/dist/cjs/hooks/useGuestCheckoutForm.d.ts +21 -21
- package/dist/cjs/hooks/useGuestCheckoutForm.js +89 -89
- package/dist/cjs/hooks/useGuestForm.d.ts +12 -12
- package/dist/cjs/hooks/useGuestForm.js +60 -60
- package/dist/cjs/hooks/useImage.d.ts +5 -5
- package/dist/cjs/hooks/useImage.js +33 -33
- package/dist/cjs/hooks/useLoginForm.d.ts +12 -12
- package/dist/cjs/hooks/useLoginForm.js +67 -67
- package/dist/cjs/hooks/useMenuItem.d.ts +57 -57
- package/dist/cjs/hooks/useMenuItem.js +67 -67
- package/dist/cjs/hooks/useModifier.d.ts +53 -53
- package/dist/cjs/hooks/useModifier.js +72 -72
- package/dist/cjs/hooks/useModifierGroup.d.ts +15 -15
- package/dist/cjs/hooks/useModifierGroup.js +17 -17
- package/dist/cjs/hooks/useOneTimePasscodeForm.d.ts +16 -16
- package/dist/cjs/hooks/useOneTimePasscodeForm.js +87 -87
- package/dist/cjs/hooks/useOrderFulfillmentForm.d.ts +11 -11
- package/dist/cjs/hooks/useOrderFulfillmentForm.js +65 -65
- package/dist/cjs/hooks/useOrderItem.d.ts +48 -48
- package/dist/cjs/hooks/useOrderItem.js +54 -54
- package/dist/cjs/hooks/useOrderRating.d.ts +10 -10
- package/dist/cjs/hooks/useOrderRating.js +34 -34
- package/dist/cjs/hooks/useOrderRatingForm.d.ts +11 -11
- package/dist/cjs/hooks/useOrderRatingForm.js +35 -35
- package/dist/cjs/hooks/useProfileForm.d.ts +15 -15
- package/dist/cjs/hooks/useProfileForm.js +116 -116
- package/dist/cjs/hooks/useResetPasswordForm.d.ts +12 -12
- package/dist/cjs/hooks/useResetPasswordForm.js +77 -77
- package/dist/cjs/hooks/useSendResetForm.d.ts +14 -14
- package/dist/cjs/hooks/useSendResetForm.js +57 -57
- package/dist/cjs/hooks/useSignUpForm.d.ts +20 -20
- package/dist/cjs/hooks/useSignUpForm.js +157 -157
- package/dist/cjs/hooks/useSignUpGuestForm.d.ts +23 -23
- package/dist/cjs/hooks/useSignUpGuestForm.js +124 -124
- package/dist/cjs/hooks/useSigninForm.d.ts +12 -12
- package/dist/cjs/hooks/useSigninForm.js +66 -66
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +5 -5
- package/dist/cjs/utils/cards.d.ts +20 -20
- package/dist/cjs/utils/cards.js +155 -155
- package/dist/cjs/utils/cart.d.ts +202 -202
- package/dist/cjs/utils/cart.js +909 -909
- package/dist/cjs/utils/checkout.d.ts +55 -55
- package/dist/cjs/utils/checkout.js +125 -125
- package/dist/cjs/utils/constants.d.ts +43 -43
- package/dist/cjs/utils/constants.js +58 -58
- package/dist/cjs/utils/customer.d.ts +4 -4
- package/dist/cjs/utils/customer.js +34 -34
- package/dist/cjs/utils/datetimes.d.ts +99 -99
- package/dist/cjs/utils/datetimes.js +601 -601
- package/dist/cjs/utils/errors.d.ts +51 -51
- package/dist/cjs/utils/errors.js +191 -191
- package/dist/cjs/utils/favorites.d.ts +10 -10
- package/dist/cjs/utils/favorites.js +119 -119
- package/dist/cjs/utils/googleMaps.d.ts +14 -14
- package/dist/cjs/utils/googleMaps.js +30 -30
- package/dist/cjs/utils/helpers.d.ts +63 -63
- package/dist/cjs/utils/helpers.js +244 -244
- package/dist/cjs/utils/index.d.ts +19 -19
- package/dist/cjs/utils/index.js +23 -23
- package/dist/cjs/utils/keypad.d.ts +9 -9
- package/dist/cjs/utils/keypad.js +105 -105
- package/dist/cjs/utils/maps.d.ts +226 -226
- package/dist/cjs/utils/maps.js +334 -334
- package/dist/cjs/utils/menu.d.ts +117 -117
- package/dist/cjs/utils/menu.js +82 -82
- package/dist/cjs/utils/orders.d.ts +21 -21
- package/dist/cjs/utils/orders.js +202 -202
- package/dist/cjs/utils/pizzaBuilder.d.ts +10 -10
- package/dist/cjs/utils/pizzaBuilder.js +43 -43
- package/dist/cjs/utils/refunds.d.ts +35 -35
- package/dist/cjs/utils/refunds.js +98 -98
- package/dist/cjs/utils/revenueCenters.d.ts +11 -11
- package/dist/cjs/utils/revenueCenters.js +125 -125
- package/dist/cjs/utils/rewards.d.ts +4 -4
- package/dist/cjs/utils/rewards.js +100 -100
- package/dist/cjs/utils/theme.d.ts +27 -27
- package/dist/cjs/utils/theme.js +266 -266
- package/dist/cjs/utils/version.d.ts +4 -4
- package/dist/cjs/utils/version.js +38 -38
- package/dist/esm/__tests__/utils/helpers.test.d.ts +1 -1
- package/dist/esm/__tests__/utils/helpers.test.js +94 -94
- package/dist/esm/__tests__/utils/theme.test.d.ts +1 -1
- package/dist/esm/__tests__/utils/theme.test.js +35 -35
- package/dist/esm/hooks/index.d.ts +35 -35
- package/dist/esm/hooks/index.js +35 -35
- package/dist/esm/hooks/types.d.ts +4 -4
- package/dist/esm/hooks/types.js +1 -1
- package/dist/esm/hooks/useAccordion.d.ts +22 -22
- package/dist/esm/hooks/useAccordion.js +52 -52
- package/dist/esm/hooks/useAddressForm.d.ts +12 -12
- package/dist/esm/hooks/useAddressForm.js +79 -79
- package/dist/esm/hooks/useAllergenForm.d.ts +10 -10
- package/dist/esm/hooks/useAllergenForm.js +54 -54
- package/dist/esm/hooks/useBuilder.d.ts +14 -14
- package/dist/esm/hooks/useBuilder.js +140 -140
- package/dist/esm/hooks/useCartGuestForm.d.ts +12 -12
- package/dist/esm/hooks/useCartGuestForm.js +54 -54
- package/dist/esm/hooks/useCartPoints.d.ts +13 -13
- package/dist/esm/hooks/useCartPoints.js +70 -70
- package/dist/esm/hooks/useCommunicationPreferences.js +1 -1
- package/dist/esm/hooks/useCreditCard.d.ts +13 -13
- package/dist/esm/hooks/useCreditCard.js +59 -59
- package/dist/esm/hooks/useCreditCardForm.d.ts +10 -10
- package/dist/esm/hooks/useCreditCardForm.js +67 -67
- package/dist/esm/hooks/useCurbside.d.ts +9 -9
- package/dist/esm/hooks/useCurbside.js +35 -35
- package/dist/esm/hooks/useDineInForm.d.ts +11 -11
- package/dist/esm/hooks/useDineInForm.js +52 -52
- package/dist/esm/hooks/useDonationForm.d.ts +28 -28
- package/dist/esm/hooks/useDonationForm.js +168 -168
- package/dist/esm/hooks/useFirstTimes.d.ts +18 -18
- package/dist/esm/hooks/useFirstTimes.js +77 -77
- package/dist/esm/hooks/useGiftCardAssignForm.d.ts +14 -14
- package/dist/esm/hooks/useGiftCardAssignForm.js +53 -53
- package/dist/esm/hooks/useGiftCardAssignOtherForm.d.ts +14 -14
- package/dist/esm/hooks/useGiftCardAssignOtherForm.js +46 -46
- package/dist/esm/hooks/useGiftCardForm.d.ts +12 -12
- package/dist/esm/hooks/useGiftCardForm.js +70 -70
- package/dist/esm/hooks/useGiftCardsForm.d.ts +31 -31
- package/dist/esm/hooks/useGiftCardsForm.js +191 -191
- package/dist/esm/hooks/useGuestCheckoutForm.d.ts +21 -21
- package/dist/esm/hooks/useGuestCheckoutForm.js +85 -85
- package/dist/esm/hooks/useGuestForm.d.ts +12 -12
- package/dist/esm/hooks/useGuestForm.js +56 -56
- package/dist/esm/hooks/useImage.d.ts +5 -5
- package/dist/esm/hooks/useImage.js +29 -29
- package/dist/esm/hooks/useLoginForm.d.ts +12 -12
- package/dist/esm/hooks/useLoginForm.js +63 -63
- package/dist/esm/hooks/useMenuItem.d.ts +57 -57
- package/dist/esm/hooks/useMenuItem.js +63 -63
- package/dist/esm/hooks/useModifier.d.ts +53 -53
- package/dist/esm/hooks/useModifier.js +68 -68
- package/dist/esm/hooks/useModifierGroup.d.ts +15 -15
- package/dist/esm/hooks/useModifierGroup.js +13 -13
- package/dist/esm/hooks/useOneTimePasscodeForm.d.ts +16 -16
- package/dist/esm/hooks/useOneTimePasscodeForm.js +83 -83
- package/dist/esm/hooks/useOrderFulfillmentForm.d.ts +11 -11
- package/dist/esm/hooks/useOrderFulfillmentForm.js +61 -61
- package/dist/esm/hooks/useOrderItem.d.ts +48 -48
- package/dist/esm/hooks/useOrderItem.js +50 -50
- package/dist/esm/hooks/useOrderRating.d.ts +10 -10
- package/dist/esm/hooks/useOrderRating.js +30 -30
- package/dist/esm/hooks/useOrderRatingForm.d.ts +11 -11
- package/dist/esm/hooks/useOrderRatingForm.js +31 -31
- package/dist/esm/hooks/useProfileForm.d.ts +15 -15
- package/dist/esm/hooks/useProfileForm.js +112 -112
- package/dist/esm/hooks/useResetPasswordForm.d.ts +12 -12
- package/dist/esm/hooks/useResetPasswordForm.js +73 -73
- package/dist/esm/hooks/useSendResetForm.d.ts +14 -14
- package/dist/esm/hooks/useSendResetForm.js +53 -53
- package/dist/esm/hooks/useSignUpForm.d.ts +20 -20
- package/dist/esm/hooks/useSignUpForm.js +153 -153
- package/dist/esm/hooks/useSignUpGuestForm.d.ts +23 -23
- package/dist/esm/hooks/useSignUpGuestForm.js +120 -120
- package/dist/esm/hooks/useSigninForm.d.ts +12 -12
- package/dist/esm/hooks/useSigninForm.js +62 -62
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/utils/cards.d.ts +20 -20
- package/dist/esm/utils/cards.js +146 -146
- package/dist/esm/utils/cart.d.ts +202 -202
- package/dist/esm/utils/cart.js +868 -868
- package/dist/esm/utils/checkout.d.ts +55 -55
- package/dist/esm/utils/checkout.js +117 -117
- package/dist/esm/utils/constants.d.ts +43 -43
- package/dist/esm/utils/constants.js +55 -55
- package/dist/esm/utils/customer.d.ts +4 -4
- package/dist/esm/utils/customer.js +29 -29
- package/dist/esm/utils/datetimes.d.ts +99 -99
- package/dist/esm/utils/datetimes.js +531 -531
- package/dist/esm/utils/errors.d.ts +51 -51
- package/dist/esm/utils/errors.js +180 -180
- package/dist/esm/utils/favorites.d.ts +10 -10
- package/dist/esm/utils/favorites.js +109 -109
- package/dist/esm/utils/googleMaps.d.ts +14 -14
- package/dist/esm/utils/googleMaps.js +26 -26
- package/dist/esm/utils/helpers.d.ts +63 -63
- package/dist/esm/utils/helpers.js +205 -205
- package/dist/esm/utils/index.d.ts +19 -19
- package/dist/esm/utils/index.js +20 -20
- package/dist/esm/utils/keypad.d.ts +9 -9
- package/dist/esm/utils/keypad.js +97 -97
- package/dist/esm/utils/maps.d.ts +226 -226
- package/dist/esm/utils/maps.js +316 -316
- package/dist/esm/utils/menu.d.ts +117 -117
- package/dist/esm/utils/menu.js +74 -74
- package/dist/esm/utils/orders.d.ts +21 -21
- package/dist/esm/utils/orders.js +185 -185
- package/dist/esm/utils/pizzaBuilder.d.ts +10 -10
- package/dist/esm/utils/pizzaBuilder.js +38 -38
- package/dist/esm/utils/refunds.d.ts +35 -35
- package/dist/esm/utils/refunds.js +90 -90
- package/dist/esm/utils/revenueCenters.d.ts +11 -11
- package/dist/esm/utils/revenueCenters.js +115 -115
- package/dist/esm/utils/rewards.d.ts +4 -4
- package/dist/esm/utils/rewards.js +94 -94
- package/dist/esm/utils/theme.d.ts +27 -27
- package/dist/esm/utils/theme.js +254 -254
- package/dist/esm/utils/version.d.ts +4 -4
- package/dist/esm/utils/version.js +34 -34
- package/package.json +69 -69
|
@@ -1,205 +1,205 @@
|
|
|
1
|
-
export const isString = (str) => {
|
|
2
|
-
return typeof str === 'string';
|
|
3
|
-
};
|
|
4
|
-
export const isObject = (obj) => {
|
|
5
|
-
return typeof obj === 'object' && obj !== null;
|
|
6
|
-
};
|
|
7
|
-
export const isEmpty = (obj) => {
|
|
8
|
-
return (!obj || (obj.constructor === Object && Object.entries(obj).length === 0));
|
|
9
|
-
};
|
|
10
|
-
export const isNum = (s) => /^\d+$/.test(s);
|
|
11
|
-
/**
|
|
12
|
-
* @deprecated please use `containsAll` or `containsAny` instead
|
|
13
|
-
* @returns true if first argument contains any of the values in the second argument
|
|
14
|
-
*/
|
|
15
|
-
export const contains = (arr, values) => {
|
|
16
|
-
return values.filter(i => arr.includes(i)).length > 0;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* @returns true if first argument contains any of the values in the second argument
|
|
20
|
-
*/
|
|
21
|
-
export const containsAny = (arr, values) => {
|
|
22
|
-
return values.length === 0 || values.filter(i => arr.includes(i)).length > 0;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* @returns true if first argument contains all of the values of the second argument
|
|
26
|
-
*/
|
|
27
|
-
export const containsAll = (arr, values) => {
|
|
28
|
-
return values.filter(i => arr.includes(i)).length === values.length;
|
|
29
|
-
};
|
|
30
|
-
// https://gist.github.com/mathewbyrne/1280286
|
|
31
|
-
export const slugify = (text) => {
|
|
32
|
-
return text
|
|
33
|
-
.toString()
|
|
34
|
-
.toLowerCase()
|
|
35
|
-
.replace('_', '-') // replace _ with -
|
|
36
|
-
.replace(/\s+/g, '-') // Replace spaces with -
|
|
37
|
-
.replace(/[^\w-]+/g, '') // Remove all non-word chars
|
|
38
|
-
.replace(/--+/g, '-') // Replace multiple - with single -
|
|
39
|
-
.replace(/^-+/, '') // Trim - from start of text
|
|
40
|
-
.replace(/-+$/, ''); // Trim - from end of text
|
|
41
|
-
};
|
|
42
|
-
export const stripTags = (s) => s.replace(/(<([^>]+)>)/gi, '').replace('&', '&');
|
|
43
|
-
export const serialize = (obj) => {
|
|
44
|
-
const str = [];
|
|
45
|
-
for (const p in obj)
|
|
46
|
-
if (Object.prototype.hasOwnProperty.call(obj, p)) {
|
|
47
|
-
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]));
|
|
48
|
-
}
|
|
49
|
-
return str.join('&');
|
|
50
|
-
};
|
|
51
|
-
export const capitalize = (s) => {
|
|
52
|
-
if (!s || !s.length)
|
|
53
|
-
return '';
|
|
54
|
-
return s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
|
|
55
|
-
};
|
|
56
|
-
export const cleanPhone = (phone) => {
|
|
57
|
-
if (!phone)
|
|
58
|
-
return '';
|
|
59
|
-
let p = phone.replace(/\D/g, '');
|
|
60
|
-
if (p.length > 11)
|
|
61
|
-
return phone;
|
|
62
|
-
p = p.length === 11 && p[0] === '1' ? p.slice(1, 11) : p;
|
|
63
|
-
p =
|
|
64
|
-
p.length === 10 ? `${p.slice(0, 3)}-${p.slice(3, 6)}-${p.slice(6, 10)}` : p;
|
|
65
|
-
return p;
|
|
66
|
-
};
|
|
67
|
-
export const makePhone = (phone) => {
|
|
68
|
-
if (!phone)
|
|
69
|
-
return '';
|
|
70
|
-
const p = phone.replace(/\D/g, '');
|
|
71
|
-
if (p.length > 6) {
|
|
72
|
-
return `${p.slice(0, 3)}-${p.slice(3, 6)}-${p.slice(6, 10)}`;
|
|
73
|
-
}
|
|
74
|
-
else if (p.length > 3) {
|
|
75
|
-
return `${p.slice(0, 3)}-${p.slice(3, 6)}`;
|
|
76
|
-
}
|
|
77
|
-
return p;
|
|
78
|
-
};
|
|
79
|
-
export const validatePhone = (phone) => {
|
|
80
|
-
var _a;
|
|
81
|
-
if (!phone)
|
|
82
|
-
return false;
|
|
83
|
-
return ((_a = phone.match(/\d/g)) === null || _a === void 0 ? void 0 : _a.length) === 10;
|
|
84
|
-
};
|
|
85
|
-
export const makeBirthDate = (birthDate) => {
|
|
86
|
-
if (!birthDate)
|
|
87
|
-
return null;
|
|
88
|
-
const b = birthDate.replace(/\D/g, '');
|
|
89
|
-
if (b.length > 4) {
|
|
90
|
-
return `${b.slice(0, 2)}/${b.slice(2, 4)}/${b.slice(4, 8)}`;
|
|
91
|
-
}
|
|
92
|
-
else if (b.length > 2) {
|
|
93
|
-
return `${b.slice(0, 2)}/${b.slice(2, 4)}`;
|
|
94
|
-
}
|
|
95
|
-
return b;
|
|
96
|
-
};
|
|
97
|
-
export const slashesToDashes = (birthDate) => {
|
|
98
|
-
if (!birthDate)
|
|
99
|
-
return null;
|
|
100
|
-
const parts = birthDate.split('/');
|
|
101
|
-
return `${parts[2] || ''}-${parts[0] || ''}-${parts[1] || ''}`;
|
|
102
|
-
};
|
|
103
|
-
export const dashesToSlashes = (birthDate) => {
|
|
104
|
-
if (!birthDate)
|
|
105
|
-
return null;
|
|
106
|
-
const parts = birthDate.split('-');
|
|
107
|
-
return `${parts[1] || ''}/${parts[2] || ''}/${parts[0] || ''}`;
|
|
108
|
-
};
|
|
109
|
-
export const validateEmail = (email) => {
|
|
110
|
-
const re =
|
|
111
|
-
// eslint-disable-next-line no-useless-escape
|
|
112
|
-
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
113
|
-
return re.test(email);
|
|
114
|
-
};
|
|
115
|
-
export const checkEmpty = (data) => {
|
|
116
|
-
if (isEmpty(data))
|
|
117
|
-
return true;
|
|
118
|
-
return Object.values(data).filter(i => !i).length > 0;
|
|
119
|
-
};
|
|
120
|
-
export const checkGuestData = (data, email) => {
|
|
121
|
-
const { first_name, last_name, phone } = data;
|
|
122
|
-
const guestData = { first_name, last_name, phone, email };
|
|
123
|
-
const validPhone = phone ? validatePhone(phone) || null : null;
|
|
124
|
-
const guestIncomplete = checkEmpty(Object.assign(Object.assign({}, guestData), { phone: validPhone }));
|
|
125
|
-
return { guestData, guestIncomplete };
|
|
126
|
-
};
|
|
127
|
-
export const checkNotFound = (errors) => {
|
|
128
|
-
const errMsg = errors ? errors.email || errors.form : null;
|
|
129
|
-
if (!errMsg)
|
|
130
|
-
return null;
|
|
131
|
-
return (errMsg.includes('not associated') || errMsg.includes('Account not found'));
|
|
132
|
-
};
|
|
133
|
-
export const makeRandomNumberString = () => Math.floor(Math.random() * 1000000000).toString();
|
|
134
|
-
export const getWidth = () => {
|
|
135
|
-
return Math.max(document.body.scrollWidth, document.documentElement.scrollWidth, document.body.offsetWidth, document.documentElement.offsetWidth, document.documentElement.clientWidth);
|
|
136
|
-
};
|
|
137
|
-
export const getHeight = () => {
|
|
138
|
-
return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.documentElement.clientHeight);
|
|
139
|
-
};
|
|
140
|
-
export const makeImageMap = (images) => {
|
|
141
|
-
const imagesMap = images
|
|
142
|
-
.filter(i => i.url)
|
|
143
|
-
.reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i.type]: i.url })), {});
|
|
144
|
-
return imagesMap;
|
|
145
|
-
};
|
|
146
|
-
export const makeImageUrl = (images, isMobile) => {
|
|
147
|
-
var _a;
|
|
148
|
-
return (_a = images.find(i => i.type === (isMobile ? 'SECONDARY_IMAGE' : 'FEATURED_IMAGE'))) === null || _a === void 0 ? void 0 : _a.url;
|
|
149
|
-
};
|
|
150
|
-
export const makeSlides = (items, isMobile) => {
|
|
151
|
-
if (!items || !items.length)
|
|
152
|
-
return null;
|
|
153
|
-
return items.map(i => (Object.assign(Object.assign({}, i), { imageUrl: makeImageUrl(i.images, isMobile) })));
|
|
154
|
-
};
|
|
155
|
-
export const displayPrice = (price) => {
|
|
156
|
-
return parseFloat(price).toFixed(2);
|
|
157
|
-
};
|
|
158
|
-
export const addCommas = (x, d) => {
|
|
159
|
-
const valueToReplace = d === undefined ? x.toString() : x.toFixed(d);
|
|
160
|
-
return valueToReplace.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
161
|
-
};
|
|
162
|
-
export const formatQuantity = (n) => {
|
|
163
|
-
return addCommas(parseFloat(n), 0);
|
|
164
|
-
};
|
|
165
|
-
export const formatPercentage = (n, d) => {
|
|
166
|
-
return addCommas(parseFloat(n), d);
|
|
167
|
-
};
|
|
168
|
-
export const formatDollars = (str, space = '', decimals = 2) => {
|
|
169
|
-
const floatPrice = parseFloat(str);
|
|
170
|
-
return floatPrice < 0
|
|
171
|
-
? `($${addCommas(Math.abs(floatPrice), decimals)})`
|
|
172
|
-
: `$${addCommas(floatPrice, decimals)}${space}`;
|
|
173
|
-
};
|
|
174
|
-
export const convertStringToArray = (str) => {
|
|
175
|
-
return str
|
|
176
|
-
? str
|
|
177
|
-
.split(',')
|
|
178
|
-
.map(i => i.trim())
|
|
179
|
-
.filter(i => i.length)
|
|
180
|
-
: [];
|
|
181
|
-
};
|
|
182
|
-
export const hasEntities = (reducer) => {
|
|
183
|
-
if (!reducer)
|
|
184
|
-
return false;
|
|
185
|
-
const { entities, loading, error } = reducer;
|
|
186
|
-
if (!entities)
|
|
187
|
-
return false;
|
|
188
|
-
if (loading === 'pending' && !entities.length)
|
|
189
|
-
return false;
|
|
190
|
-
return !error && entities.length;
|
|
191
|
-
};
|
|
192
|
-
export const range = (start, end, step = 1) => {
|
|
193
|
-
if (typeof end === 'undefined') {
|
|
194
|
-
end = start;
|
|
195
|
-
start = 0;
|
|
196
|
-
}
|
|
197
|
-
const length = Math.max(Math.ceil((end - start) / step), 0);
|
|
198
|
-
return Array.from({ length }, (_, index) => start + index * step);
|
|
199
|
-
};
|
|
200
|
-
export const sample = (collection) => {
|
|
201
|
-
if (collection.length === 0)
|
|
202
|
-
return undefined;
|
|
203
|
-
const randomIndex = Math.floor(Math.random() * collection.length);
|
|
204
|
-
return collection[randomIndex];
|
|
205
|
-
};
|
|
1
|
+
export const isString = (str) => {
|
|
2
|
+
return typeof str === 'string';
|
|
3
|
+
};
|
|
4
|
+
export const isObject = (obj) => {
|
|
5
|
+
return typeof obj === 'object' && obj !== null;
|
|
6
|
+
};
|
|
7
|
+
export const isEmpty = (obj) => {
|
|
8
|
+
return (!obj || (obj.constructor === Object && Object.entries(obj).length === 0));
|
|
9
|
+
};
|
|
10
|
+
export const isNum = (s) => /^\d+$/.test(s);
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated please use `containsAll` or `containsAny` instead
|
|
13
|
+
* @returns true if first argument contains any of the values in the second argument
|
|
14
|
+
*/
|
|
15
|
+
export const contains = (arr, values) => {
|
|
16
|
+
return values.filter(i => arr.includes(i)).length > 0;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* @returns true if first argument contains any of the values in the second argument
|
|
20
|
+
*/
|
|
21
|
+
export const containsAny = (arr, values) => {
|
|
22
|
+
return values.length === 0 || values.filter(i => arr.includes(i)).length > 0;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* @returns true if first argument contains all of the values of the second argument
|
|
26
|
+
*/
|
|
27
|
+
export const containsAll = (arr, values) => {
|
|
28
|
+
return values.filter(i => arr.includes(i)).length === values.length;
|
|
29
|
+
};
|
|
30
|
+
// https://gist.github.com/mathewbyrne/1280286
|
|
31
|
+
export const slugify = (text) => {
|
|
32
|
+
return text
|
|
33
|
+
.toString()
|
|
34
|
+
.toLowerCase()
|
|
35
|
+
.replace('_', '-') // replace _ with -
|
|
36
|
+
.replace(/\s+/g, '-') // Replace spaces with -
|
|
37
|
+
.replace(/[^\w-]+/g, '') // Remove all non-word chars
|
|
38
|
+
.replace(/--+/g, '-') // Replace multiple - with single -
|
|
39
|
+
.replace(/^-+/, '') // Trim - from start of text
|
|
40
|
+
.replace(/-+$/, ''); // Trim - from end of text
|
|
41
|
+
};
|
|
42
|
+
export const stripTags = (s) => s.replace(/(<([^>]+)>)/gi, '').replace('&', '&');
|
|
43
|
+
export const serialize = (obj) => {
|
|
44
|
+
const str = [];
|
|
45
|
+
for (const p in obj)
|
|
46
|
+
if (Object.prototype.hasOwnProperty.call(obj, p)) {
|
|
47
|
+
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]));
|
|
48
|
+
}
|
|
49
|
+
return str.join('&');
|
|
50
|
+
};
|
|
51
|
+
export const capitalize = (s) => {
|
|
52
|
+
if (!s || !s.length)
|
|
53
|
+
return '';
|
|
54
|
+
return s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
|
|
55
|
+
};
|
|
56
|
+
export const cleanPhone = (phone) => {
|
|
57
|
+
if (!phone)
|
|
58
|
+
return '';
|
|
59
|
+
let p = phone.replace(/\D/g, '');
|
|
60
|
+
if (p.length > 11)
|
|
61
|
+
return phone;
|
|
62
|
+
p = p.length === 11 && p[0] === '1' ? p.slice(1, 11) : p;
|
|
63
|
+
p =
|
|
64
|
+
p.length === 10 ? `${p.slice(0, 3)}-${p.slice(3, 6)}-${p.slice(6, 10)}` : p;
|
|
65
|
+
return p;
|
|
66
|
+
};
|
|
67
|
+
export const makePhone = (phone) => {
|
|
68
|
+
if (!phone)
|
|
69
|
+
return '';
|
|
70
|
+
const p = phone.replace(/\D/g, '');
|
|
71
|
+
if (p.length > 6) {
|
|
72
|
+
return `${p.slice(0, 3)}-${p.slice(3, 6)}-${p.slice(6, 10)}`;
|
|
73
|
+
}
|
|
74
|
+
else if (p.length > 3) {
|
|
75
|
+
return `${p.slice(0, 3)}-${p.slice(3, 6)}`;
|
|
76
|
+
}
|
|
77
|
+
return p;
|
|
78
|
+
};
|
|
79
|
+
export const validatePhone = (phone) => {
|
|
80
|
+
var _a;
|
|
81
|
+
if (!phone)
|
|
82
|
+
return false;
|
|
83
|
+
return ((_a = phone.match(/\d/g)) === null || _a === void 0 ? void 0 : _a.length) === 10;
|
|
84
|
+
};
|
|
85
|
+
export const makeBirthDate = (birthDate) => {
|
|
86
|
+
if (!birthDate)
|
|
87
|
+
return null;
|
|
88
|
+
const b = birthDate.replace(/\D/g, '');
|
|
89
|
+
if (b.length > 4) {
|
|
90
|
+
return `${b.slice(0, 2)}/${b.slice(2, 4)}/${b.slice(4, 8)}`;
|
|
91
|
+
}
|
|
92
|
+
else if (b.length > 2) {
|
|
93
|
+
return `${b.slice(0, 2)}/${b.slice(2, 4)}`;
|
|
94
|
+
}
|
|
95
|
+
return b;
|
|
96
|
+
};
|
|
97
|
+
export const slashesToDashes = (birthDate) => {
|
|
98
|
+
if (!birthDate)
|
|
99
|
+
return null;
|
|
100
|
+
const parts = birthDate.split('/');
|
|
101
|
+
return `${parts[2] || ''}-${parts[0] || ''}-${parts[1] || ''}`;
|
|
102
|
+
};
|
|
103
|
+
export const dashesToSlashes = (birthDate) => {
|
|
104
|
+
if (!birthDate)
|
|
105
|
+
return null;
|
|
106
|
+
const parts = birthDate.split('-');
|
|
107
|
+
return `${parts[1] || ''}/${parts[2] || ''}/${parts[0] || ''}`;
|
|
108
|
+
};
|
|
109
|
+
export const validateEmail = (email) => {
|
|
110
|
+
const re =
|
|
111
|
+
// eslint-disable-next-line no-useless-escape
|
|
112
|
+
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
113
|
+
return re.test(email);
|
|
114
|
+
};
|
|
115
|
+
export const checkEmpty = (data) => {
|
|
116
|
+
if (isEmpty(data))
|
|
117
|
+
return true;
|
|
118
|
+
return Object.values(data).filter(i => !i).length > 0;
|
|
119
|
+
};
|
|
120
|
+
export const checkGuestData = (data, email) => {
|
|
121
|
+
const { first_name, last_name, phone } = data;
|
|
122
|
+
const guestData = { first_name, last_name, phone, email };
|
|
123
|
+
const validPhone = phone ? validatePhone(phone) || null : null;
|
|
124
|
+
const guestIncomplete = checkEmpty(Object.assign(Object.assign({}, guestData), { phone: validPhone }));
|
|
125
|
+
return { guestData, guestIncomplete };
|
|
126
|
+
};
|
|
127
|
+
export const checkNotFound = (errors) => {
|
|
128
|
+
const errMsg = errors ? errors.email || errors.form : null;
|
|
129
|
+
if (!errMsg)
|
|
130
|
+
return null;
|
|
131
|
+
return (errMsg.includes('not associated') || errMsg.includes('Account not found'));
|
|
132
|
+
};
|
|
133
|
+
export const makeRandomNumberString = () => Math.floor(Math.random() * 1000000000).toString();
|
|
134
|
+
export const getWidth = () => {
|
|
135
|
+
return Math.max(document.body.scrollWidth, document.documentElement.scrollWidth, document.body.offsetWidth, document.documentElement.offsetWidth, document.documentElement.clientWidth);
|
|
136
|
+
};
|
|
137
|
+
export const getHeight = () => {
|
|
138
|
+
return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.documentElement.clientHeight);
|
|
139
|
+
};
|
|
140
|
+
export const makeImageMap = (images) => {
|
|
141
|
+
const imagesMap = images
|
|
142
|
+
.filter(i => i.url)
|
|
143
|
+
.reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i.type]: i.url })), {});
|
|
144
|
+
return imagesMap;
|
|
145
|
+
};
|
|
146
|
+
export const makeImageUrl = (images, isMobile) => {
|
|
147
|
+
var _a;
|
|
148
|
+
return (_a = images.find(i => i.type === (isMobile ? 'SECONDARY_IMAGE' : 'FEATURED_IMAGE'))) === null || _a === void 0 ? void 0 : _a.url;
|
|
149
|
+
};
|
|
150
|
+
export const makeSlides = (items, isMobile) => {
|
|
151
|
+
if (!items || !items.length)
|
|
152
|
+
return null;
|
|
153
|
+
return items.map(i => (Object.assign(Object.assign({}, i), { imageUrl: makeImageUrl(i.images, isMobile) })));
|
|
154
|
+
};
|
|
155
|
+
export const displayPrice = (price) => {
|
|
156
|
+
return parseFloat(price).toFixed(2);
|
|
157
|
+
};
|
|
158
|
+
export const addCommas = (x, d) => {
|
|
159
|
+
const valueToReplace = d === undefined ? x.toString() : x.toFixed(d);
|
|
160
|
+
return valueToReplace.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
161
|
+
};
|
|
162
|
+
export const formatQuantity = (n) => {
|
|
163
|
+
return addCommas(parseFloat(n), 0);
|
|
164
|
+
};
|
|
165
|
+
export const formatPercentage = (n, d) => {
|
|
166
|
+
return addCommas(parseFloat(n), d);
|
|
167
|
+
};
|
|
168
|
+
export const formatDollars = (str, space = '', decimals = 2) => {
|
|
169
|
+
const floatPrice = parseFloat(str);
|
|
170
|
+
return floatPrice < 0
|
|
171
|
+
? `($${addCommas(Math.abs(floatPrice), decimals)})`
|
|
172
|
+
: `$${addCommas(floatPrice, decimals)}${space}`;
|
|
173
|
+
};
|
|
174
|
+
export const convertStringToArray = (str) => {
|
|
175
|
+
return str
|
|
176
|
+
? str
|
|
177
|
+
.split(',')
|
|
178
|
+
.map(i => i.trim())
|
|
179
|
+
.filter(i => i.length)
|
|
180
|
+
: [];
|
|
181
|
+
};
|
|
182
|
+
export const hasEntities = (reducer) => {
|
|
183
|
+
if (!reducer)
|
|
184
|
+
return false;
|
|
185
|
+
const { entities, loading, error } = reducer;
|
|
186
|
+
if (!entities)
|
|
187
|
+
return false;
|
|
188
|
+
if (loading === 'pending' && !entities.length)
|
|
189
|
+
return false;
|
|
190
|
+
return !error && entities.length;
|
|
191
|
+
};
|
|
192
|
+
export const range = (start, end, step = 1) => {
|
|
193
|
+
if (typeof end === 'undefined') {
|
|
194
|
+
end = start;
|
|
195
|
+
start = 0;
|
|
196
|
+
}
|
|
197
|
+
const length = Math.max(Math.ceil((end - start) / step), 0);
|
|
198
|
+
return Array.from({ length }, (_, index) => start + index * step);
|
|
199
|
+
};
|
|
200
|
+
export const sample = (collection) => {
|
|
201
|
+
if (collection.length === 0)
|
|
202
|
+
return undefined;
|
|
203
|
+
const randomIndex = Math.floor(Math.random() * collection.length);
|
|
204
|
+
return collection[randomIndex];
|
|
205
|
+
};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export * from './cards';
|
|
2
|
-
export * from './cart';
|
|
3
|
-
export * from './checkout';
|
|
4
|
-
export * from './constants';
|
|
5
|
-
export * from './customer';
|
|
6
|
-
export * from './datetimes';
|
|
7
|
-
export * from './errors';
|
|
8
|
-
export * from './googleMaps';
|
|
9
|
-
export * from './helpers';
|
|
10
|
-
export * from './keypad';
|
|
11
|
-
export * from './maps';
|
|
12
|
-
export * from './menu';
|
|
13
|
-
export * from './revenueCenters';
|
|
14
|
-
export * from './refunds';
|
|
15
|
-
export * from './rewards';
|
|
16
|
-
export * from './version';
|
|
17
|
-
export * from './theme';
|
|
18
|
-
export * from './favorites';
|
|
19
|
-
export * from './pizzaBuilder';
|
|
1
|
+
export * from './cards';
|
|
2
|
+
export * from './cart';
|
|
3
|
+
export * from './checkout';
|
|
4
|
+
export * from './constants';
|
|
5
|
+
export * from './customer';
|
|
6
|
+
export * from './datetimes';
|
|
7
|
+
export * from './errors';
|
|
8
|
+
export * from './googleMaps';
|
|
9
|
+
export * from './helpers';
|
|
10
|
+
export * from './keypad';
|
|
11
|
+
export * from './maps';
|
|
12
|
+
export * from './menu';
|
|
13
|
+
export * from './revenueCenters';
|
|
14
|
+
export * from './refunds';
|
|
15
|
+
export * from './rewards';
|
|
16
|
+
export * from './version';
|
|
17
|
+
export * from './theme';
|
|
18
|
+
export * from './favorites';
|
|
19
|
+
export * from './pizzaBuilder';
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
export * from './cards';
|
|
2
|
-
export * from './cart';
|
|
3
|
-
export * from './checkout';
|
|
4
|
-
export * from './constants';
|
|
5
|
-
export * from './customer';
|
|
6
|
-
export * from './datetimes';
|
|
7
|
-
export * from './errors';
|
|
8
|
-
export * from './googleMaps';
|
|
9
|
-
export * from './helpers';
|
|
10
|
-
export * from './keypad';
|
|
11
|
-
export * from './maps';
|
|
12
|
-
export * from './menu';
|
|
13
|
-
export * from './revenueCenters';
|
|
14
|
-
export * from './refunds';
|
|
15
|
-
export * from './rewards';
|
|
16
|
-
export * from './version';
|
|
17
|
-
// export * from './orders'
|
|
18
|
-
export * from './theme';
|
|
19
|
-
export * from './favorites';
|
|
20
|
-
export * from './pizzaBuilder';
|
|
1
|
+
export * from './cards';
|
|
2
|
+
export * from './cart';
|
|
3
|
+
export * from './checkout';
|
|
4
|
+
export * from './constants';
|
|
5
|
+
export * from './customer';
|
|
6
|
+
export * from './datetimes';
|
|
7
|
+
export * from './errors';
|
|
8
|
+
export * from './googleMaps';
|
|
9
|
+
export * from './helpers';
|
|
10
|
+
export * from './keypad';
|
|
11
|
+
export * from './maps';
|
|
12
|
+
export * from './menu';
|
|
13
|
+
export * from './revenueCenters';
|
|
14
|
+
export * from './refunds';
|
|
15
|
+
export * from './rewards';
|
|
16
|
+
export * from './version';
|
|
17
|
+
// export * from './orders'
|
|
18
|
+
export * from './theme';
|
|
19
|
+
export * from './favorites';
|
|
20
|
+
export * from './pizzaBuilder';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export declare const centsToDollars: (cents: number) => string;
|
|
2
|
-
export declare const buttonsKeypad: string[][];
|
|
3
|
-
export declare const buttonsNumpad: string[][];
|
|
4
|
-
export declare const buttonsDollars: string[][];
|
|
5
|
-
export declare const buttonsCheckout: string[][];
|
|
6
|
-
export declare const reduceKeypad: (value: string, key: string) => string;
|
|
7
|
-
export declare const reduceNumpad: (value: string, key: string, clear: boolean) => string;
|
|
8
|
-
export declare const reduceDollars: (value: string, key: string, clear: boolean) => string;
|
|
9
|
-
export declare const reduceCheckout: (value: string, key: string, clear: boolean) => string;
|
|
1
|
+
export declare const centsToDollars: (cents: number) => string;
|
|
2
|
+
export declare const buttonsKeypad: string[][];
|
|
3
|
+
export declare const buttonsNumpad: string[][];
|
|
4
|
+
export declare const buttonsDollars: string[][];
|
|
5
|
+
export declare const buttonsCheckout: string[][];
|
|
6
|
+
export declare const reduceKeypad: (value: string, key: string) => string;
|
|
7
|
+
export declare const reduceNumpad: (value: string, key: string, clear: boolean) => string;
|
|
8
|
+
export declare const reduceDollars: (value: string, key: string, clear: boolean) => string;
|
|
9
|
+
export declare const reduceCheckout: (value: string, key: string, clear: boolean) => string;
|