@open-tender/utils 0.3.7 → 0.3.10
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/.DS_Store +0 -0
- package/dist/cjs/__tests__/utils/helpers.test.js +37 -0
- package/dist/cjs/hooks/useFirstTimes.d.ts +1 -1
- package/dist/cjs/hooks/useFirstTimes.js +2 -2
- package/dist/cjs/utils/cart.js +5 -1
- package/dist/cjs/utils/helpers.d.ts +12 -0
- package/dist/cjs/utils/helpers.js +19 -1
- package/dist/cjs/utils/rewards.d.ts +3 -1
- package/dist/esm/__tests__/utils/helpers.test.js +38 -1
- package/dist/esm/hooks/useFirstTimes.d.ts +1 -1
- package/dist/esm/hooks/useFirstTimes.js +2 -2
- package/dist/esm/utils/cart.js +5 -1
- package/dist/esm/utils/helpers.d.ts +12 -0
- package/dist/esm/utils/helpers.js +16 -0
- package/dist/esm/utils/rewards.d.ts +3 -1
- package/package.json +1 -1
package/dist/.DS_Store
ADDED
|
Binary file
|
|
@@ -33,3 +33,40 @@ describe('formatQuantity', () => {
|
|
|
33
33
|
expect((0, utils_1.formatQuantity)('1.55')).toBe('2');
|
|
34
34
|
});
|
|
35
35
|
});
|
|
36
|
+
describe('containsAny', () => {
|
|
37
|
+
it('returns true when array contains any of the items', () => {
|
|
38
|
+
expect((0, utils_1.containsAny)(['a', 'b', 'c'], ['a', 'd'])).toBe(true);
|
|
39
|
+
expect((0, utils_1.containsAny)(['a', 'b', 'c'], ['d', 'e', 'f'])).toBe(false);
|
|
40
|
+
expect((0, utils_1.containsAny)(['a', 'b', 'c'], ['a', 'b', 'c'])).toBe(true);
|
|
41
|
+
expect((0, utils_1.containsAny)(['a', 'b', 'c'], ['a', 'b', 'c', 'd'])).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
it('returns false when array does not contain any of the items', () => {
|
|
44
|
+
expect((0, utils_1.containsAny)(['a', 'b', 'c'], ['d', 'e'])).toBe(false);
|
|
45
|
+
expect((0, utils_1.containsAny)(['a', 'b', 'c'], ['d', 'e', 'f'])).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
it('returns false when array is empty', () => {
|
|
48
|
+
expect((0, utils_1.containsAny)([], ['a', 'b', 'c'])).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
it('returns true when items is empty', () => {
|
|
51
|
+
expect((0, utils_1.containsAny)(['a', 'b', 'c'], [])).toBe(true);
|
|
52
|
+
expect((0, utils_1.containsAny)([], [])).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
describe('containsAll', () => {
|
|
56
|
+
it('returns true when array contains all of the items', () => {
|
|
57
|
+
expect((0, utils_1.containsAll)(['a', 'b', 'c'], ['a', 'b'])).toBe(true);
|
|
58
|
+
expect((0, utils_1.containsAll)(['a', 'b', 'c'], ['a', 'b', 'c'])).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
it('returns false when array does not contain all of the items', () => {
|
|
61
|
+
expect((0, utils_1.containsAll)(['a', 'b', 'c'], ['a', 'e'])).toBe(false);
|
|
62
|
+
expect((0, utils_1.containsAll)(['a', 'b', 'c'], ['d', 'e', 'f'])).toBe(false);
|
|
63
|
+
expect((0, utils_1.containsAll)(['a', 'b', 'c'], ['a', 'b', 'c', 'd'])).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
it('returns false when array is empty', () => {
|
|
66
|
+
expect((0, utils_1.containsAll)([], ['a', 'b', 'c'])).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
it('returns true when items is empty', () => {
|
|
69
|
+
expect((0, utils_1.containsAll)(['a', 'b', 'c'], [])).toBe(true);
|
|
70
|
+
expect((0, utils_1.containsAll)([], [])).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { FirstTime, OrderType, RequestedAt, RevenueCenter, ServiceType, TimeOption } from '@open-tender/types';
|
|
3
|
-
export declare const useFirstTimes: (firstTime: FirstTime, revenueCenter: RevenueCenter, serviceType: ServiceType, orderType: OrderType, requestedAt?: RequestedAt, isGroupOrder?: boolean) => {
|
|
3
|
+
export declare const useFirstTimes: (firstTime: FirstTime, revenueCenter: RevenueCenter, serviceType: ServiceType, orderType: OrderType, requestedAt?: RequestedAt, isGroupOrder?: boolean, days?: number) => {
|
|
4
4
|
date: `${number}${number}${number}${number}-${number}${number}-${number}${number}`;
|
|
5
5
|
setDate: import("react").Dispatch<import("react").SetStateAction<`${number}${number}${number}${number}-${number}${number}-${number}${number}`>>;
|
|
6
6
|
time: string | number;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useFirstTimes = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
-
const useFirstTimes = (firstTime, revenueCenter, serviceType, orderType, requestedAt, isGroupOrder = false) => {
|
|
6
|
+
const useFirstTimes = (firstTime, revenueCenter, serviceType, orderType, requestedAt, isGroupOrder = false, days = 100) => {
|
|
7
7
|
const { timezone, holidays, days_ahead, valid_times, group_ordering } = revenueCenter;
|
|
8
8
|
const { prep_time = 0, lead_time = 0 } = group_ordering || {};
|
|
9
9
|
const leadTime = isGroupOrder ? prep_time + lead_time : 0;
|
|
@@ -15,7 +15,7 @@ const useFirstTimes = (firstTime, revenueCenter, serviceType, orderType, request
|
|
|
15
15
|
const [date, setDate] = (0, react_1.useState)(requested.date || firstTime.date);
|
|
16
16
|
const [time, setTime] = (0, react_1.useState)(requested.minutes || firstTime.minutes);
|
|
17
17
|
const [dateChange, setDateChange] = (0, react_1.useState)(false);
|
|
18
|
-
const daysAhead = orderType === 'CATERING' ?
|
|
18
|
+
const daysAhead = orderType === 'CATERING' ? days : days_ahead;
|
|
19
19
|
const dates = (0, react_1.useMemo)(() => (0, utils_1.makeDates)(firstTime.date, daysAhead, 'E, MMM d'), [firstTime.date, daysAhead]);
|
|
20
20
|
const dateOptions = dates.map(({ label, value }) => ({ name: label, value }));
|
|
21
21
|
const timeOptions = (0, react_1.useMemo)(() => {
|
package/dist/cjs/utils/cart.js
CHANGED
|
@@ -818,8 +818,12 @@ const prepareOrder = (data) => {
|
|
|
818
818
|
order.deposit = data.deposit;
|
|
819
819
|
if (data.tenders)
|
|
820
820
|
order.tenders = data.tenders;
|
|
821
|
-
if (data.address)
|
|
821
|
+
if (data.address && data.serviceType === 'DELIVERY') {
|
|
822
822
|
order.address = data.address;
|
|
823
|
+
}
|
|
824
|
+
else {
|
|
825
|
+
order.address = null;
|
|
826
|
+
}
|
|
823
827
|
if (data.orderId)
|
|
824
828
|
order.order_id = data.orderId;
|
|
825
829
|
if (data.cartId)
|
|
@@ -3,7 +3,19 @@ export declare const isString: (str: any) => boolean;
|
|
|
3
3
|
export declare const isObject: (obj: any) => boolean;
|
|
4
4
|
export declare const isEmpty: (obj?: object | null) => boolean;
|
|
5
5
|
export declare const isNum: (s: string) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated please use `containsAll` or `containsAny` instead
|
|
8
|
+
* @returns true if first argument contains any of the values in the second argument
|
|
9
|
+
*/
|
|
6
10
|
export declare const contains: (arr: Array<any> | string, values: Array<any>) => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* @returns true if first argument contains any of the values in the second argument
|
|
13
|
+
*/
|
|
14
|
+
export declare const containsAny: <T>(arr: T[], values: T[]) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* @returns true if first argument contains all of the values of the second argument
|
|
17
|
+
*/
|
|
18
|
+
export declare const containsAll: <T>(arr: T[], values: T[]) => boolean;
|
|
7
19
|
export declare const slugify: (text: string) => string;
|
|
8
20
|
export declare const stripTags: (s: string) => string;
|
|
9
21
|
export declare const serialize: (obj: Record<string | number, string | number | boolean>) => string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasEntities = exports.convertStringToArray = exports.formatDollars = exports.formatPercentage = 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;
|
|
3
|
+
exports.hasEntities = exports.convertStringToArray = exports.formatDollars = exports.formatPercentage = 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.containsAll = exports.containsAny = 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
|
};
|
|
@@ -15,10 +15,28 @@ const isEmpty = (obj) => {
|
|
|
15
15
|
exports.isEmpty = isEmpty;
|
|
16
16
|
const isNum = (s) => /^\d+$/.test(s);
|
|
17
17
|
exports.isNum = isNum;
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated please use `containsAll` or `containsAny` instead
|
|
20
|
+
* @returns true if first argument contains any of the values in the second argument
|
|
21
|
+
*/
|
|
18
22
|
const contains = (arr, values) => {
|
|
19
23
|
return values.filter(i => arr.includes(i)).length > 0;
|
|
20
24
|
};
|
|
21
25
|
exports.contains = contains;
|
|
26
|
+
/**
|
|
27
|
+
* @returns true if first argument contains any of the values in the second argument
|
|
28
|
+
*/
|
|
29
|
+
const containsAny = (arr, values) => {
|
|
30
|
+
return values.length === 0 || values.filter(i => arr.includes(i)).length > 0;
|
|
31
|
+
};
|
|
32
|
+
exports.containsAny = containsAny;
|
|
33
|
+
/**
|
|
34
|
+
* @returns true if first argument contains all of the values of the second argument
|
|
35
|
+
*/
|
|
36
|
+
const containsAll = (arr, values) => {
|
|
37
|
+
return values.filter(i => arr.includes(i)).length === values.length;
|
|
38
|
+
};
|
|
39
|
+
exports.containsAll = containsAll;
|
|
22
40
|
// https://gist.github.com/mathewbyrne/1280286
|
|
23
41
|
const slugify = (text) => {
|
|
24
42
|
return text
|
|
@@ -9,10 +9,12 @@ export declare const makeStatus: (tiers: LoyaltyTier[], status: LoyaltyStatus, p
|
|
|
9
9
|
color: string;
|
|
10
10
|
value: string;
|
|
11
11
|
description: string;
|
|
12
|
+
discount: import("@open-tender/types").LoyaltyDiscount | null;
|
|
12
13
|
hex_code: string;
|
|
14
|
+
is_current_tier: true;
|
|
13
15
|
name: string;
|
|
14
16
|
threshold: string;
|
|
15
|
-
|
|
17
|
+
tier_no: number;
|
|
16
18
|
}[];
|
|
17
19
|
} | null;
|
|
18
20
|
export declare const makeProgress: (loyalty_type: LoyaltyType, spend: LoyaltySpend, redemption: LoyaltyRedemption) => number | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { formatPercentage, formatQuantity } from '../../utils';
|
|
1
|
+
import { formatPercentage, formatQuantity, containsAll, containsAny } from '../../utils';
|
|
2
2
|
describe('formatPercentage', () => {
|
|
3
3
|
it('formats percentage when decimal is undefined', () => {
|
|
4
4
|
expect(formatPercentage('0')).toBe('0');
|
|
@@ -31,3 +31,40 @@ describe('formatQuantity', () => {
|
|
|
31
31
|
expect(formatQuantity('1.55')).toBe('2');
|
|
32
32
|
});
|
|
33
33
|
});
|
|
34
|
+
describe('containsAny', () => {
|
|
35
|
+
it('returns true when array contains any of the items', () => {
|
|
36
|
+
expect(containsAny(['a', 'b', 'c'], ['a', 'd'])).toBe(true);
|
|
37
|
+
expect(containsAny(['a', 'b', 'c'], ['d', 'e', 'f'])).toBe(false);
|
|
38
|
+
expect(containsAny(['a', 'b', 'c'], ['a', 'b', 'c'])).toBe(true);
|
|
39
|
+
expect(containsAny(['a', 'b', 'c'], ['a', 'b', 'c', 'd'])).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
it('returns false when array does not contain any of the items', () => {
|
|
42
|
+
expect(containsAny(['a', 'b', 'c'], ['d', 'e'])).toBe(false);
|
|
43
|
+
expect(containsAny(['a', 'b', 'c'], ['d', 'e', 'f'])).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
it('returns false when array is empty', () => {
|
|
46
|
+
expect(containsAny([], ['a', 'b', 'c'])).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
it('returns true when items is empty', () => {
|
|
49
|
+
expect(containsAny(['a', 'b', 'c'], [])).toBe(true);
|
|
50
|
+
expect(containsAny([], [])).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
describe('containsAll', () => {
|
|
54
|
+
it('returns true when array contains all of the items', () => {
|
|
55
|
+
expect(containsAll(['a', 'b', 'c'], ['a', 'b'])).toBe(true);
|
|
56
|
+
expect(containsAll(['a', 'b', 'c'], ['a', 'b', 'c'])).toBe(true);
|
|
57
|
+
});
|
|
58
|
+
it('returns false when array does not contain all of the items', () => {
|
|
59
|
+
expect(containsAll(['a', 'b', 'c'], ['a', 'e'])).toBe(false);
|
|
60
|
+
expect(containsAll(['a', 'b', 'c'], ['d', 'e', 'f'])).toBe(false);
|
|
61
|
+
expect(containsAll(['a', 'b', 'c'], ['a', 'b', 'c', 'd'])).toBe(false);
|
|
62
|
+
});
|
|
63
|
+
it('returns false when array is empty', () => {
|
|
64
|
+
expect(containsAll([], ['a', 'b', 'c'])).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
it('returns true when items is empty', () => {
|
|
67
|
+
expect(containsAll(['a', 'b', 'c'], [])).toBe(true);
|
|
68
|
+
expect(containsAll([], [])).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { FirstTime, OrderType, RequestedAt, RevenueCenter, ServiceType, TimeOption } from '@open-tender/types';
|
|
3
|
-
export declare const useFirstTimes: (firstTime: FirstTime, revenueCenter: RevenueCenter, serviceType: ServiceType, orderType: OrderType, requestedAt?: RequestedAt, isGroupOrder?: boolean) => {
|
|
3
|
+
export declare const useFirstTimes: (firstTime: FirstTime, revenueCenter: RevenueCenter, serviceType: ServiceType, orderType: OrderType, requestedAt?: RequestedAt, isGroupOrder?: boolean, days?: number) => {
|
|
4
4
|
date: `${number}${number}${number}${number}-${number}${number}-${number}${number}`;
|
|
5
5
|
setDate: import("react").Dispatch<import("react").SetStateAction<`${number}${number}${number}${number}-${number}${number}-${number}${number}`>>;
|
|
6
6
|
time: string | number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMemo, useState } from 'react';
|
|
2
2
|
import { dateStrMinutesToIso, isoToDateStrMinutes, makeDates, makeReadableDateStrFromIso, makeTimes, timezoneMap } from '../utils';
|
|
3
|
-
export const useFirstTimes = (firstTime, revenueCenter, serviceType, orderType, requestedAt, isGroupOrder = false) => {
|
|
3
|
+
export const useFirstTimes = (firstTime, revenueCenter, serviceType, orderType, requestedAt, isGroupOrder = false, days = 100) => {
|
|
4
4
|
const { timezone, holidays, days_ahead, valid_times, group_ordering } = revenueCenter;
|
|
5
5
|
const { prep_time = 0, lead_time = 0 } = group_ordering || {};
|
|
6
6
|
const leadTime = isGroupOrder ? prep_time + lead_time : 0;
|
|
@@ -12,7 +12,7 @@ export const useFirstTimes = (firstTime, revenueCenter, serviceType, orderType,
|
|
|
12
12
|
const [date, setDate] = useState(requested.date || firstTime.date);
|
|
13
13
|
const [time, setTime] = useState(requested.minutes || firstTime.minutes);
|
|
14
14
|
const [dateChange, setDateChange] = useState(false);
|
|
15
|
-
const daysAhead = orderType === 'CATERING' ?
|
|
15
|
+
const daysAhead = orderType === 'CATERING' ? days : days_ahead;
|
|
16
16
|
const dates = useMemo(() => makeDates(firstTime.date, daysAhead, 'E, MMM d'), [firstTime.date, daysAhead]);
|
|
17
17
|
const dateOptions = dates.map(({ label, value }) => ({ name: label, value }));
|
|
18
18
|
const timeOptions = useMemo(() => {
|
package/dist/esm/utils/cart.js
CHANGED
|
@@ -783,8 +783,12 @@ export const prepareOrder = (data) => {
|
|
|
783
783
|
order.deposit = data.deposit;
|
|
784
784
|
if (data.tenders)
|
|
785
785
|
order.tenders = data.tenders;
|
|
786
|
-
if (data.address)
|
|
786
|
+
if (data.address && data.serviceType === 'DELIVERY') {
|
|
787
787
|
order.address = data.address;
|
|
788
|
+
}
|
|
789
|
+
else {
|
|
790
|
+
order.address = null;
|
|
791
|
+
}
|
|
788
792
|
if (data.orderId)
|
|
789
793
|
order.order_id = data.orderId;
|
|
790
794
|
if (data.cartId)
|
|
@@ -3,7 +3,19 @@ export declare const isString: (str: any) => boolean;
|
|
|
3
3
|
export declare const isObject: (obj: any) => boolean;
|
|
4
4
|
export declare const isEmpty: (obj?: object | null) => boolean;
|
|
5
5
|
export declare const isNum: (s: string) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated please use `containsAll` or `containsAny` instead
|
|
8
|
+
* @returns true if first argument contains any of the values in the second argument
|
|
9
|
+
*/
|
|
6
10
|
export declare const contains: (arr: Array<any> | string, values: Array<any>) => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* @returns true if first argument contains any of the values in the second argument
|
|
13
|
+
*/
|
|
14
|
+
export declare const containsAny: <T>(arr: T[], values: T[]) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* @returns true if first argument contains all of the values of the second argument
|
|
17
|
+
*/
|
|
18
|
+
export declare const containsAll: <T>(arr: T[], values: T[]) => boolean;
|
|
7
19
|
export declare const slugify: (text: string) => string;
|
|
8
20
|
export declare const stripTags: (s: string) => string;
|
|
9
21
|
export declare const serialize: (obj: Record<string | number, string | number | boolean>) => string;
|
|
@@ -8,9 +8,25 @@ export const isEmpty = (obj) => {
|
|
|
8
8
|
return (!obj || (obj.constructor === Object && Object.entries(obj).length === 0));
|
|
9
9
|
};
|
|
10
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
|
+
*/
|
|
11
15
|
export const contains = (arr, values) => {
|
|
12
16
|
return values.filter(i => arr.includes(i)).length > 0;
|
|
13
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
|
+
};
|
|
14
30
|
// https://gist.github.com/mathewbyrne/1280286
|
|
15
31
|
export const slugify = (text) => {
|
|
16
32
|
return text
|
|
@@ -9,10 +9,12 @@ export declare const makeStatus: (tiers: LoyaltyTier[], status: LoyaltyStatus, p
|
|
|
9
9
|
color: string;
|
|
10
10
|
value: string;
|
|
11
11
|
description: string;
|
|
12
|
+
discount: import("@open-tender/types").LoyaltyDiscount | null;
|
|
12
13
|
hex_code: string;
|
|
14
|
+
is_current_tier: true;
|
|
13
15
|
name: string;
|
|
14
16
|
threshold: string;
|
|
15
|
-
|
|
17
|
+
tier_no: number;
|
|
16
18
|
}[];
|
|
17
19
|
} | null;
|
|
18
20
|
export declare const makeProgress: (loyalty_type: LoyaltyType, spend: LoyaltySpend, redemption: LoyaltyRedemption) => number | null;
|
package/package.json
CHANGED