@ancon/wildcat-utils 1.20.16 → 1.20.17

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 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("moment"),g=require("./types.js"),d=require("./constants.js"),M=require("./getOutletCurrentActiveOperatingHour.js"),v=require("./getMomentFromDateAndTimeString.js"),k=require("./searchNextOpeningMoment.js");require("@ancon/wildcat-types");const D={0:127,1:1,2:2,3:4,4:8,5:16,6:32,7:64};function S(o,e){const a=o.isSame(e,"d"),n={[e.format(d.OutletMapKeyFormatter)]:{intervals:[],exception:null,metadata:{dayOfWeek:D[e.isoWeekday()]}}};for(let i=a?1:0;i<d.OutletTimelineDayCount;i+=1){const s=c(o).add(i,"d");n[s.format(d.OutletMapKeyFormatter)]={intervals:[],exception:null,metadata:{dayOfWeek:D[s.isoWeekday()]}}}return n}function W(o,e){const a=c().utcOffset(),t=c(e.fromDate).utc(!1).subtract(a,"minutes"),n=c(e.toDate).utc(!1).subtract(a,"minutes");if(!t.isSame(n,"d"))Object.keys(o).forEach(s=>{const r=c(s);if(r.isSame(t,"d")||r.isSame(n,"d")||r.isBetween(t,n)){const l=o[s],u=l.exception?l.exception.position:0;e.position>u&&(l.exception=e)}});else{const s=t.format(d.OutletMapKeyFormatter),r=o[s];if(r){const y=r.exception?r.exception.position:0;e.position>y&&(r.exception=e)}}}function E(o,e){Object.keys(o).forEach(a=>{const t=o[a],{dayOfWeek:n}=t.metadata,{dayOfWeek:i}=e;(n&i)===n&&t.intervals.push(e)})}function K(o,e,a){const t=S(e,a);return o.forEach(n=>{n.type===g.OperatingHourType.Exception?W(t,n):E(t,n)}),t}function x(o,e,a,t,n){const i=K(o,a,t),s=t.format(d.OutletMapKeyFormatter),r=M(s,i[s],t)!==null,y=e;let l=null,u=null;if(e){const m=a.format(d.OutletMapKeyFormatter),p=M(m,i[m],a);if(p){const[f,O]=p.duration.split(":").map(Number);u=v(m,p.start),l=u.clone().add(f,"hours").add(O,"minutes")}}else u=k(i,a,n);if(!e&&!u){const m=o.filter(f=>f.state&&c(f.toDate).isAfter(a)),[p]=m.sort((f,O)=>t.valueOf()-(c(f.toDate).valueOf()-c(O.toDate).valueOf()));if(p)return x(o,e,c(p.toDate),t)}return{closingTime:l,openingTime:u,openDuringSpecifiedTime:y,openNow:r}}exports.DaysOfWeekMap=D;exports.default=x;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("moment"),g=require("./types.js"),d=require("./constants.js"),M=require("./getOutletCurrentActiveOperatingHour.js"),v=require("./getMomentFromDateAndTimeString.js"),k=require("./searchNextOpeningMoment.js");require("@ancon/wildcat-types");const D={0:127,1:1,2:2,3:4,4:8,5:16,6:32,7:64};function S(n,t){const a=n.isSame(t,"d"),o={[t.format(d.OutletMapKeyFormatter)]:{intervals:[],exception:null,metadata:{dayOfWeek:D[t.isoWeekday()]}}};for(let i=a?1:0;i<d.OutletTimelineDayCount;i+=1){const s=c(n).add(i,"d");o[s.format(d.OutletMapKeyFormatter)]={intervals:[],exception:null,metadata:{dayOfWeek:D[s.isoWeekday()]}}}return o}function W(n,t){const a=c().utcOffset(),e=c(t.fromDate).utc(!1).subtract(a,"minutes"),o=c(t.toDate).utc(!1).subtract(a,"minutes");if(!e.isSame(o,"d"))Object.keys(n).forEach(s=>{const r=c(s);if(r.isSame(e,"d")||r.isSame(o,"d")||r.isBetween(e,o)){const l=n[s],u=l.exception?l.exception.position:0;t.position>u&&(l.exception=t)}});else{const s=e.format(d.OutletMapKeyFormatter),r=n[s];if(r){const y=r.exception?r.exception.position:0;t.position>y&&(r.exception=t)}}}function E(n,t){Object.keys(n).forEach(a=>{const e=n[a],{dayOfWeek:o}=e.metadata,{dayOfWeek:i}=t;(o&i)===o&&e.intervals.push(t)})}function K(n,t,a){const e=S(t,a);return n.forEach(o=>{o.type===g.OperatingHourType.Exception?W(e,o):E(e,o)}),e}function x(n,t,a,e,o){const i=K(n,a,e),s=e.format(d.OutletMapKeyFormatter),r=M(s,i[s],e)!==null,y=t;let l=null,u=null;if(t){const m=a.format(d.OutletMapKeyFormatter),p=M(m,i[m],a);if(p){const[f,O]=p.duration.split(":").map(Number);u=v(m,p.start),l=u.clone().add(f,"hours").add(O,"minutes")}}else u=k(i,a,o);if(!t&&!u){const m=n.filter(f=>f.state&&c(f.toDate).isAfter(a)),[p]=m.sort((f,O)=>e.valueOf()-(c(f.toDate).valueOf()-c(O.toDate).valueOf()));if(p)return x(n,t,c(p.toDate),e,o)}return{closingTime:l,openingTime:u,openDuringSpecifiedTime:y,openNow:r}}exports.DaysOfWeekMap=D;exports.default=x;
@@ -15,8 +15,8 @@ const x = {
15
15
  6: 32,
16
16
  7: 64
17
17
  };
