mblabs-roccato-backend-commons 1.0.40 → 1.0.42

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.
@@ -11,7 +11,7 @@ declare class DateService {
11
11
  minusHours(start: Date, toRemove: number): Date;
12
12
  minusMinutes(start: Date, toRemove: number): Date;
13
13
  isValidDate(inp: string, format?: string): boolean;
14
- getStartAndEndOfDay(inp: string): {
14
+ getStartAndEndOfDay(inp?: Date | string, useUTC?: boolean): {
15
15
  startOfDay: Date;
16
16
  endOfDay: Date;
17
17
  };
@@ -51,11 +51,26 @@ class DateService {
51
51
  isValidDate(inp, format = 'yyyy-MM-dd') {
52
52
  return luxon_1.DateTime.fromFormat(inp, format).isValid;
53
53
  }
54
- getStartAndEndOfDay(inp) {
55
- const date = luxon_1.DateTime.fromISO(inp);
56
- const startOfDay = date.startOf('day').toJSDate();
57
- const endOfDay = date.endOf('day').toJSDate();
58
- return { startOfDay, endOfDay };
54
+ getStartAndEndOfDay(inp = this.getCurrentDate(), useUTC = false) {
55
+ const date = inp instanceof Date
56
+ ? luxon_1.DateTime.fromJSDate(inp)
57
+ : luxon_1.DateTime.fromISO(inp);
58
+ if (!date.isValid) {
59
+ return {
60
+ startOfDay: luxon_1.DateTime.local().startOf('day').toJSDate(),
61
+ endOfDay: luxon_1.DateTime.local().endOf('day').toJSDate(),
62
+ };
63
+ }
64
+ if (useUTC) {
65
+ return {
66
+ startOfDay: date.toUTC().startOf('day').toJSDate(),
67
+ endOfDay: date.toUTC().endOf('day').toJSDate(),
68
+ };
69
+ }
70
+ return {
71
+ startOfDay: date.startOf('day').toJSDate(),
72
+ endOfDay: date.endOf('day').toJSDate(),
73
+ };
59
74
  }
60
75
  getStartOfDay(inp, format = constants_1.DATE.SYSTEM.FULL_DATETIME) {
61
76
  const date = luxon_1.DateTime.fromISO(inp);
@@ -1,6 +1,6 @@
1
1
  declare class FileService {
2
2
  readTemplate(path: string, encoding: string): Promise<unknown>;
3
- fillTemplate(template: any, replacements: Record<string, string | number | boolean>): any;
3
+ fillTemplate(template: string, replacements: Record<string, string | number | boolean>, placeholderPattern?: (key: string) => RegExp): string;
4
4
  getBase64Metadata(file: string): {
5
5
  buffer: Buffer<ArrayBuffer>;
6
6
  extension: string;
@@ -17,10 +17,10 @@ class FileService {
17
17
  });
18
18
  return promise;
19
19
  }
20
- fillTemplate(template, replacements) {
20
+ fillTemplate(template, replacements, placeholderPattern = (key) => new RegExp(`\\{${key}\\}`, 'g')) {
21
21
  Object.keys(replacements).forEach((replacement) => {
22
- const value = replacements[replacement] ? replacements[replacement] : '';
23
- template = template.replace(new RegExp(`\\{${replacement}\\}`, 'g'), value);
22
+ const value = replacements[replacement] ?? '';
23
+ template = template.replace(placeholderPattern(replacement), String(value));
24
24
  });
25
25
  return template;
26
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mblabs-roccato-backend-commons",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -66,11 +66,32 @@ class DateService {
66
66
  return DateTime.fromFormat(inp, format).isValid;
67
67
  }
68
68
 
69
- public getStartAndEndOfDay (inp: string) {
70
- const date = DateTime.fromISO(inp);
71
- const startOfDay = date.startOf('day').toJSDate();
72
- const endOfDay = date.endOf('day').toJSDate();
73
- return { startOfDay, endOfDay };
69
+ public getStartAndEndOfDay (
70
+ inp: Date | string = this.getCurrentDate(),
71
+ useUTC = false
72
+ ) {
73
+ const date = inp instanceof Date
74
+ ? DateTime.fromJSDate(inp)
75
+ : DateTime.fromISO(inp);
76
+
77
+ if (!date.isValid) {
78
+ return {
79
+ startOfDay: DateTime.local().startOf('day').toJSDate(),
80
+ endOfDay: DateTime.local().endOf('day').toJSDate(),
81
+ };
82
+ }
83
+
84
+ if (useUTC) {
85
+ return {
86
+ startOfDay: date.toUTC().startOf('day').toJSDate(),
87
+ endOfDay: date.toUTC().endOf('day').toJSDate(),
88
+ };
89
+ }
90
+
91
+ return {
92
+ startOfDay: date.startOf('day').toJSDate(),
93
+ endOfDay: date.endOf('day').toJSDate(),
94
+ };
74
95
  }
75
96
 
76
97
  public getStartOfDay (inp: string, format = DATE.SYSTEM.FULL_DATETIME): string {
@@ -17,12 +17,15 @@ class FileService {
17
17
  return promise;
18
18
  }
19
19
 
20
- public fillTemplate (template: any, replacements: Record<string, string | number | boolean>) {
20
+ public fillTemplate (
21
+ template: string,
22
+ replacements: Record<string, string | number | boolean>,
23
+ placeholderPattern: (key: string) => RegExp = (key) => new RegExp(`\\{${key}\\}`, 'g')
24
+ ): string {
21
25
 
22
26
  Object.keys(replacements).forEach((replacement) => {
23
- const value = replacements[replacement] ? replacements[replacement] : '';
24
-
25
- template = template.replace(new RegExp(`\\{${replacement}\\}`, 'g'), value);
27
+ const value = replacements[replacement] ?? '';
28
+ template = template.replace(placeholderPattern(replacement), String(value));
26
29
  });
27
30
 
28
31
  return template;