@ancon/wildcat-utils 1.23.2 → 1.24.0

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.
@@ -0,0 +1,10 @@
1
+ import { OrderFormat, ServiceDateTime, ServiceDateTimeInterval } from '@ancon/wildcat-types';
2
+ /**
3
+ * Returns the intervals for the specified weekday index (0-6) and order format (optional)
4
+ *
5
+ * @param weekdayIndex
6
+ * @param serviceDateTimes
7
+ * @param orderFormat
8
+ * @returns
9
+ */
10
+ export default function getPickerIntervalsForDay(weekdayIndex: number, serviceDateTimes: ServiceDateTime[], orderFormat?: OrderFormat): ServiceDateTimeInterval[];
@@ -0,0 +1 @@
1
+ "use strict";const o=require("moment"),y=require("../shared/enums.js"),d=require("../shared/constants.js"),m=require("./getServiceIntervalsForOrderFormat.js");function F(t,n,u){return m(u,n).reduce((e,r)=>{const i=r.dayOfWeek===y.DayOfWeek.Everyday,a=!!r.type;if(i){if(a){const s=o(r.fromDate),f=o().isoWeekday(t);return s.isSame(f,"isoWeek")&&t===s.isoWeekday()&&e.push(r),e}return e.push(r),e}return r.dayOfWeek===d.DaysOfWeekMap[t]&&e.push(r),e},[])}module.exports=F;
@@ -0,0 +1,26 @@
1
+ import s from "moment";
2
+ import { DayOfWeek as p } from "../shared/enums.mjs";
3
+ import { DaysOfWeekMap as u } from "../shared/constants.mjs";
4
+ import y from "./getServiceIntervalsForOrderFormat.mjs";
5
+ function D(o, f, m) {
6
+ return y(
7
+ m,
8
+ f
9
+ ).reduce(
10
+ (r, e) => {
11
+ const i = e.dayOfWeek === p.Everyday, a = !!e.type;
12
+ if (i) {
13
+ if (a) {
14
+ const t = s(e.fromDate), n = s().isoWeekday(o);
15
+ return t.isSame(n, "isoWeek") && o === t.isoWeekday() && r.push(e), r;
16
+ }
17
+ return r.push(e), r;
18
+ }
19
+ return e.dayOfWeek === u[o] && r.push(e), r;
20
+ },
21
+ []
22
+ );
23
+ }
24
+ export {
25
+ D as default
26
+ };
@@ -0,0 +1,12 @@
1
+ import { ServiceDateTimeInterval } from '@ancon/wildcat-types';
2
+ import moment, { Moment } from 'moment';
3
+ /**
4
+ * Calculates the start and end date of an outlet service interval and returns them as Moment objects.
5
+ *
6
+ * @param date - Moment object representing the date to be used for the calculation
7
+ * @param interval - Object containing the start and duration of the interval in the form "hh:mm:ss"
8
+ * @param preparationTime - String representing the preparation time in the form "hh:mm:ss"
9
+ * @param outletTimeZoneOffset - String representing the outlet timezone offset in the form "hh:mm:ss"
10
+ * @returns - Array containing the interval start and end as Moment objects
11
+ */
12
+ export default function getServiceIntervalRange(date: Moment, interval: Pick<ServiceDateTimeInterval, 'start' | 'duration'>, preparationTime?: string, outletTimeZoneOffset?: string): moment.Moment[];
@@ -0,0 +1 @@
1
+ "use strict";const H=require("moment"),v=require("../time/toMinutes.js"),S=require("../time/getNextTenthMinute.js");function n(e){return e.split(":").map(Number)}function b(e,s,r="00:00:00",c="00:00:00"){const{duration:d,start:m}=s,[a,f]=n(m),[l,M]=n(c),[p,h]=n(r),[O,T]=n(d),t=e.clone().utc(!0).hour(a).minute(f).second(0).millisecond(0),o=t.clone().add(l,"hour").add(M,"minute").date()-e.date();o!==0&&t.subtract(o,"day");const i=v(p,h),u=t.clone().add(O,"hours").add(T,"minutes");return u.diff(H().utc(!0),"minutes")<i&&u.subtract(i,"minutes"),t.add(i,"minutes"),t.minute(S(t)),[t,u]}module.exports=b;
@@ -0,0 +1,15 @@
1
+ import H from "moment";
2
+ import v from "../time/toMinutes.mjs";
3
+ import S from "../time/getNextTenthMinute.mjs";
4
+ function n(e) {
5
+ return e.split(":").map(Number);
6
+ }
7
+ function N(e, s, r = "00:00:00", m = "00:00:00") {
8
+ const { duration: d, start: a } = s, [c, f] = n(a), [l, p] = n(m), [M, h] = n(r), [O, T] = n(d), t = e.clone().utc(!0).hour(c).minute(f).second(0).millisecond(0), u = t.clone().add(l, "hour").add(p, "minute").date() - e.date();
9
+ u !== 0 && t.subtract(u, "day");
10
+ const o = v(M, h), i = t.clone().add(O, "hours").add(T, "minutes");
11
+ return i.diff(H().utc(!0), "minutes") < o && i.subtract(o, "minutes"), t.add(o, "minutes"), t.minute(S(t)), [t, i];
12
+ }
13
+ export {
14
+ N as default
15
+ };
@@ -0,0 +1,25 @@
1
+ import { OrderFormat, ServiceDateTime } from '@ancon/wildcat-types';
2
+ declare type ModifiedServiceDateTimeInterval = {
3
+ start: string;
4
+ duration: string;
5
+ end: string;
6
+ fromDate: string;
7
+ toDate: string;
8
+ type: number;
9
+ position: number;
10
+ state: number;
11
+ dayOfWeek: number;
12
+ isDefault: boolean;
13
+ reason: string;
14
+ orderFormats: OrderFormat;
15
+ };
16
+ /**
17
+ * @param orderFormat - The order format to filter by - if undefined, returns all intervals
18
+ * @param serviceDateTimes - The outlet service date times
19
+ * @returns - An array of intervals for the matching order format
20
+ *
21
+ * @example
22
+ * getServiceIntervalsForOrderFormat(OrderFormat.Delivery, serviceDateTimes) // returns all delivery intervals
23
+ */
24
+ export default function getServiceIntervalsForOrderFormat(orderFormat?: OrderFormat, serviceDateTimes?: ServiceDateTime[]): ModifiedServiceDateTimeInterval[];
25
+ export {};
@@ -0,0 +1 @@
1
+ "use strict";function d(t,n=[]){if(t===void 0)return n.reduce((r,o)=>(r.push(...o.intervals.map(s=>({...s,orderFormats:o.orderFormats}))),r),[]);const u=n.some(r=>r.orderFormats===t);return n.reduce((r,o)=>(!u&&(o.orderFormats&t)!==t||(!u||o.orderFormats===t)&&r.push(...o.intervals.map(s=>({...s,orderFormats:o.orderFormats}))),r),[])}module.exports=d;
@@ -0,0 +1,27 @@
1
+ function d(n, t = []) {
2
+ if (n === void 0)
3
+ return t.reduce(
4
+ (r, o) => (r.push(
5
+ ...o.intervals.map((u) => ({
6
+ ...u,
7
+ orderFormats: o.orderFormats
8
+ }))
9
+ ), r),
10
+ []
11
+ );
12
+ const s = t.some(
13
+ (r) => r.orderFormats === n
14
+ );
15
+ return t.reduce(
16
+ (r, o) => (!s && (o.orderFormats & n) !== n || (!s || o.orderFormats === n) && r.push(
17
+ ...o.intervals.map((u) => ({
18
+ ...u,
19
+ orderFormats: o.orderFormats
20
+ }))
21
+ ), r),
22
+ []
23
+ );
24
+ }
25
+ export {
26
+ d as default
27
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ancon/wildcat-utils",
3
- "version": "1.23.2",
3
+ "version": "1.24.0",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -276,6 +276,21 @@
276
276
  "require": "./outlet/getOutletTodayOpeningTimes.js",
277
277
  "types": "./outlet/getOutletTodayOpeningTimes.d.ts"
278
278
  },
