@futdevpro/fsm-dynamo 1.9.9 → 1.9.12
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/.github/workflows/main.yml +196 -0
- package/HOWTO.md +15 -15
- package/README.md +17 -17
- package/build/_collections/constants/country-divisions.const.d.ts +1 -1
- package/build/_collections/constants/country-divisions.const.d.ts.map +1 -1
- package/build/_collections/constants/country-divisions.const.js +2 -2
- package/build/_collections/constants/country-divisions.const.js.map +1 -1
- package/build/_collections/constants/courtry-isos.const.d.ts +1 -1
- package/build/_collections/constants/courtry-isos.const.d.ts.map +1 -1
- package/build/_collections/constants/courtry-isos.const.js +2 -2
- package/build/_collections/constants/courtry-isos.const.js.map +1 -1
- package/build/_collections/constants/error-defaults.const.d.ts +1 -1
- package/build/_collections/constants/error-defaults.const.d.ts.map +1 -1
- package/build/_collections/constants/module-settings/usage-module-settings.const.js +1 -1
- package/build/_collections/constants/pipe-transforms.const.js +12 -12
- package/build/_collections/constants/pipe-transforms.const.js.map +1 -1
- package/build/_collections/utils/pipe-transforms/division-pipe.util.js +1 -1
- package/build/_collections/utils/pipe-transforms/division-pipe.util.js.map +1 -1
- package/build/_collections/utils/pipe-transforms/list-pipe.util.d.ts.map +1 -1
- package/build/_collections/utils/pipe-transforms/list-pipe.util.js.map +1 -1
- package/build/_collections/utils/pipe-transforms/range-pipe.util.d.ts +2 -2
- package/build/_collections/utils/pipe-transforms/range-pipe.util.d.ts.map +1 -1
- package/build/_collections/utils/pipe-transforms/range-pipe.util.js +11 -11
- package/build/_collections/utils/pipe-transforms/range-pipe.util.js.map +1 -1
- package/build/_collections/utils/regions.util.d.ts.map +1 -1
- package/build/_collections/utils/regions.util.js +3 -0
- package/build/_collections/utils/regions.util.js.map +1 -1
- package/build/_enums/range-pipe-setting.enum.d.ts +1 -1
- package/build/_enums/range-pipe-setting.enum.d.ts.map +1 -1
- package/build/_enums/range-pipe-setting.enum.js +12 -12
- package/build/_enums/range-pipe-setting.enum.js.map +1 -1
- package/build/_models/control-models/error.control-model.js +1 -1
- package/build/_models/control-models/error.control-model.js.map +1 -1
- package/build/_models/control-models/error.control-model.spec.js +25 -6
- package/build/_models/control-models/error.control-model.spec.js.map +1 -1
- package/build/_models/interfaces/index.d.ts +3 -0
- package/build/_models/interfaces/index.d.ts.map +1 -1
- package/build/_models/interfaces/index.js +3 -0
- package/build/_models/interfaces/index.js.map +1 -1
- package/build/_models/interfaces/pipe-transforms.interface.d.ts +2 -2
- package/build/_models/interfaces/pipe-transforms.interface.d.ts.map +1 -1
- package/futdevpro-fsm-dynamo-01.09.12.tgz +0 -0
- package/nodemon.json +11 -11
- package/package.json +151 -151
- package/src/_collections/assets/location/country-codes-ISO-3166.json +3239 -3239
- package/src/_collections/assets/location/country-divisions-ISO-3166-all-list.json +19035 -19035
- package/src/_collections/assets/location/country-divisions-ISO-3166.json +4993 -4993
- package/src/_collections/assets/location/country-phone-codes.json +1203 -1203
- package/src/_collections/constants/country-divisions.const.ts +9 -9
- package/src/_collections/constants/courtry-isos.const.ts +8 -8
- package/src/_collections/constants/error-defaults.const.ts +11 -11
- package/src/_collections/constants/index.ts +15 -15
- package/src/_collections/constants/module-settings/custom-data-module-settings.const.ts +15 -15
- package/src/_collections/constants/module-settings/index.ts +8 -8
- package/src/_collections/constants/module-settings/test-module-settings.const.ts +19 -19
- package/src/_collections/constants/module-settings/usage-module-settings.const.ts +19 -19
- package/src/_collections/constants/pipe-transforms.const.ts +35 -35
- package/src/_collections/constants/times.const.ts +8 -8
- package/src/_collections/index.ts +6 -6
- package/src/_collections/utils/array.util.spec.ts +39 -39
- package/src/_collections/utils/array.util.ts +137 -137
- package/src/_collections/utils/index.ts +18 -18
- package/src/_collections/utils/location.util.ts +55 -55
- package/src/_collections/utils/log.util.ts +239 -239
- package/src/_collections/utils/math/box-bounds.util.ts +85 -85
- package/src/_collections/utils/math/index.ts +5 -5
- package/src/_collections/utils/math/math.util.ts +53 -53
- package/src/_collections/utils/math/random.util.ts +80 -80
- package/src/_collections/utils/math/trigonometry.util.ts +73 -73
- package/src/_collections/utils/math/vector2.util.ts +197 -197
- package/src/_collections/utils/pipe-transforms/country-pipe.util.ts +18 -18
- package/src/_collections/utils/pipe-transforms/custom-pipe.util.ts +9 -9
- package/src/_collections/utils/pipe-transforms/division-pipe.util.ts +20 -20
- package/src/_collections/utils/pipe-transforms/index.ts +15 -15
- package/src/_collections/utils/pipe-transforms/list-pipe.util.ts +10 -14
- package/src/_collections/utils/pipe-transforms/multi-pipe-pipe.util.ts +160 -160
- package/src/_collections/utils/pipe-transforms/obj-key-pipe.util.ts +9 -9
- package/src/_collections/utils/pipe-transforms/range-pipe.util.ts +94 -94
- package/src/_collections/utils/pipe-transforms/region-pipe.util.ts +18 -18
- package/src/_collections/utils/pipe-transforms/replace-pipe.util.ts +11 -11
- package/src/_collections/utils/pipe-transforms/slider-pipe.util.ts +20 -20
- package/src/_collections/utils/pipe-transforms/smart-replace-pipe.util.ts +71 -71
- package/src/_collections/utils/regex/index.ts +4 -4
- package/src/_collections/utils/regex/password-regex.util.ts +52 -52
- package/src/_collections/utils/regex/regex.util.ts +6 -6
- package/src/_collections/utils/regex/username-regex.util.ts +33 -33
- package/src/_collections/utils/regions.util.ts +100 -97
- package/src/_collections/utils/round-list.util.ts +44 -44
- package/src/_collections/utils/shared.static-service.ts +177 -177
- package/src/_collections/utils/time.util.spec.ts +50 -50
- package/src/_collections/utils/time.util.ts +219 -219
- package/src/_collections/utils/type-cloning-facility.util.ts +121 -121
- package/src/_collections/utils/utilities.util.ts +130 -130
- package/src/_enums/basic-property-type.enum.ts +9 -9
- package/src/_enums/data-model-type.enum.ts +13 -13
- package/src/_enums/day-of-week.enum.ts +28 -28
- package/src/_enums/error-level.enum.ts +17 -17
- package/src/_enums/index.ts +16 -16
- package/src/_enums/location/index.ts +3 -3
- package/src/_enums/location/region.enum.ts +9 -9
- package/src/_enums/location/sub-region.enum.ts +26 -26
- package/src/_enums/location/subdivision-region-type.enum.ts +44 -44
- package/src/_enums/log-style.enum.ts +30 -30
- package/src/_enums/month.enum.ts +16 -16
- package/src/_enums/pipe.enum.ts +45 -45
- package/src/_enums/range-pipe-setting.enum.ts +11 -11
- package/src/_enums/time/day-of-week.enum.ts +28 -28
- package/src/_enums/time/index.ts +3 -3
- package/src/_enums/time/month.enum.ts +16 -16
- package/src/_enums/time/relative-date.enum.ts +13 -13
- package/src/_models/control-models/daily-usage-data.control-model.ts +21 -21
- package/src/_models/control-models/data-model-params.control-model.ts +39 -39
- package/src/_models/control-models/data-property-params.control-model.ts +106 -106
- package/src/_models/control-models/error.control-model.spec.ts +753 -716
- package/src/_models/control-models/error.control-model.ts +722 -722
- package/src/_models/control-models/index.ts +10 -10
- package/src/_models/control-models/poll.control-model.ts +113 -113
- package/src/_models/control-models/range-value.control-model.ts +142 -142
- package/src/_models/control-models/usage-action.control-model.ts +15 -15
- package/src/_models/control-models/usage-data.control-model.ts +20 -20
- package/src/_models/data-models/custom-data.data-model.ts +28 -28
- package/src/_models/data-models/index.ts +5 -5
- package/src/_models/data-models/metadata.data-model.ts +83 -83
- package/src/_models/data-models/usage-session.data-model.ts +53 -53
- package/src/_models/index.ts +12 -12
- package/src/_models/interfaces/error-defaults.interface.ts +11 -11
- package/src/_models/interfaces/index.ts +11 -8
- package/src/_models/interfaces/location/country-division.interface.ts +7 -7
- package/src/_models/interfaces/location/country-iso.interface.ts +21 -21
- package/src/_models/interfaces/location/country-phone-code.interface.ts +7 -7
- package/src/_models/interfaces/location/division-collection.interface.ts +10 -10
- package/src/_models/interfaces/location/division-region-data.interface.ts +8 -8
- package/src/_models/interfaces/location/geo-ip-location.interface.ts +26 -26
- package/src/_models/interfaces/location/index.ts +10 -10
- package/src/_models/interfaces/location/location-coordinates.interface.ts +5 -5
- package/src/_models/interfaces/multi-pipe-settings.type.ts +7 -7
- package/src/_models/interfaces/paged.interface.ts +11 -11
- package/src/_models/interfaces/pipe-transforms.interface.ts +29 -29
- package/src/_models/interfaces/random-weight.interface.ts +7 -7
- package/src/_models/interfaces/route-settings.interface.ts +11 -11
- package/src/_modules/collections.index.ts +2 -2
- package/src/_modules/constants.index.ts +2 -2
- package/src/_modules/custom-data-module.index.ts +6 -6
- package/src/_modules/data-modules.index.ts +9 -9
- package/src/_modules/enums.index.ts +2 -2
- package/src/_modules/error-module.index.ts +8 -8
- package/src/_modules/location.index.ts +15 -15
- package/src/_modules/models.index.ts +2 -2
- package/src/_modules/shared-service.index.ts +9 -9
- package/src/_modules/test-module.index.ts +5 -5
- package/src/_modules/usage-module.index.ts +10 -10
- package/tsconfig.json +29 -29
- package/tslint.json +153 -153
- package/build/_enums/region.enum.d.ts +0 -8
- package/build/_enums/region.enum.d.ts.map +0 -1
- package/build/_enums/region.enum.js +0 -12
- package/build/_enums/region.enum.js.map +0 -1
- package/build/_enums/relative-date.enum.d.ts +0 -9
- package/build/_enums/relative-date.enum.d.ts.map +0 -1
- package/build/_enums/relative-date.enum.js +0 -13
- package/build/_enums/relative-date.enum.js.map +0 -1
- package/build/_enums/sub-region.enum.d.ts +0 -20
- package/build/_enums/sub-region.enum.d.ts.map +0 -1
- package/build/_enums/sub-region.enum.js +0 -24
- package/build/_enums/sub-region.enum.js.map +0 -1
- package/build/_enums/subdivision-region-type.enum.d.ts +0 -41
- package/build/_enums/subdivision-region-type.enum.d.ts.map +0 -1
- package/build/_enums/subdivision-region-type.enum.js +0 -46
- package/build/_enums/subdivision-region-type.enum.js.map +0 -1
- package/src/_enums/region.enum.ts +0 -9
- package/src/_enums/relative-date.enum.ts +0 -13
- package/src/_enums/sub-region.enum.ts +0 -26
- package/src/_enums/subdivision-region-type.enum.ts +0 -44
|
@@ -1,219 +1,219 @@
|
|
|
1
|
-
|
|
2
|
-
import { day, hour, minute, month, second, week, year } from '../constants/times.const';
|
|
3
|
-
import { DynamoFM_Month } from '../../_enums/time/month.enum';
|
|
4
|
-
import { DynamoFM_DayOfWeek } from '../../_enums/time/day-of-week.enum';
|
|
5
|
-
import { DynamoFM_RelativeDate } from '../../_enums/time/relative-date.enum';
|
|
6
|
-
|
|
7
|
-
export type DFM_Time = DynamoFM_Time;
|
|
8
|
-
export type DFM_T = DynamoFM_Time;
|
|
9
|
-
export class DynamoFM_Time {
|
|
10
|
-
|
|
11
|
-
static readonly second = second;
|
|
12
|
-
static readonly minute = minute;
|
|
13
|
-
static readonly hour = hour;
|
|
14
|
-
static readonly day = day;
|
|
15
|
-
static readonly week = week;
|
|
16
|
-
static readonly month = month;
|
|
17
|
-
static readonly year = year;
|
|
18
|
-
|
|
19
|
-
static getAge(birthDate: Date | number | string): number {
|
|
20
|
-
return this.getYear(+new Date() - +new Date(birthDate));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* returns the date as a number of years
|
|
25
|
-
* @param date
|
|
26
|
-
* @returns
|
|
27
|
-
*/
|
|
28
|
-
static getYear(date: Date | number | string): number {
|
|
29
|
-
if (typeof date === 'string') {
|
|
30
|
-
date = new Date(date);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return (+date / year);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* returns the date as a number of hours
|
|
38
|
-
* @param date
|
|
39
|
-
* @returns
|
|
40
|
-
*/
|
|
41
|
-
static getHour(date: Date | number | string): number {
|
|
42
|
-
if (typeof date === 'string') {
|
|
43
|
-
date = new Date(date);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return (+date / hour);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* calculates the birthdate from the age
|
|
51
|
-
* (with current date so this wont be accurate for days or months, only years)
|
|
52
|
-
* @param date
|
|
53
|
-
* @returns
|
|
54
|
-
*/
|
|
55
|
-
static getDateByAge(age: number): Date {
|
|
56
|
-
return new Date(+new Date() - (year * age));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* returns the date x before the current date
|
|
61
|
-
* @param relativeDate
|
|
62
|
-
* @returns
|
|
63
|
-
*/
|
|
64
|
-
static getDateByRelativeDate(
|
|
65
|
-
relativeDate: DynamoFM_RelativeDate,
|
|
66
|
-
comparedTo?: Date
|
|
67
|
-
): Date {
|
|
68
|
-
switch (relativeDate) {
|
|
69
|
-
case DynamoFM_RelativeDate.lastDay:
|
|
70
|
-
return this.oneDayAgo(comparedTo);
|
|
71
|
-
|
|
72
|
-
case DynamoFM_RelativeDate.lastWeek:
|
|
73
|
-
return this.oneWeekAgo(comparedTo);
|
|
74
|
-
|
|
75
|
-
case DynamoFM_RelativeDate.lastMonth:
|
|
76
|
-
return this.oneMonthAgo(comparedTo);
|
|
77
|
-
|
|
78
|
-
case DynamoFM_RelativeDate.lastYear:
|
|
79
|
-
return this.oneYearAgo(comparedTo);
|
|
80
|
-
|
|
81
|
-
case DynamoFM_RelativeDate.last10Years:
|
|
82
|
-
return this.tenYearsAgo(comparedTo);
|
|
83
|
-
|
|
84
|
-
case DynamoFM_RelativeDate.allTime:
|
|
85
|
-
return new Date(0);
|
|
86
|
-
|
|
87
|
-
default:
|
|
88
|
-
return new Date(0);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* returns the date one hour ago
|
|
94
|
-
* @returns
|
|
95
|
-
*/
|
|
96
|
-
static oneHourAgo(comparedTo: Date = new Date()): Date {
|
|
97
|
-
return new Date(+comparedTo - hour);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* returns the date one day ago
|
|
102
|
-
* @returns
|
|
103
|
-
*/
|
|
104
|
-
static oneDayAgo(comparedTo: Date = new Date()): Date {
|
|
105
|
-
return new Date(+comparedTo - day);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* returns the date one week ago
|
|
110
|
-
* @returns
|
|
111
|
-
*/
|
|
112
|
-
static oneWeekAgo(comparedTo: Date = new Date()): Date {
|
|
113
|
-
return new Date(+comparedTo - week);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* returns the date one month ago
|
|
118
|
-
* @returns
|
|
119
|
-
*/
|
|
120
|
-
static oneMonthAgo(comparedTo: Date = new Date()): Date {
|
|
121
|
-
return new Date(+comparedTo - month);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* returns the date one year ago
|
|
126
|
-
* @returns
|
|
127
|
-
*/
|
|
128
|
-
static oneYearAgo(comparedTo: Date = new Date()): Date {
|
|
129
|
-
return new Date(+comparedTo - year);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* returns the date ten years ago
|
|
134
|
-
* @returns
|
|
135
|
-
*/
|
|
136
|
-
static tenYearsAgo(comparedTo: Date = new Date()): Date {
|
|
137
|
-
return new Date(+comparedTo - (10 * year));
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* returns the DynamoFM_DayOfWeek type of the current day
|
|
142
|
-
* @returns
|
|
143
|
-
*/
|
|
144
|
-
static getTodayOfWeek(): DynamoFM_DayOfWeek {
|
|
145
|
-
return DynamoFM_DayOfWeek[
|
|
146
|
-
new Date().toLocaleString('en-us', { weekday: 'long' }).toLocaleLowerCase()
|
|
147
|
-
];
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* returns the days of the week from today to the end of the week in DynamoFM_DayOfWeek format
|
|
152
|
-
* @returns
|
|
153
|
-
*/
|
|
154
|
-
static getDaysOfWeekFromToday(): DynamoFM_DayOfWeek[] {
|
|
155
|
-
const today: DynamoFM_DayOfWeek = this.getTodayOfWeek();
|
|
156
|
-
const daysOfWeek: DynamoFM_DayOfWeek[] = Object.values(DynamoFM_DayOfWeek);
|
|
157
|
-
const todayIndex: number = daysOfWeek.indexOf(today);
|
|
158
|
-
|
|
159
|
-
return daysOfWeek.slice(todayIndex).concat(daysOfWeek.slice(0, todayIndex));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* returns the days of the week to today to the end of the week in DynamoFM_DayOfWeek format
|
|
164
|
-
* @returns
|
|
165
|
-
*/
|
|
166
|
-
static getDaysOfWeekToToday(): DynamoFM_DayOfWeek[] {
|
|
167
|
-
const today: DynamoFM_DayOfWeek = this.getTodayOfWeek();
|
|
168
|
-
const daysOfWeek: DynamoFM_DayOfWeek[] = Object.values(DynamoFM_DayOfWeek);
|
|
169
|
-
const todayIndex: number = daysOfWeek.indexOf(today);
|
|
170
|
-
|
|
171
|
-
return daysOfWeek.slice(0, todayIndex).reverse().concat(daysOfWeek.slice(todayIndex).reverse());
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* returns the DynamoFM_Month type of the current month
|
|
176
|
-
* @returns
|
|
177
|
-
*/
|
|
178
|
-
static getCurrentMonth(): DynamoFM_Month {
|
|
179
|
-
return DynamoFM_Month[
|
|
180
|
-
new Date().toLocaleString('en-us', { month: 'long' }).toLocaleLowerCase()
|
|
181
|
-
];
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* returns the number of days in the month
|
|
186
|
-
* @param inYear this value is important for february if you want to know if it is a leap year
|
|
187
|
-
* @returns
|
|
188
|
-
*/
|
|
189
|
-
static getMonthLength(month: DynamoFM_Month, inYear?: number): number {
|
|
190
|
-
switch (month) {
|
|
191
|
-
case DynamoFM_Month.january:
|
|
192
|
-
case DynamoFM_Month.march:
|
|
193
|
-
case DynamoFM_Month.may:
|
|
194
|
-
case DynamoFM_Month.june:
|
|
195
|
-
case DynamoFM_Month.august:
|
|
196
|
-
case DynamoFM_Month.october:
|
|
197
|
-
return 31;
|
|
198
|
-
|
|
199
|
-
case DynamoFM_Month.april:
|
|
200
|
-
case DynamoFM_Month.july:
|
|
201
|
-
case DynamoFM_Month.september:
|
|
202
|
-
case DynamoFM_Month.november:
|
|
203
|
-
case DynamoFM_Month.december:
|
|
204
|
-
return 30;
|
|
205
|
-
|
|
206
|
-
case DynamoFM_Month.february:
|
|
207
|
-
return this.isLeapYear(inYear ?? new Date().getFullYear()) ? 29 : 28;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* returns year is leap or not
|
|
213
|
-
* @param year
|
|
214
|
-
* @returns
|
|
215
|
-
*/
|
|
216
|
-
static isLeapYear(year: number): boolean {
|
|
217
|
-
return year % 4 === 0;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
1
|
+
|
|
2
|
+
import { day, hour, minute, month, second, week, year } from '../constants/times.const';
|
|
3
|
+
import { DynamoFM_Month } from '../../_enums/time/month.enum';
|
|
4
|
+
import { DynamoFM_DayOfWeek } from '../../_enums/time/day-of-week.enum';
|
|
5
|
+
import { DynamoFM_RelativeDate } from '../../_enums/time/relative-date.enum';
|
|
6
|
+
|
|
7
|
+
export type DFM_Time = DynamoFM_Time;
|
|
8
|
+
export type DFM_T = DynamoFM_Time;
|
|
9
|
+
export class DynamoFM_Time {
|
|
10
|
+
|
|
11
|
+
static readonly second = second;
|
|
12
|
+
static readonly minute = minute;
|
|
13
|
+
static readonly hour = hour;
|
|
14
|
+
static readonly day = day;
|
|
15
|
+
static readonly week = week;
|
|
16
|
+
static readonly month = month;
|
|
17
|
+
static readonly year = year;
|
|
18
|
+
|
|
19
|
+
static getAge(birthDate: Date | number | string): number {
|
|
20
|
+
return this.getYear(+new Date() - +new Date(birthDate));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* returns the date as a number of years
|
|
25
|
+
* @param date
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
static getYear(date: Date | number | string): number {
|
|
29
|
+
if (typeof date === 'string') {
|
|
30
|
+
date = new Date(date);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return (+date / year);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* returns the date as a number of hours
|
|
38
|
+
* @param date
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
static getHour(date: Date | number | string): number {
|
|
42
|
+
if (typeof date === 'string') {
|
|
43
|
+
date = new Date(date);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return (+date / hour);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* calculates the birthdate from the age
|
|
51
|
+
* (with current date so this wont be accurate for days or months, only years)
|
|
52
|
+
* @param date
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
static getDateByAge(age: number): Date {
|
|
56
|
+
return new Date(+new Date() - (year * age));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* returns the date x before the current date
|
|
61
|
+
* @param relativeDate
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
static getDateByRelativeDate(
|
|
65
|
+
relativeDate: DynamoFM_RelativeDate,
|
|
66
|
+
comparedTo?: Date
|
|
67
|
+
): Date {
|
|
68
|
+
switch (relativeDate) {
|
|
69
|
+
case DynamoFM_RelativeDate.lastDay:
|
|
70
|
+
return this.oneDayAgo(comparedTo);
|
|
71
|
+
|
|
72
|
+
case DynamoFM_RelativeDate.lastWeek:
|
|
73
|
+
return this.oneWeekAgo(comparedTo);
|
|
74
|
+
|
|
75
|
+
case DynamoFM_RelativeDate.lastMonth:
|
|
76
|
+
return this.oneMonthAgo(comparedTo);
|
|
77
|
+
|
|
78
|
+
case DynamoFM_RelativeDate.lastYear:
|
|
79
|
+
return this.oneYearAgo(comparedTo);
|
|
80
|
+
|
|
81
|
+
case DynamoFM_RelativeDate.last10Years:
|
|
82
|
+
return this.tenYearsAgo(comparedTo);
|
|
83
|
+
|
|
84
|
+
case DynamoFM_RelativeDate.allTime:
|
|
85
|
+
return new Date(0);
|
|
86
|
+
|
|
87
|
+
default:
|
|
88
|
+
return new Date(0);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* returns the date one hour ago
|
|
94
|
+
* @returns
|
|
95
|
+
*/
|
|
96
|
+
static oneHourAgo(comparedTo: Date = new Date()): Date {
|
|
97
|
+
return new Date(+comparedTo - hour);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* returns the date one day ago
|
|
102
|
+
* @returns
|
|
103
|
+
*/
|
|
104
|
+
static oneDayAgo(comparedTo: Date = new Date()): Date {
|
|
105
|
+
return new Date(+comparedTo - day);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* returns the date one week ago
|
|
110
|
+
* @returns
|
|
111
|
+
*/
|
|
112
|
+
static oneWeekAgo(comparedTo: Date = new Date()): Date {
|
|
113
|
+
return new Date(+comparedTo - week);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* returns the date one month ago
|
|
118
|
+
* @returns
|
|
119
|
+
*/
|
|
120
|
+
static oneMonthAgo(comparedTo: Date = new Date()): Date {
|
|
121
|
+
return new Date(+comparedTo - month);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* returns the date one year ago
|
|
126
|
+
* @returns
|
|
127
|
+
*/
|
|
128
|
+
static oneYearAgo(comparedTo: Date = new Date()): Date {
|
|
129
|
+
return new Date(+comparedTo - year);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* returns the date ten years ago
|
|
134
|
+
* @returns
|
|
135
|
+
*/
|
|
136
|
+
static tenYearsAgo(comparedTo: Date = new Date()): Date {
|
|
137
|
+
return new Date(+comparedTo - (10 * year));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* returns the DynamoFM_DayOfWeek type of the current day
|
|
142
|
+
* @returns
|
|
143
|
+
*/
|
|
144
|
+
static getTodayOfWeek(): DynamoFM_DayOfWeek {
|
|
145
|
+
return DynamoFM_DayOfWeek[
|
|
146
|
+
new Date().toLocaleString('en-us', { weekday: 'long' }).toLocaleLowerCase()
|
|
147
|
+
];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* returns the days of the week from today to the end of the week in DynamoFM_DayOfWeek format
|
|
152
|
+
* @returns
|
|
153
|
+
*/
|
|
154
|
+
static getDaysOfWeekFromToday(): DynamoFM_DayOfWeek[] {
|
|
155
|
+
const today: DynamoFM_DayOfWeek = this.getTodayOfWeek();
|
|
156
|
+
const daysOfWeek: DynamoFM_DayOfWeek[] = Object.values(DynamoFM_DayOfWeek);
|
|
157
|
+
const todayIndex: number = daysOfWeek.indexOf(today);
|
|
158
|
+
|
|
159
|
+
return daysOfWeek.slice(todayIndex).concat(daysOfWeek.slice(0, todayIndex));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* returns the days of the week to today to the end of the week in DynamoFM_DayOfWeek format
|
|
164
|
+
* @returns
|
|
165
|
+
*/
|
|
166
|
+
static getDaysOfWeekToToday(): DynamoFM_DayOfWeek[] {
|
|
167
|
+
const today: DynamoFM_DayOfWeek = this.getTodayOfWeek();
|
|
168
|
+
const daysOfWeek: DynamoFM_DayOfWeek[] = Object.values(DynamoFM_DayOfWeek);
|
|
169
|
+
const todayIndex: number = daysOfWeek.indexOf(today);
|
|
170
|
+
|
|
171
|
+
return daysOfWeek.slice(0, todayIndex).reverse().concat(daysOfWeek.slice(todayIndex).reverse());
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* returns the DynamoFM_Month type of the current month
|
|
176
|
+
* @returns
|
|
177
|
+
*/
|
|
178
|
+
static getCurrentMonth(): DynamoFM_Month {
|
|
179
|
+
return DynamoFM_Month[
|
|
180
|
+
new Date().toLocaleString('en-us', { month: 'long' }).toLocaleLowerCase()
|
|
181
|
+
];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* returns the number of days in the month
|
|
186
|
+
* @param inYear this value is important for february if you want to know if it is a leap year
|
|
187
|
+
* @returns
|
|
188
|
+
*/
|
|
189
|
+
static getMonthLength(month: DynamoFM_Month, inYear?: number): number {
|
|
190
|
+
switch (month) {
|
|
191
|
+
case DynamoFM_Month.january:
|
|
192
|
+
case DynamoFM_Month.march:
|
|
193
|
+
case DynamoFM_Month.may:
|
|
194
|
+
case DynamoFM_Month.june:
|
|
195
|
+
case DynamoFM_Month.august:
|
|
196
|
+
case DynamoFM_Month.october:
|
|
197
|
+
return 31;
|
|
198
|
+
|
|
199
|
+
case DynamoFM_Month.april:
|
|
200
|
+
case DynamoFM_Month.july:
|
|
201
|
+
case DynamoFM_Month.september:
|
|
202
|
+
case DynamoFM_Month.november:
|
|
203
|
+
case DynamoFM_Month.december:
|
|
204
|
+
return 30;
|
|
205
|
+
|
|
206
|
+
case DynamoFM_Month.february:
|
|
207
|
+
return this.isLeapYear(inYear ?? new Date().getFullYear()) ? 29 : 28;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* returns year is leap or not
|
|
213
|
+
* @param year
|
|
214
|
+
* @returns
|
|
215
|
+
*/
|
|
216
|
+
static isLeapYear(year: number): boolean {
|
|
217
|
+
return year % 4 === 0;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
|
|
2
|
-
export type DynamoFM_TCF = DynamoFM_TypeCloningFacility;
|
|
3
|
-
export type DFM_TypeCloningFacility = DynamoFM_TypeCloningFacility;
|
|
4
|
-
export type DFM_TCF = DynamoFM_TCF;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* This functions should be able to clone any object,
|
|
9
|
-
* even if it contains circular references.
|
|
10
|
-
*
|
|
11
|
-
* if the object has a clone() function, it will be used.
|
|
12
|
-
* if the object has any getter or setter, it will be ignored,
|
|
13
|
-
* therefore it should have a clone() function.
|
|
14
|
-
*
|
|
15
|
-
* WARNING: this function will clone all connected objects!
|
|
16
|
-
*
|
|
17
|
-
* */
|
|
18
|
-
export class DynamoFM_TypeCloningFacility {
|
|
19
|
-
|
|
20
|
-
static clone<T>(
|
|
21
|
-
object: T,
|
|
22
|
-
skip: string[] = [],
|
|
23
|
-
affectedObjects: ObjectCollector[] = [],
|
|
24
|
-
debug: boolean = false
|
|
25
|
-
): T {
|
|
26
|
-
const result: T = {} as T;
|
|
27
|
-
|
|
28
|
-
for (const key in object) {
|
|
29
|
-
if (debug) {
|
|
30
|
-
console.log('clone DEBUG; key:', key);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (typeof object === 'object'/* object.hasOwnProperty(key) */) {
|
|
34
|
-
const type = typeof object[key];
|
|
35
|
-
|
|
36
|
-
if (skip.includes(key)) {
|
|
37
|
-
continue;
|
|
38
|
-
|
|
39
|
-
} else if (type === 'object') {
|
|
40
|
-
const alreadyAffected = affectedObjects?.find(
|
|
41
|
-
(affectedObject): boolean => affectedObject.id === object[key]
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
if (alreadyAffected) {
|
|
45
|
-
result[key] = alreadyAffected.clonedObject;
|
|
46
|
-
|
|
47
|
-
} else {
|
|
48
|
-
const newAffectedObject: ObjectCollector = {
|
|
49
|
-
id: object[key]
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
affectedObjects.push(newAffectedObject);
|
|
53
|
-
|
|
54
|
-
if (Array.isArray(object[key])) {
|
|
55
|
-
newAffectedObject.clonedObject = this.cloneArray(
|
|
56
|
-
object[key] as unknown[],
|
|
57
|
-
skip,
|
|
58
|
-
affectedObjects,
|
|
59
|
-
debug
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
} else if (
|
|
63
|
-
(object[key] as any)?.clone &&
|
|
64
|
-
typeof (object[key] as any)?.clone === 'function'
|
|
65
|
-
) {
|
|
66
|
-
newAffectedObject.clonedObject = (object[key] as any).clone();
|
|
67
|
-
|
|
68
|
-
} else {
|
|
69
|
-
newAffectedObject.clonedObject = this.clone(
|
|
70
|
-
object[key],
|
|
71
|
-
skip,
|
|
72
|
-
affectedObjects,
|
|
73
|
-
debug
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
result[key] = newAffectedObject.clonedObject;
|
|
78
|
-
}
|
|
79
|
-
} else {
|
|
80
|
-
result[key] = object[key];
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return result;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
static cloneArray<T>(
|
|
89
|
-
array: T[],
|
|
90
|
-
skip: string[] = [],
|
|
91
|
-
affectedObjects: ObjectCollector[] = [],
|
|
92
|
-
debug: boolean = false
|
|
93
|
-
): T[] {
|
|
94
|
-
const result: T[] = [];
|
|
95
|
-
|
|
96
|
-
array.forEach((element, index): void => {
|
|
97
|
-
if (debug) {
|
|
98
|
-
console.log('cloneArrayDEBUG; index', index);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (typeof element === 'object') {
|
|
102
|
-
result.push(this.clone(element, skip, affectedObjects, debug));
|
|
103
|
-
|
|
104
|
-
} else {
|
|
105
|
-
result.push(element);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
return result;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
storeCirculation // TODO stringifyable -------------------------------------------------------------------------------------------------------------------------------------------
|
|
113
|
-
|
|
114
|
-
restoreCirculation // TODO stringified -------------------------------------------------------------------------------------------------------------------------------------------
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
interface ObjectCollector {
|
|
118
|
-
id;
|
|
119
|
-
clonedObject?;
|
|
120
|
-
}
|
|
121
|
-
|
|
1
|
+
|
|
2
|
+
export type DynamoFM_TCF = DynamoFM_TypeCloningFacility;
|
|
3
|
+
export type DFM_TypeCloningFacility = DynamoFM_TypeCloningFacility;
|
|
4
|
+
export type DFM_TCF = DynamoFM_TCF;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* This functions should be able to clone any object,
|
|
9
|
+
* even if it contains circular references.
|
|
10
|
+
*
|
|
11
|
+
* if the object has a clone() function, it will be used.
|
|
12
|
+
* if the object has any getter or setter, it will be ignored,
|
|
13
|
+
* therefore it should have a clone() function.
|
|
14
|
+
*
|
|
15
|
+
* WARNING: this function will clone all connected objects!
|
|
16
|
+
*
|
|
17
|
+
* */
|
|
18
|
+
export class DynamoFM_TypeCloningFacility {
|
|
19
|
+
|
|
20
|
+
static clone<T>(
|
|
21
|
+
object: T,
|
|
22
|
+
skip: string[] = [],
|
|
23
|
+
affectedObjects: ObjectCollector[] = [],
|
|
24
|
+
debug: boolean = false
|
|
25
|
+
): T {
|
|
26
|
+
const result: T = {} as T;
|
|
27
|
+
|
|
28
|
+
for (const key in object) {
|
|
29
|
+
if (debug) {
|
|
30
|
+
console.log('clone DEBUG; key:', key);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (typeof object === 'object'/* object.hasOwnProperty(key) */) {
|
|
34
|
+
const type = typeof object[key];
|
|
35
|
+
|
|
36
|
+
if (skip.includes(key)) {
|
|
37
|
+
continue;
|
|
38
|
+
|
|
39
|
+
} else if (type === 'object') {
|
|
40
|
+
const alreadyAffected = affectedObjects?.find(
|
|
41
|
+
(affectedObject): boolean => affectedObject.id === object[key]
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
if (alreadyAffected) {
|
|
45
|
+
result[key] = alreadyAffected.clonedObject;
|
|
46
|
+
|
|
47
|
+
} else {
|
|
48
|
+
const newAffectedObject: ObjectCollector = {
|
|
49
|
+
id: object[key]
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
affectedObjects.push(newAffectedObject);
|
|
53
|
+
|
|
54
|
+
if (Array.isArray(object[key])) {
|
|
55
|
+
newAffectedObject.clonedObject = this.cloneArray(
|
|
56
|
+
object[key] as unknown[],
|
|
57
|
+
skip,
|
|
58
|
+
affectedObjects,
|
|
59
|
+
debug
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
} else if (
|
|
63
|
+
(object[key] as any)?.clone &&
|
|
64
|
+
typeof (object[key] as any)?.clone === 'function'
|
|
65
|
+
) {
|
|
66
|
+
newAffectedObject.clonedObject = (object[key] as any).clone();
|
|
67
|
+
|
|
68
|
+
} else {
|
|
69
|
+
newAffectedObject.clonedObject = this.clone(
|
|
70
|
+
object[key],
|
|
71
|
+
skip,
|
|
72
|
+
affectedObjects,
|
|
73
|
+
debug
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
result[key] = newAffectedObject.clonedObject;
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
result[key] = object[key];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static cloneArray<T>(
|
|
89
|
+
array: T[],
|
|
90
|
+
skip: string[] = [],
|
|
91
|
+
affectedObjects: ObjectCollector[] = [],
|
|
92
|
+
debug: boolean = false
|
|
93
|
+
): T[] {
|
|
94
|
+
const result: T[] = [];
|
|
95
|
+
|
|
96
|
+
array.forEach((element, index): void => {
|
|
97
|
+
if (debug) {
|
|
98
|
+
console.log('cloneArrayDEBUG; index', index);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (typeof element === 'object') {
|
|
102
|
+
result.push(this.clone(element, skip, affectedObjects, debug));
|
|
103
|
+
|
|
104
|
+
} else {
|
|
105
|
+
result.push(element);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
storeCirculation // TODO stringifyable -------------------------------------------------------------------------------------------------------------------------------------------
|
|
113
|
+
|
|
114
|
+
restoreCirculation // TODO stringified -------------------------------------------------------------------------------------------------------------------------------------------
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
interface ObjectCollector {
|
|
118
|
+
id;
|
|
119
|
+
clonedObject?;
|
|
120
|
+
}
|
|
121
|
+
|