18
- function S(o, t) {
19
- const a = o.isSame(t, "d"), n = {
18
+ function S(n, t) {
19
+ const a = n.isSame(t, "d"), o = {
20
20
  [t.format(d)]: {
21
21
  intervals: [],
22
22
  exception: null,
@@ -24,51 +24,51 @@ function S(o, t) {
24
24
  }
25
25
  };
26
26
  for (let i = a ? 1 : 0; i < k; i += 1) {
27
- const s = c(o).add(i, "d");
28
- n[s.format(d)] = {
27
+ const s = c(n).add(i, "d");
28
+ o[s.format(d)] = {
29
29
  intervals: [],
30
30
  exception: null,
31
31
  metadata: { dayOfWeek: x[s.isoWeekday()] }
32
32
  };
33
33
  }
34
- return n;
34
+ return o;
35
35
  }
36
- function W(o, t) {
37
- const a = c().utcOffset(), e = c(t.fromDate).utc(!1).subtract(a, "minutes"), n = c(t.toDate).utc(!1).subtract(a, "minutes");
36
+ function W(n, t) {
37
+ const a = c().utcOffset(), e = c(t.fromDate).utc(!1).subtract(a, "minutes"), o = c(t.toDate).utc(!1).subtract(a, "minutes");
38
38
  if (!e.isSame(
39
- n,
39
+ o,
40
40
  "d"
41
41
  ))
42
- Object.keys(o).forEach((s) => {
42
+ Object.keys(n).forEach((s) => {
43
43
  const r = c(s);
44
- if (r.isSame(e, "d") || r.isSame(n, "d") || r.isBetween(e, n)) {
45
- const f = o[s], p = f.exception ? f.exception.position : 0;
44
+ if (r.isSame(e, "d") || r.isSame(o, "d") || r.isBetween(e, o)) {
45
+ const f = n[s], p = f.exception ? f.exception.position : 0;
46
46
  t.position > p && (f.exception = t);
47
47
  }
48
48
  });
49
49
  else {
50
- const s = e.format(d), r = o[s];
50
+ const s = e.format(d), r = n[s];
51
51
  if (r) {
52
52
  const y = r.exception ? r.exception.position : 0;
53
53
  t.position > y && (r.exception = t);
54
54
  }
55
55
  }
56
56
  }
57
- function E(o, t) {
58
- Object.keys(o).forEach((a) => {
59
- const e = o[a], { dayOfWeek: n } = e.metadata, { dayOfWeek: i } = t;
60
- (n & i) === n && e.intervals.push(t);
57
+ function E(n, t) {
58
+ Object.keys(n).forEach((a) => {
59
+ const e = n[a], { dayOfWeek: o } = e.metadata, { dayOfWeek: i } = t;
60
+ (o & i) === o && e.intervals.push(t);
61
61
  });
62
62
  }
63
- function I(o, t, a) {
63
+ function I(n, t, a) {
64
64
  const e = S(t, a);
65
- return o.forEach((n) => {
66
- n.type === g.Exception ? W(e, n) : E(e, n);
65
+ return n.forEach((o) => {
66
+ o.type === g.Exception ? W(e, o) : E(e, o);
67
67
  }), e;
68
68
  }
69
- function h(o, t, a, e, n) {
69
+ function h(n, t, a, e, o) {
70
70
  const i = I(
71
- o,
71
+ n,
72
72
  a,
73
73
  e
74
74
  ), s = e.format(d), r = D(
@@ -94,20 +94,21 @@ function h(o, t, a, e, n) {
94
94
  p = M(
95
95
  i,
96
96
  a,
97
- n
97
+ o
98
98
  );
99
99
  if (!t && !p) {
100
- const u = o.filter(
100
+ const u = n.filter(
101
101
  (m) => m.state && c(m.toDate).isAfter(a)
102
102
  ), [l] = u.sort(
103
103
  (m, O) => e.valueOf() - (c(m.toDate).valueOf() - c(O.toDate).valueOf())
104
104
  );
105
105
  if (l)
106
106
  return h(
107
- o,
107
+ n,
108
108
  t,
109
109
  c(l.toDate),
110
- e
110
+ e,
111
+ o
111
112
  );
112
113
  }
113
114
  return { closingTime: f, openingTime: p, openDuringSpecifiedTime: y, openNow: r };
@@ -1 +1 @@
1
- "use strict";const m=require("moment"),p=require("@ancon/wildcat-types"),c=require("./constants.js"),a=require("./getMomentFromDateAndTimeString.js");function O(i){const[e]=i.split(":").map(Number)??[];return e??0}function d(i,e,r="00:00:00"){const[t,o]=r.split(":"),n=i.clone().add(t,"hour").add(o,"minute").date()-e.date();return n!==0?i.subtract(n,"day"):i}function g(i){let e=null;const{intervals:r,exception:t}=i;if(t){const{state:o}=t;o||(e=t)}else{const o=r.sort((n,s)=>O(n.start)-O(s.start)),[u]=o;return u}return e}function h(i,e,r){var o,u;const t=[];if(e.exception){if(e.exception.state===p.OutletState.Open){const n=a(i,e.exception.start);r.isBefore(n)&&t.push({interval:e.exception,moment:n})}}else for(let n=0;n<e.intervals.length;n+=1){const s=e.intervals[n],l=a(i,s.start);r.isBefore(l)&&t.push({interval:s,moment:l})}return t.length<2?((o=t[0])==null?void 0:o.interval)??null:((u=t.sort((n,s)=>n.moment-r-(s.moment-r))[0])==null?void 0:u.interval)??null}function x(i,e,r){let t=null;const o=m(e).format(c.OutletMapKeyFormatter),u=h(o,i[o],e);if(u&&(t=a(o,u.start),t=d(t,e,r)),!t)for(let n=1;n<c.OutletTimelineDayCount;n+=1){const s=m(e).add(n,"d"),l=s.format(c.OutletMapKeyFormatter),y=i[l],f=g(y);if(f){t=a(l,f.start),t=d(t,s,r);break}}return t}module.exports=x;
1
+ "use strict";const m=require("moment"),y=require("@ancon/wildcat-types"),c=require("./constants.js"),a=require("./getMomentFromDateAndTimeString.js");function O(i){const[e]=i.split(":").map(Number)??[];return e??0}function p(i,e,r="00:00:00"){const[t,o]=r.split(":"),n=i.clone().add(t,"hour").add(o,"minute").date()-e.date();return n!==0?i.subtract(n,"day"):i}function g(i){let e=null;const{intervals:r,exception:t}=i;if(t){const{state:o}=t;o||(e=t)}else{const o=r.sort((n,s)=>O(n.start)-O(s.start)),[u]=o;return u}return e}function h(i,e,r){var o,u;const t=[];if(e.exception){if(e.exception.state===y.OutletState.Open){const n=a(i,e.exception.start);r.isBefore(n)&&t.push({interval:e.exception,moment:n})}}else for(let n=0;n<e.intervals.length;n+=1){const s=e.intervals[n],l=a(i,s.start);r.isBefore(l)&&t.push({interval:s,moment:l})}return t.length<2?((o=t[0])==null?void 0:o.interval)??null:((u=t.sort((n,s)=>n.moment-r-(s.moment-r))[0])==null?void 0:u.interval)??null}function x(i,e,r){let t=null;const o=m(e).format(c.OutletMapKeyFormatter),u=h(o,i[o],e);if(u&&(t=a(o,u.start)),!t)for(let n=1;n<c.OutletTimelineDayCount;n+=1){const s=m(e).add(n,"d"),l=s.format(c.OutletMapKeyFormatter),d=i[l],f=g(d);if(f){t=a(l,f.start),t=p(t,s,r);break}}return t}module.exports=x;
@@ -1,36 +1,36 @@
1
- import c from "moment";
2
- import { OutletState as y } from "@ancon/wildcat-types";
3
- import { OutletMapKeyFormatter as m, OutletTimelineDayCount as g } from "./constants.mjs";
1
+ import m from "moment";
2
+ import { OutletState as d } from "@ancon/wildcat-types";
3
+ import { OutletMapKeyFormatter as c, OutletTimelineDayCount as y } from "./constants.mjs";
4
4
  import a from "./getMomentFromDateAndTimeString.mjs";
5
- function O(i) {
6
- const [e] = i.split(":").map(Number) ?? [];
5
+ function O(o) {
6
+ const [e] = o.split(":").map(Number) ?? [];
7
7
  return e ?? 0;
8
8
  }
9
- function p(i, e, r = "00:00:00") {
10
- const [t, o] = r.split(":"), n = i.clone().add(t, "hour").add(o, "minute").date() - e.date();
11
- return n !== 0 ? i.subtract(n, "day") : i;
9
+ function g(o, e, r = "00:00:00") {
10
+ const [t, i] = r.split(":"), n = o.clone().add(t, "hour").add(i, "minute").date() - e.date();
11
+ return n !== 0 ? o.subtract(n, "day") : o;
12
12
  }
13
- function h(i) {
13
+ function h(o) {
14
14
  let e = null;
15
- const { intervals: r, exception: t } = i;
15
+ const { intervals: r, exception: t } = o;
16
16
  if (t) {
17
- const { state: o } = t;
18
- o || (e = t);
17
+ const { state: i } = t;
18
+ i || (e = t);
19
19
  } else {
20
- const o = r.sort(
20
+ const i = r.sort(
21
21
  (n, s) => O(n.start) - O(s.start)
22
- ), [l] = o;
22
+ ), [l] = i;
23
23
  return l;
24
24
  }
25
25
  return e;
26
26
  }
27
- function x(i, e, r) {
28
- var o, l;
27
+ function x(o, e, r) {
28
+ var i, l;
29
29
  const t = [];
30
30
  if (e.exception) {
31
- if (e.exception.state === y.Open) {
31
+ if (e.exception.state === d.Open) {
32
32
  const n = a(
33
- i,
33
+ o,
34
34
  e.exception.start
35
35
  );
36
36
  r.isBefore(n) && t.push({
@@ -41,37 +41,33 @@ function x(i, e, r) {
41
41
  } else
42
42
  for (let n = 0; n < e.intervals.length; n += 1) {
43
43
  const s = e.intervals[n], u = a(
44
- i,
44
+ o,
45
45
  s.start
46
46
  );
47
47
  r.isBefore(u) && t.push({ interval: s, moment: u });
48
48
  }
49
- return t.length < 2 ? ((o = t[0]) == null ? void 0 : o.interval) ?? null : ((l = t.sort(
49
+ return t.length < 2 ? ((i = t[0]) == null ? void 0 : i.interval) ?? null : ((l = t.sort(
50
50
  (n, s) => n.moment - r - (s.moment - r)
51
51
  )[0]) == null ? void 0 : l.interval) ?? null;
52
52
  }
53
- function b(i, e, r) {
53
+ function b(o, e, r) {
54
54
  let t = null;
55
- const o = c(e).format(m), l = x(
56
- o,
57
- i[o],
55
+ const i = m(e).format(c), l = x(
56
+ i,
57
+ o[i],
58
58
  e
59
59
  );
60
60
  if (l && (t = a(
61
- o,
61
+ i,
62
62
  l.start
63
- ), t = p(
64
- t,
65
- e,
66
- r
67
63
  )), !t)
68
- for (let n = 1; n < g; n += 1) {
69
- const s = c(e).add(n, "d"), u = s.format(m), d = i[u], f = h(d);
64
+ for (let n = 1; n < y; n += 1) {
65
+ const s = m(e).add(n, "d"), u = s.format(c), p = o[u], f = h(p);
70
66
  if (f) {
71
67
  t = a(
72
68
  u,
73
69
  f.start
74
- ), t = p(
70
+ ), t = g(
75
71
  t,
76
72
  s,
77
73
  r
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ancon/wildcat-utils",
3
- "version": "1.20.16",
3
+ "version": "1.20.17",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",