ismx-nexo-node-app 0.4.137 → 0.4.139

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.
@@ -91,6 +91,33 @@ class DateUtils {
91
91
  };
92
92
  return recursivelyRevive(obj);
93
93
  }
94
+ static split(span, from, to) {
95
+ const dates = [];
96
+ const current = new Date(from);
97
+ switch (span) {
98
+ case 'day':
99
+ while (current <= to) {
100
+ dates.push(new Date(current));
101
+ current.setDate(current.getDate() + 1);
102
+ }
103
+ break;
104
+ case 'month':
105
+ current.setDate(1);
106
+ while (current <= to) {
107
+ dates.push(new Date(current.getFullYear(), current.getMonth(), 1));
108
+ current.setMonth(current.getMonth() + 1);
109
+ }
110
+ break;
111
+ case 'year':
112
+ current.setMonth(0, 1);
113
+ while (current <= to) {
114
+ dates.push(new Date(current.getFullYear(), 0, 1));
115
+ current.setFullYear(current.getFullYear() + 1);
116
+ }
117
+ break;
118
+ }
119
+ return dates;
120
+ }
94
121
  }
95
122
  DateUtils.MILLIS = 1;
96
123
  DateUtils.SECONDS = 1000 * DateUtils.MILLIS;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class ObjectUtils {
4
+ static snakeToCamel(obj) {
5
+ if (typeof obj === 'string')
6
+ return obj.toLowerCase().replace(/([-_][a-z])/g, group => group.toUpperCase().replace('-', '').replace('_', ''));
7
+ if (Array.isArray(obj))
8
+ return obj.map(el => ObjectUtils.snakeToCamel(el));
9
+ if (typeof obj === 'function' || obj !== Object(obj) || obj instanceof Date)
10
+ return obj;
11
+ return ObjectUtils.fromEntries(Object.entries(obj).map(([key, value]) => [
12
+ ObjectUtils.snakeToCamel(key), value,
13
+ ]));
14
+ }
15
+ static fromEntries(iterable) {
16
+ const result = {};
17
+ for (const [key, value] of iterable)
18
+ result[key] = value;
19
+ return result;
20
+ }
21
+ }
22
+ exports.default = ObjectUtils;
@@ -17,4 +17,5 @@ export default abstract class DateUtils {
17
17
  static isIsoDate(value: string): boolean;
18
18
  static reviveDate(value: string): string | Date;
19
19
  static reviveDates<T>(obj: T): T;
20
+ static split(span: 'year' | 'month' | 'day', from: Date, to: Date): Date[];
20
21
  }
@@ -0,0 +1,6 @@
1
+ export default class ObjectUtils {
2
+ static snakeToCamel(obj: any): any;
3
+ static fromEntries(iterable: [string, any][]): {
4
+ [key: string]: any;
5
+ };
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.137",
3
+ "version": "0.4.139",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -124,5 +124,4 @@ export default abstract class ArrayUtils {
124
124
  static sorted<T>(array: T[], compareFn?: (a: T, b: T) => number): T[] {
125
125
  return [ ...array ].sort(compareFn);
126
126
  }
127
-
128
127
  }
@@ -115,4 +115,37 @@ export default abstract class DateUtils {
115
115
 
116
116
  return recursivelyRevive(obj);
117
117
  }
118
+
119
+ static split(span: 'year' | 'month' | 'day', from: Date, to: Date): Date[]
120
+ {
121
+ const dates: Date[] = [];
122
+ const current = new Date(from);
123
+
124
+ switch (span) {
125
+ case 'day':
126
+ while (current <= to) {
127
+ dates.push(new Date(current));
128
+ current.setDate(current.getDate() + 1);
129
+ }
130
+ break;
131
+
132
+ case 'month':
133
+ current.setDate(1);
134
+ while (current <= to) {
135
+ dates.push(new Date(current.getFullYear(), current.getMonth(), 1));
136
+ current.setMonth(current.getMonth() + 1);
137
+ }
138
+ break;
139
+
140
+ case 'year':
141
+ current.setMonth(0, 1);
142
+ while (current <= to) {
143
+ dates.push(new Date(current.getFullYear(), 0, 1));
144
+ current.setFullYear(current.getFullYear() + 1);
145
+ }
146
+ break;
147
+ }
148
+
149
+ return dates;
150
+ }
118
151
  }
@@ -0,0 +1,28 @@
1
+ export default class ObjectUtils {
2
+
3
+ static snakeToCamel(obj: any): any {
4
+ if (typeof obj === 'string')
5
+ return obj.toLowerCase().replace(/([-_][a-z])/g, group =>
6
+ group.toUpperCase().replace('-', '').replace('_', '')
7
+ );
8
+
9
+ if (Array.isArray(obj))
10
+ return obj.map(el => ObjectUtils.snakeToCamel(el));
11
+
12
+ if (typeof obj === 'function' || obj !== Object(obj) || obj instanceof Date)
13
+ return obj;
14
+
15
+ return ObjectUtils.fromEntries(
16
+ Object.entries(obj).map(([key, value]) => [
17
+ ObjectUtils.snakeToCamel(key), value,
18
+ ]),
19
+ );
20
+ }
21
+
22
+ static fromEntries(iterable: [string,any][]): {[key:string]:any} {
23
+ const result: {[key:string]:any} = {};
24
+ for (const [key, value] of iterable)
25
+ result[key] = value;
26
+ return result;
27
+ }
28
+ }