279
+ "./outlet/getPickerIntervalsForDay": {
280
+ "import": "./outlet/getPickerIntervalsForDay.mjs",
281
+ "require": "./outlet/getPickerIntervalsForDay.js",
282
+ "types": "./outlet/getPickerIntervalsForDay.d.ts"
283
+ },
284
+ "./outlet/getServiceIntervalRange": {
285
+ "import": "./outlet/getServiceIntervalRange.mjs",
286
+ "require": "./outlet/getServiceIntervalRange.js",
287
+ "types": "./outlet/getServiceIntervalRange.d.ts"
288
+ },
289
+ "./outlet/getServiceIntervalsForOrderFormat": {
290
+ "import": "./outlet/getServiceIntervalsForOrderFormat.mjs",
291
+ "require": "./outlet/getServiceIntervalsForOrderFormat.js",
292
+ "types": "./outlet/getServiceIntervalsForOrderFormat.d.ts"
293
+ },
279
294
  "./outlet": {
280
295
  "import": "./outlet/index.mjs",
281
296
  "require": "./outlet/index.js",
@@ -331,6 +346,11 @@
331
346
  "require": "./printing/isValidStarCloudPrinter.js",
332
347
  "types": "./printing/isValidStarCloudPrinter.d.ts"
333
348
  },
