@ancon/wildcat-utils 1.10.0 → 1.10.2
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/api/getEndpointWithVersion.js +1 -6
- package/api/getEndpointWithVersion.mjs +6 -0
- package/api/getUrlAndParams.js +1 -23
- package/api/getUrlAndParams.mjs +23 -0
- package/api/index.js +1 -6
- package/api/index.mjs +6 -0
- package/color/brighten.js +1 -7
- package/color/brighten.mjs +7 -0
- package/color/darken.js +1 -7
- package/color/darken.mjs +7 -0
- package/color/index.js +1 -9
- package/color/index.mjs +9 -0
- package/color/lighten.js +1 -7
- package/color/lighten.mjs +7 -0
- package/index.js +1 -40
- package/index.mjs +40 -0
- package/logger/Logger.js +1 -30
- package/logger/Logger.mjs +30 -0
- package/logger/index.js +1 -6
- package/logger/index.mjs +6 -0
- package/logger/types.js +1 -4
- package/logger/types.mjs +4 -0
- package/outlet/getListOutletOpeningHoursTable.js +1 -172
- package/outlet/getListOutletOpeningHoursTable.mjs +172 -0
- package/outlet/index.js +1 -8
- package/outlet/index.mjs +8 -0
- package/outlet/types.js +1 -1
- package/outlet/types.mjs +1 -0
- package/package.json +53 -28
- package/shared/enums.js +1 -7
- package/shared/enums.mjs +7 -0
- package/shared/generateId.js +1 -7
- package/shared/generateId.mjs +7 -0
- package/shared/index.js +1 -11
- package/shared/index.mjs +11 -0
- package/shared/isWithinFlag.js +1 -6
- package/shared/isWithinFlag.mjs +6 -0
- package/string/index.js +1 -4
- package/string/index.mjs +4 -0
- package/string/slugify.js +1 -6
- package/string/slugify.mjs +6 -0
- package/user/getFullAddressString.js +1 -6
- package/user/getFullAddressString.mjs +6 -0
- package/user/getFullName.js +1 -13
- package/user/getFullName.mjs +13 -0
- package/user/index.js +1 -6
- package/user/index.mjs +6 -0
- package/versioning/cleanVersionString.js +1 -7
- package/versioning/cleanVersionString.mjs +7 -0
- package/versioning/index.js +1 -7
- package/versioning/index.mjs +7 -0
- package/versioning/isVersionALessThanB.js +1 -9
- package/versioning/isVersionALessThanB.mjs +9 -0
- package/api/getEndpointWithVersion.cjs +0 -1
- package/api/getUrlAndParams.cjs +0 -1
- package/api/index.cjs +0 -1
- package/color/brighten.cjs +0 -1
- package/color/darken.cjs +0 -1
- package/color/index.cjs +0 -1
- package/color/lighten.cjs +0 -1
- package/index.cjs +0 -1
- package/logger/Logger.cjs +0 -1
- package/logger/index.cjs +0 -1
- package/logger/types.cjs +0 -1
- package/outlet/getListOutletOpeningHoursTable.cjs +0 -1
- package/outlet/index.cjs +0 -1
- package/outlet/types.cjs +0 -1
- package/shared/enums.cjs +0 -1
- package/shared/generateId.cjs +0 -1
- package/shared/index.cjs +0 -1
- package/shared/isWithinFlag.cjs +0 -1
- package/string/index.cjs +0 -1
- package/string/slugify.cjs +0 -1
- package/user/getFullAddressString.cjs +0 -1
- package/user/getFullName.cjs +0 -1
- package/user/index.cjs +0 -1
- package/versioning/cleanVersionString.cjs +0 -1
- package/versioning/index.cjs +0 -1
- package/versioning/isVersionALessThanB.cjs +0 -1
package/api/getUrlAndParams.js
CHANGED
|
@@ -1,23 +1 @@
|
|
|
1
|
-
const
|
|
2
|
-
function a(o, e) {
|
|
3
|
-
const s = { url: o, params: e ?? {} };
|
|
4
|
-
if (!e)
|
|
5
|
-
return s;
|
|
6
|
-
const t = o.match(f);
|
|
7
|
-
return t != null && t.length ? t.reduce(
|
|
8
|
-
(n, l) => {
|
|
9
|
-
const r = l.replace(g, ""), p = e[r];
|
|
10
|
-
return p ? (delete n.params[r], n.url = n.url.replace(
|
|
11
|
-
new RegExp(l, "g"),
|
|
12
|
-
`/${p}`
|
|
13
|
-
)) : n.params[r] = e[r], n;
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
url: o,
|
|
17
|
-
params: { ...e }
|
|
18
|
-
}
|
|
19
|
-
) : s;
|
|
20
|
-
}
|
|
21
|
-
export {
|
|
22
|
-
a as default
|
|
23
|
-
};
|
|
1
|
+
"use strict";const l=/(\/{.+?})/g,c=/[/{}]/g;function f(s,t){const o={url:s,params:t??{}};if(!t)return o;const n=s.match(l);return n!=null&&n.length?n.reduce((e,p)=>{const r=p.replace(c,""),g=t[r];return g?(delete e.params[r],e.url=e.url.replace(new RegExp(p,"g"),`/${g}`)):e.params[r]=t[r],e},{url:s,params:{...t}}):o}module.exports=f;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const f = /(\/{.+?})/g, g = /[/{}]/g;
|
|
2
|
+
function a(o, e) {
|
|
3
|
+
const s = { url: o, params: e ?? {} };
|
|
4
|
+
if (!e)
|
|
5
|
+
return s;
|
|
6
|
+
const t = o.match(f);
|
|
7
|
+
return t != null && t.length ? t.reduce(
|
|
8
|
+
(n, l) => {
|
|
9
|
+
const r = l.replace(g, ""), p = e[r];
|
|
10
|
+
return p ? (delete n.params[r], n.url = n.url.replace(
|
|
11
|
+
new RegExp(l, "g"),
|
|
12
|
+
`/${p}`
|
|
13
|
+
)) : n.params[r] = e[r], n;
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
url: o,
|
|
17
|
+
params: { ...e }
|
|
18
|
+
}
|
|
19
|
+
) : s;
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
a as default
|
|
23
|
+
};
|
package/api/index.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { default as o } from "./getEndpointWithVersion.js";
|
|
3
|
-
export {
|
|
4
|
-
o as getEndpointWithVersion,
|
|
5
|
-
r as getUrlAndParams
|
|
6
|
-
};
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./getUrlAndParams.js"),t=require("./getEndpointWithVersion.js");exports.getUrlAndParams=e;exports.getEndpointWithVersion=t;
|
package/api/index.mjs
ADDED
package/color/brighten.js
CHANGED
package/color/darken.js
CHANGED
package/color/darken.mjs
ADDED
package/color/index.js
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { default as f } from "./brighten.js";
|
|
3
|
-
import { default as l } from "./darken.js";
|
|
4
|
-
import "tinycolor2";
|
|
5
|
-
export {
|
|
6
|
-
f as brighten,
|
|
7
|
-
l as darken,
|
|
8
|
-
a as lighten
|
|
9
|
-
};
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./lighten.js"),r=require("./brighten.js"),o=require("./darken.js");require("tinycolor2");exports.lighten=e;exports.brighten=r;exports.darken=o;
|
package/color/index.mjs
ADDED
package/color/lighten.js
CHANGED
package/index.js
CHANGED
|
@@ -1,40 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { default as d } from "./shared/isWithinFlag.js";
|
|
3
|
-
import { default as n } from "./shared/generateId.js";
|
|
4
|
-
import { default as g } from "./outlet/getListOutletOpeningHoursTable.js";
|
|
5
|
-
import { default as h } from "./versioning/isVersionALessThanB.js";
|
|
6
|
-
import { default as F } from "./versioning/cleanVersionString.js";
|
|
7
|
-
import { default as v } from "./api/getUrlAndParams.js";
|
|
8
|
-
import { default as A } from "./api/getEndpointWithVersion.js";
|
|
9
|
-
import { default as S } from "./string/slugify.js";
|
|
10
|
-
import { default as V } from "./color/lighten.js";
|
|
11
|
-
import { default as b } from "./color/brighten.js";
|
|
12
|
-
import { default as c } from "./color/darken.js";
|
|
13
|
-
import { getFullName as D } from "./user/getFullName.js";
|
|
14
|
-
import { getFullAddressString as H } from "./user/getFullAddressString.js";
|
|
15
|
-
import { default as P } from "./logger/Logger.js";
|
|
16
|
-
import { LogLevel as j } from "./logger/types.js";
|
|
17
|
-
import "moment";
|
|
18
|
-
import "compare-versions";
|
|
19
|
-
import "tinycolor2";
|
|
20
|
-
export {
|
|
21
|
-
f as DayOfWeek,
|
|
22
|
-
l as IntervalState,
|
|
23
|
-
s as IntervalType,
|
|
24
|
-
j as LogLevel,
|
|
25
|
-
P as Logger,
|
|
26
|
-
m as OrderFormat,
|
|
27
|
-
b as brighten,
|
|
28
|
-
F as cleanVersionString,
|
|
29
|
-
c as darken,
|
|
30
|
-
n as generateId,
|
|
31
|
-
A as getEndpointWithVersion,
|
|
32
|
-
H as getFullAddressString,
|
|
33
|
-
D as getFullName,
|
|
34
|
-
g as getListOutletOpeningHoursTable,
|
|
35
|
-
v as getUrlAndParams,
|
|
36
|
-
h as isVersionALessThanB,
|
|
37
|
-
d as isWithinFlag,
|
|
38
|
-
V as lighten,
|
|
39
|
-
S as slugify
|
|
40
|
-
};
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./shared/enums.js"),r=require("./shared/isWithinFlag.js"),t=require("./shared/generateId.js"),n=require("./outlet/getListOutletOpeningHoursTable.js"),i=require("./versioning/isVersionALessThanB.js"),s=require("./versioning/cleanVersionString.js"),o=require("./api/getUrlAndParams.js"),g=require("./api/getEndpointWithVersion.js"),l=require("./string/slugify.js"),u=require("./color/lighten.js"),a=require("./color/brighten.js"),c=require("./color/darken.js"),d=require("./user/getFullName.js"),q=require("./user/getFullAddressString.js"),_=require("./logger/Logger.js"),h=require("./logger/types.js");require("moment");require("compare-versions");require("tinycolor2");exports.DayOfWeek=e.DayOfWeek;exports.IntervalState=e.IntervalState;exports.IntervalType=e.IntervalType;exports.OrderFormat=e.OrderFormat;exports.isWithinFlag=r;exports.generateId=t;exports.getListOutletOpeningHoursTable=n;exports.isVersionALessThanB=i;exports.cleanVersionString=s;exports.getUrlAndParams=o;exports.getEndpointWithVersion=g;exports.slugify=l;exports.lighten=u;exports.brighten=a;exports.darken=c;exports.getFullName=d.getFullName;exports.getFullAddressString=q.getFullAddressString;exports.Logger=_;exports.LogLevel=h.LogLevel;
|
package/index.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DayOfWeek as f, IntervalState as l, IntervalType as s, OrderFormat as m } from "./shared/enums.mjs";
|
|
2
|
+
import { default as d } from "./shared/isWithinFlag.mjs";
|
|
3
|
+
import { default as n } from "./shared/generateId.mjs";
|
|
4
|
+
import { default as g } from "./outlet/getListOutletOpeningHoursTable.mjs";
|
|
5
|
+
import { default as h } from "./versioning/isVersionALessThanB.mjs";
|
|
6
|
+
import { default as F } from "./versioning/cleanVersionString.mjs";
|
|
7
|
+
import { default as v } from "./api/getUrlAndParams.mjs";
|
|
8
|
+
import { default as A } from "./api/getEndpointWithVersion.mjs";
|
|
9
|
+
import { default as S } from "./string/slugify.mjs";
|
|
10
|
+
import { default as V } from "./color/lighten.mjs";
|
|
11
|
+
import { default as b } from "./color/brighten.mjs";
|
|
12
|
+
import { default as c } from "./color/darken.mjs";
|
|
13
|
+
import { getFullName as D } from "./user/getFullName.mjs";
|
|
14
|
+
import { getFullAddressString as H } from "./user/getFullAddressString.mjs";
|
|
15
|
+
import { default as P } from "./logger/Logger.mjs";
|
|
16
|
+
import { LogLevel as j } from "./logger/types.mjs";
|
|
17
|
+
import "moment";
|
|
18
|
+
import "compare-versions";
|
|
19
|
+
import "tinycolor2";
|
|
20
|
+
export {
|
|
21
|
+
f as DayOfWeek,
|
|
22
|
+
l as IntervalState,
|
|
23
|
+
s as IntervalType,
|
|
24
|
+
j as LogLevel,
|
|
25
|
+
P as Logger,
|
|
26
|
+
m as OrderFormat,
|
|
27
|
+
b as brighten,
|
|
28
|
+
F as cleanVersionString,
|
|
29
|
+
c as darken,
|
|
30
|
+
n as generateId,
|
|
31
|
+
A as getEndpointWithVersion,
|
|
32
|
+
H as getFullAddressString,
|
|
33
|
+
D as getFullName,
|
|
34
|
+
g as getListOutletOpeningHoursTable,
|
|
35
|
+
v as getUrlAndParams,
|
|
36
|
+
h as isVersionALessThanB,
|
|
37
|
+
d as isWithinFlag,
|
|
38
|
+
V as lighten,
|
|
39
|
+
S as slugify
|
|
40
|
+
};
|
package/logger/Logger.js
CHANGED
|
@@ -1,30 +1 @@
|
|
|
1
|
-
|
|
2
|
-
class a {
|
|
3
|
-
constructor(t) {
|
|
4
|
-
this.logStrategy = t;
|
|
5
|
-
}
|
|
6
|
-
setLogStrategy(t) {
|
|
7
|
-
this.logStrategy = t;
|
|
8
|
-
}
|
|
9
|
-
verbose(t, e) {
|
|
10
|
-
this.logStrategy.execute(r.Verbose, t, e);
|
|
11
|
-
}
|
|
12
|
-
debug(t, e) {
|
|
13
|
-
this.logStrategy.execute(r.Debug, t, e);
|
|
14
|
-
}
|
|
15
|
-
info(t, e) {
|
|
16
|
-
this.logStrategy.execute(r.Information, t, e);
|
|
17
|
-
}
|
|
18
|
-
warn(t, e) {
|
|
19
|
-
this.logStrategy.execute(r.Warning, t, e);
|
|
20
|
-
}
|
|
21
|
-
error(t, e) {
|
|
22
|
-
this.logStrategy.execute(r.Error, t, e);
|
|
23
|
-
}
|
|
24
|
-
fatal(t, e) {
|
|
25
|
-
this.logStrategy.execute(r.Fatal, t, e);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export {
|
|
29
|
-
a as default
|
|
30
|
-
};
|
|
1
|
+
"use strict";const g=require("./types.js");class o{constructor(e){this.logStrategy=e}setLogStrategy(e){this.logStrategy=e}verbose(e,t){this.logStrategy.execute(g.LogLevel.Verbose,e,t)}debug(e,t){this.logStrategy.execute(g.LogLevel.Debug,e,t)}info(e,t){this.logStrategy.execute(g.LogLevel.Information,e,t)}warn(e,t){this.logStrategy.execute(g.LogLevel.Warning,e,t)}error(e,t){this.logStrategy.execute(g.LogLevel.Error,e,t)}fatal(e,t){this.logStrategy.execute(g.LogLevel.Fatal,e,t)}}module.exports=o;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { LogLevel as r } from "./types.mjs";
|
|
2
|
+
class a {
|
|
3
|
+
constructor(t) {
|
|
4
|
+
this.logStrategy = t;
|
|
5
|
+
}
|
|
6
|
+
setLogStrategy(t) {
|
|
7
|
+
this.logStrategy = t;
|
|
8
|
+
}
|
|
9
|
+
verbose(t, e) {
|
|
10
|
+
this.logStrategy.execute(r.Verbose, t, e);
|
|
11
|
+
}
|
|
12
|
+
debug(t, e) {
|
|
13
|
+
this.logStrategy.execute(r.Debug, t, e);
|
|
14
|
+
}
|
|
15
|
+
info(t, e) {
|
|
16
|
+
this.logStrategy.execute(r.Information, t, e);
|
|
17
|
+
}
|
|
18
|
+
warn(t, e) {
|
|
19
|
+
this.logStrategy.execute(r.Warning, t, e);
|
|
20
|
+
}
|
|
21
|
+
error(t, e) {
|
|
22
|
+
this.logStrategy.execute(r.Error, t, e);
|
|
23
|
+
}
|
|
24
|
+
fatal(t, e) {
|
|
25
|
+
this.logStrategy.execute(r.Fatal, t, e);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
a as default
|
|
30
|
+
};
|
package/logger/index.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { LogLevel as g } from "./types.js";
|
|
3
|
-
export {
|
|
4
|
-
g as LogLevel,
|
|
5
|
-
r as Logger
|
|
6
|
-
};
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./Logger.js"),g=require("./types.js");exports.Logger=e;exports.LogLevel=g.LogLevel;
|
package/logger/index.mjs
ADDED
package/logger/types.js
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
var a
|
|
2
|
-
export {
|
|
3
|
-
a as LogLevel
|
|
4
|
-
};
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var a=(r=>(r[r.Verbose=0]="Verbose",r[r.Debug=1]="Debug",r[r.Information=2]="Information",r[r.Warning=3]="Warning",r[r.Error=4]="Error",r[r.Fatal=5]="Fatal",r))(a||{});exports.LogLevel=a;
|
package/logger/types.mjs
ADDED
|
@@ -1,172 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { OrderFormat as p, DayOfWeek as m, IntervalType as y, IntervalState as O } from "../shared/enums.js";
|
|
3
|
-
import h from "../shared/isWithinFlag.js";
|
|
4
|
-
import W from "../shared/generateId.js";
|
|
5
|
-
const k = [
|
|
6
|
-
{ id: p.EatIn, name: "eatIn" },
|
|
7
|
-
{ id: p.Takeaway, name: "takeaway" },
|
|
8
|
-
{ id: p.TableOrder, name: "tableOrder" },
|
|
9
|
-
{ id: p.Delivery, name: "delivery" }
|
|
10
|
-
];
|
|
11
|
-
function M(e) {
|
|
12
|
-
const r = F.utc(e).subtract(1, "day").startOf("day"), t = [];
|
|
13
|
-
for (let a = 0, o = r; a < 7; a += 1)
|
|
14
|
-
o = o.clone().add(1, "day").startOf("day"), t.push(o.clone());
|
|
15
|
-
return t;
|
|
16
|
-
}
|
|
17
|
-
function v(e) {
|
|
18
|
-
return [...e].sort((r, t) => r.isoWeekday() - t.isoWeekday());
|
|
19
|
-
}
|
|
20
|
-
function S(e) {
|
|
21
|
-
return e.split(":").map(Number);
|
|
22
|
-
}
|
|
23
|
-
function H(e, r) {
|
|
24
|
-
const [t, a] = S(e.start), [o, s] = S(
|
|
25
|
-
e.duration
|
|
26
|
-
);
|
|
27
|
-
if (e.type === y.Interval) {
|
|
28
|
-
const n = r.clone().add(t, "hour").add(a, "minute"), i = n.clone().add(o, "hour").add(s, "minute");
|
|
29
|
-
return {
|
|
30
|
-
id: e.id,
|
|
31
|
-
start: n.toISOString(),
|
|
32
|
-
end: i.toISOString()
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
if (e.type === y.Exception) {
|
|
36
|
-
const n = F(e.fromDate), i = F(e.toDate);
|
|
37
|
-
if (r.isBetween(n, i, void 0, "[]")) {
|
|
38
|
-
const I = r.clone().add(t, "hour").add(a, "minute"), u = I.clone().add(o, "hour").add(s, "minute");
|
|
39
|
-
return {
|
|
40
|
-
id: e.id,
|
|
41
|
-
start: I.toISOString(),
|
|
42
|
-
end: u.toISOString(),
|
|
43
|
-
reason: e.reason
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
throw new Error("Invalid interval type");
|
|
49
|
-
}
|
|
50
|
-
function E(e, r, t) {
|
|
51
|
-
const a = {
|
|
52
|
-
[m.Monday]: 1,
|
|
53
|
-
[m.Tuesday]: 2,
|
|
54
|
-
[m.Wednesday]: 3,
|
|
55
|
-
[m.Thursday]: 4,
|
|
56
|
-
[m.Friday]: 5,
|
|
57
|
-
[m.Saturday]: 6,
|
|
58
|
-
[m.Sunday]: 7
|
|
59
|
-
};
|
|
60
|
-
for (let o = 0; o < r.length; o += 1) {
|
|
61
|
-
const s = r[o], n = s.isoWeekday(), i = e.dayOfWeek, u = (a[i] ?? null) === n || i === m.Everyday;
|
|
62
|
-
if (t[n] || (t[n] = {
|
|
63
|
-
isoWeekday: n,
|
|
64
|
-
key: "",
|
|
65
|
-
open: [],
|
|
66
|
-
adjusted: [],
|
|
67
|
-
closed: []
|
|
68
|
-
}), u) {
|
|
69
|
-
const d = H(e, s);
|
|
70
|
-
d && (t[n].key += d.id, e.type === y.Interval && e.state === O.Open ? t[n].open.push(d) : e.type === y.Interval && e.state === O.Closed ? t[n].closed.push(d) : e.type === y.Exception && e.state === O.Open ? t[n].adjusted.push(d) : e.type === y.Exception && e.state === O.Closed && t[n].closed.push(d));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
function T(e) {
|
|
75
|
-
switch (e.type) {
|
|
76
|
-
case y.Exception:
|
|
77
|
-
return W("interval-exception");
|
|
78
|
-
case y.Interval:
|
|
79
|
-
return W("interval-normal");
|
|
80
|
-
default:
|
|
81
|
-
return W("interval-unknown");
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
function x(e) {
|
|
85
|
-
const r = e.reduce(
|
|
86
|
-
(t, a) => (k.forEach((o) => {
|
|
87
|
-
h(o.id, a.orderFormats) && (t[o.id] || (t[o.id] = {
|
|
88
|
-
orderFormat: o,
|
|
89
|
-
intervals: []
|
|
90
|
-
}), t[o.id].intervals.push(
|
|
91
|
-
...a.intervals.sort(
|
|
92
|
-
(s, n) => s.dayOfWeek - n.dayOfWeek
|
|
93
|
-
)
|
|
94
|
-
));
|
|
95
|
-
}), t),
|
|
96
|
-
{}
|
|
97
|
-
);
|
|
98
|
-
return Object.values(r);
|
|
99
|
-
}
|
|
100
|
-
function j(e) {
|
|
101
|
-
return e.reduce(
|
|
102
|
-
(r, t, a) => {
|
|
103
|
-
const o = r.findIndex(
|
|
104
|
-
(s) => s !== t && !s.orderFormats.some(
|
|
105
|
-
(n) => t.orderFormats.some(
|
|
106
|
-
(i) => i.id === n.id
|
|
107
|
-
)
|
|
108
|
-
) && s.openingHours.every(
|
|
109
|
-
(n) => t.openingHours.some((i) => i.key === n.key)
|
|
110
|
-
) && t.openingHours.every(
|
|
111
|
-
(n) => s.openingHours.some((i) => i.key === n.key)
|
|
112
|
-
)
|
|
113
|
-
);
|
|
114
|
-
if (o >= 0) {
|
|
115
|
-
const s = r[o];
|
|
116
|
-
return r.splice(o, 1, {
|
|
117
|
-
...s,
|
|
118
|
-
orderFormats: [...t.orderFormats, ...s.orderFormats]
|
|
119
|
-
}), r.splice(a, 1), r;
|
|
120
|
-
}
|
|
121
|
-
return r;
|
|
122
|
-
},
|
|
123
|
-
[...e]
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
function w(e) {
|
|
127
|
-
return e.map((r) => ({
|
|
128
|
-
...r,
|
|
129
|
-
intervals: r.intervals.map((t) => ({
|
|
130
|
-
...t,
|
|
131
|
-
id: T(t)
|
|
132
|
-
}))
|
|
133
|
-
}));
|
|
134
|
-
}
|
|
135
|
-
function A(e, r) {
|
|
136
|
-
const t = x(
|
|
137
|
-
w(e.serviceDateTimes)
|
|
138
|
-
), a = M(r), o = v(a), s = t.reduce(
|
|
139
|
-
(u, d) => (u[d.orderFormat.id] || (u[d.orderFormat.id] = {}), d.intervals.reduce((g, f) => (E(f, o, g), g), u[d.orderFormat.id]), u),
|
|
140
|
-
{}
|
|
141
|
-
), n = {
|
|
142
|
-
[p.EatIn]: k[0],
|
|
143
|
-
[p.Takeaway]: k[1],
|
|
144
|
-
[p.TableOrder]: k[2],
|
|
145
|
-
[p.Delivery]: k[3]
|
|
146
|
-
}, i = Object.entries(
|
|
147
|
-
s
|
|
148
|
-
).map(([u, d]) => ({
|
|
149
|
-
orderFormats: [n[Number(u)]],
|
|
150
|
-
openingHours: Object.entries(d).map(
|
|
151
|
-
([g, f]) => ({
|
|
152
|
-
isoWeekday: Number(g),
|
|
153
|
-
key: f.key,
|
|
154
|
-
open: f.open.sort(
|
|
155
|
-
(c, l) => c.start.localeCompare(l.start)
|
|
156
|
-
),
|
|
157
|
-
adjusted: f.adjusted.sort(
|
|
158
|
-
(c, l) => c.start.localeCompare(l.start)
|
|
159
|
-
),
|
|
160
|
-
closed: f.closed.sort(
|
|
161
|
-
(c, l) => c.start.localeCompare(l.start)
|
|
162
|
-
)
|
|
163
|
-
})
|
|
164
|
-
)
|
|
165
|
-
}));
|
|
166
|
-
return j(i).sort(
|
|
167
|
-
(u, d) => u.orderFormats[0].id - d.orderFormats[0].id
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
export {
|
|
171
|
-
A as default
|
|
172
|
-
};
|
|
1
|
+
"use strict";const k=require("moment"),r=require("../shared/enums.js"),g=require("../shared/isWithinFlag.js"),I=require("../shared/generateId.js"),l=[{id:r.OrderFormat.EatIn,name:"eatIn"},{id:r.OrderFormat.Takeaway,name:"takeaway"},{id:r.OrderFormat.TableOrder,name:"tableOrder"},{id:r.OrderFormat.Delivery,name:"delivery"}];function F(e){const n=k.utc(e).subtract(1,"day").startOf("day"),t=[];for(let i=0,s=n;i<7;i+=1)s=s.clone().add(1,"day").startOf("day"),t.push(s.clone());return t}function v(e){return[...e].sort((n,t)=>n.isoWeekday()-t.isoWeekday())}function W(e){return e.split(":").map(Number)}function S(e,n){const[t,i]=W(e.start),[s,a]=W(e.duration);if(e.type===r.IntervalType.Interval){const o=n.clone().add(t,"hour").add(i,"minute"),u=o.clone().add(s,"hour").add(a,"minute");return{id:e.id,start:o.toISOString(),end:u.toISOString()}}if(e.type===r.IntervalType.Exception){const o=k(e.fromDate),u=k(e.toDate);if(n.isBetween(o,u,void 0,"[]")){const c=n.clone().add(t,"hour").add(i,"minute"),y=c.clone().add(s,"hour").add(a,"minute");return{id:e.id,start:c.toISOString(),end:y.toISOString(),reason:e.reason}}return null}throw new Error("Invalid interval type")}function h(e,n,t){const i={[r.DayOfWeek.Monday]:1,[r.DayOfWeek.Tuesday]:2,[r.DayOfWeek.Wednesday]:3,[r.DayOfWeek.Thursday]:4,[r.DayOfWeek.Friday]:5,[r.DayOfWeek.Saturday]:6,[r.DayOfWeek.Sunday]:7};for(let s=0;s<n.length;s+=1){const a=n[s],o=a.isoWeekday(),u=e.dayOfWeek,y=(i[u]??null)===o||u===r.DayOfWeek.Everyday;if(t[o]||(t[o]={isoWeekday:o,key:"",open:[],adjusted:[],closed:[]}),y){const d=S(e,a);d&&(t[o].key+=d.id,e.type===r.IntervalType.Interval&&e.state===r.IntervalState.Open?t[o].open.push(d):e.type===r.IntervalType.Interval&&e.state===r.IntervalState.Closed?t[o].closed.push(d):e.type===r.IntervalType.Exception&&e.state===r.IntervalState.Open?t[o].adjusted.push(d):e.type===r.IntervalType.Exception&&e.state===r.IntervalState.Closed&&t[o].closed.push(d))}}}function T(e){switch(e.type){case r.IntervalType.Exception:return I("interval-exception");case r.IntervalType.Interval:return I("interval-normal");default:return I("interval-unknown")}}function D(e){const n=e.reduce((t,i)=>(l.forEach(s=>{g(s.id,i.orderFormats)&&(t[s.id]||(t[s.id]={orderFormat:s,intervals:[]}),t[s.id].intervals.push(...i.intervals.sort((a,o)=>a.dayOfWeek-o.dayOfWeek)))}),t),{});return Object.values(n)}function M(e){return e.reduce((n,t,i)=>{const s=n.findIndex(a=>a!==t&&!a.orderFormats.some(o=>t.orderFormats.some(u=>u.id===o.id))&&a.openingHours.every(o=>t.openingHours.some(u=>u.key===o.key))&&t.openingHours.every(o=>a.openingHours.some(u=>u.key===o.key)));if(s>=0){const a=n[s];return n.splice(s,1,{...a,orderFormats:[...t.orderFormats,...a.orderFormats]}),n.splice(i,1),n}return n},[...e])}function H(e){return e.map(n=>({...n,intervals:n.intervals.map(t=>({...t,id:T(t)}))}))}function E(e,n){const t=D(H(e.serviceDateTimes)),i=F(n),s=v(i),a=t.reduce((y,d)=>(y[d.orderFormat.id]||(y[d.orderFormat.id]={}),d.intervals.reduce((O,p)=>(h(p,s,O),O),y[d.orderFormat.id]),y),{}),o={[r.OrderFormat.EatIn]:l[0],[r.OrderFormat.Takeaway]:l[1],[r.OrderFormat.TableOrder]:l[2],[r.OrderFormat.Delivery]:l[3]},u=Object.entries(a).map(([y,d])=>({orderFormats:[o[Number(y)]],openingHours:Object.entries(d).map(([O,p])=>({isoWeekday:Number(O),key:p.key,open:p.open.sort((m,f)=>m.start.localeCompare(f.start)),adjusted:p.adjusted.sort((m,f)=>m.start.localeCompare(f.start)),closed:p.closed.sort((m,f)=>m.start.localeCompare(f.start))}))}));return M(u).sort((y,d)=>y.orderFormats[0].id-d.orderFormats[0].id)}module.exports=E;
|