349
+ "./shared/constants": {
350
+ "import": "./shared/constants.mjs",
351
+ "require": "./shared/constants.js",
352
+ "types": "./shared/constants.d.ts"
353
+ },
334
354
  "./shared/enums": {
335
355
  "import": "./shared/enums.mjs",
336
356
  "require": "./shared/enums.js",
@@ -401,6 +421,21 @@
401
421
  "require": "./tables/index.js",
402
422
  "types": "./tables/index.d.ts"
403
423
  },
424
+ "./time/getNextTenthMinute": {
425
+ "import": "./time/getNextTenthMinute.mjs",
426
+ "require": "./time/getNextTenthMinute.js",
427
+ "types": "./time/getNextTenthMinute.d.ts"
428
+ },
429
+ "./time": {
430
+ "import": "./time/index.mjs",
431
+ "require": "./time/index.js",
432
+ "types": "./time/index.d.ts"
433
+ },
434
+ "./time/toMinutes": {
435
+ "import": "./time/toMinutes.mjs",
436
+ "require": "./time/toMinutes.js",
437
+ "types": "./time/toMinutes.d.ts"
438
+ },
404
439
  "./user/getFormattedPhoneNumber": {
405
440
  "import": "./user/getFormattedPhoneNumber.mjs",
406
441
  "require": "./user/getFormattedPhoneNumber.js",
@@ -0,0 +1,2 @@
1
+ import { DayOfWeek } from './enums';
2
+ export declare const DaysOfWeekMap: Record<number, DayOfWeek>;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./enums.js"),a={0:e.DayOfWeek.Everyday,1:e.DayOfWeek.Monday,2:e.DayOfWeek.Tuesday,3:e.DayOfWeek.Wednesday,4:e.DayOfWeek.Thursday,5:e.DayOfWeek.Friday,6:e.DayOfWeek.Saturday,7:e.DayOfWeek.Sunday};exports.DaysOfWeekMap=a;
@@ -0,0 +1,14 @@
1
+ import { DayOfWeek as a } from "./enums.mjs";
2
+ const d = {
3
+ 0: a.Everyday,
4
+ 1: a.Monday,
5
+ 2: a.Tuesday,
6
+ 3: a.Wednesday,
7
+ 4: a.Thursday,
8
+ 5: a.Friday,
9
+ 6: a.Saturday,
10
+ 7: a.Sunday
11
+ };
12
+ export {
13
+ d as DaysOfWeekMap
14
+ };
@@ -0,0 +1,12 @@
1
+ import { Moment } from 'moment';
2
+ /**
3
+ * Returns the next tenth minute from the given moment object
4
+ *
5
+ * @param momentObject - Moment object to get the next tenth minute from (defaults to now)
6
+ * @returns - The next tenth minute from the given moment object
7
+ *
8
+ * @example
9
+ * getNextTenthMinute(moment('2021-01-01 12:39:56')) // 40
10
+ * getNextTenthMinute(moment('2021-01-01 12:31:56')) // 40
11
+ */
12
+ export default function getNextTenthMinute(momentObject?: Moment): number;
@@ -0,0 +1 @@
1
+ "use strict";const e=require("moment");function n(t){return Math.ceil((t??e()).minutes()/10)*10}module.exports=n;
@@ -0,0 +1,7 @@
1
+ import e from "moment";
2
+ function i(t) {
3
+ return Math.ceil((t ?? e()).minutes() / 10) * 10;
4
+ }
5
+ export {
6
+ i as default
7
+ };
@@ -0,0 +1,3 @@
1
+ import toMinutes from './toMinutes';
2
+ import getNextTenthMinute from './getNextTenthMinute';
3
+ export { toMinutes, getNextTenthMinute };
package/time/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./toMinutes.js"),t=require("./getNextTenthMinute.js");require("moment");exports.toMinutes=e;exports.getNextTenthMinute=t;
package/time/index.mjs ADDED
@@ -0,0 +1,7 @@
1
+ import { default as r } from "./toMinutes.mjs";
2
+ import { default as f } from "./getNextTenthMinute.mjs";
3
+ import "moment";
4
+ export {
5
+ f as getNextTenthMinute,
6
+ r as toMinutes
7
+ };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Converts hours and minutes to minutes
3
+ */
4
+ export default function toMinutes(hours?: number, minutes?: number): number;
@@ -0,0 +1 @@
1
+ "use strict";const o=require("moment");function r(e=0,n=0){const t=o();return t.clone().add(e,"hour").add(n,"minute").diff(t,"minute")}module.exports=r;
@@ -0,0 +1,8 @@
1
+ import n from "moment";
2
+ function r(e = 0, o = 0) {
3
+ const t = n();
4
+ return t.clone().add(e, "hour").add(o, "minute").diff(t, "minute");
5
+ }
6
+ export {
7
+ r as default
8
+ };