@futdevpro/fsm-dynamo 1.7.3 → 1.7.6

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.
Files changed (167) hide show
  1. package/.eslintrc.json +138 -0
  2. package/lib/_constants/error-defaults.const.d.ts.map +1 -1
  3. package/lib/_constants/error-defaults.const.js.map +1 -1
  4. package/lib/_constants/module-settings/usage-module-settings.const.js +1 -1
  5. package/lib/_constants/module-settings/usage-module-settings.const.js.map +1 -1
  6. package/lib/_enums/day-of-week.enum.d.ts +13 -0
  7. package/lib/_enums/day-of-week.enum.d.ts.map +1 -0
  8. package/lib/_enums/day-of-week.enum.js +25 -0
  9. package/lib/_enums/day-of-week.enum.js.map +1 -0
  10. package/lib/_enums/index.d.ts +4 -0
  11. package/lib/_enums/index.d.ts.map +1 -1
  12. package/lib/_enums/index.js +4 -0
  13. package/lib/_enums/index.js.map +1 -1
  14. package/lib/_enums/month.enum.d.ts +15 -0
  15. package/lib/_enums/month.enum.d.ts.map +1 -0
  16. package/lib/_enums/month.enum.js +19 -0
  17. package/lib/_enums/month.enum.js.map +1 -0
  18. package/lib/_enums/relative-date.enum.d.ts +9 -0
  19. package/lib/_enums/relative-date.enum.d.ts.map +1 -0
  20. package/lib/_enums/relative-date.enum.js +13 -0
  21. package/lib/_enums/relative-date.enum.js.map +1 -0
  22. package/lib/_models/control-models/daily-usage-data.control-model.d.ts +1 -1
  23. package/lib/_models/control-models/daily-usage-data.control-model.js.map +1 -1
  24. package/lib/_models/control-models/data-params.control-model.js.map +1 -1
  25. package/lib/_models/control-models/data-property-params.control-model.d.ts +4 -2
  26. package/lib/_models/control-models/data-property-params.control-model.d.ts.map +1 -1
  27. package/lib/_models/control-models/data-property-params.control-model.js +6 -3
  28. package/lib/_models/control-models/data-property-params.control-model.js.map +1 -1
  29. package/lib/_models/control-models/error.control-model.d.ts +28 -24
  30. package/lib/_models/control-models/error.control-model.d.ts.map +1 -1
  31. package/lib/_models/control-models/error.control-model.js +39 -16
  32. package/lib/_models/control-models/error.control-model.js.map +1 -1
  33. package/lib/_models/control-models/error.control-model.spec.js +3 -2
  34. package/lib/_models/control-models/error.control-model.spec.js.map +1 -1
  35. package/lib/_models/control-models/poll.control-model.d.ts +2 -2
  36. package/lib/_models/control-models/poll.control-model.d.ts.map +1 -1
  37. package/lib/_models/control-models/poll.control-model.js +2 -1
  38. package/lib/_models/control-models/poll.control-model.js.map +1 -1
  39. package/lib/_models/control-models/range-value.control-model.d.ts +25 -2
  40. package/lib/_models/control-models/range-value.control-model.d.ts.map +1 -1
  41. package/lib/_models/control-models/range-value.control-model.js +83 -1
  42. package/lib/_models/control-models/range-value.control-model.js.map +1 -1
  43. package/lib/_models/control-models/usage-action.control-model.js +0 -1
  44. package/lib/_models/control-models/usage-action.control-model.js.map +1 -1
  45. package/lib/_models/control-models/usage-data.control-model.js.map +1 -1
  46. package/lib/_models/data-models/custom-data.data-model.d.ts.map +1 -1
  47. package/lib/_models/data-models/custom-data.data-model.js.map +1 -1
  48. package/lib/_models/data-models/metadata.data-model.d.ts.map +1 -1
  49. package/lib/_models/data-models/metadata.data-model.js.map +1 -1
  50. package/lib/_models/data-models/usage-session.data-model.d.ts.map +1 -1
  51. package/lib/_models/data-models/usage-session.data-model.js.map +1 -1
  52. package/lib/_models/interfaces/paged.interace.d.ts +8 -0
  53. package/lib/_models/interfaces/paged.interace.d.ts.map +1 -0
  54. package/lib/_models/interfaces/paged.interace.js +3 -0
  55. package/lib/_models/interfaces/paged.interace.js.map +1 -0
  56. package/lib/_modules/usage-module.index.d.ts +1 -0
  57. package/lib/_modules/usage-module.index.d.ts.map +1 -1
  58. package/lib/_modules/usage-module.index.js +1 -0
  59. package/lib/_modules/usage-module.index.js.map +1 -1
  60. package/lib/_utils/array.util.d.ts +5 -0
  61. package/lib/_utils/array.util.d.ts.map +1 -1
  62. package/lib/_utils/array.util.js +26 -0
  63. package/lib/_utils/array.util.js.map +1 -1
  64. package/lib/_utils/array.util.spec.js.map +1 -1
  65. package/lib/_utils/box-bounds.util.d.ts +18 -0
  66. package/lib/_utils/box-bounds.util.d.ts.map +1 -0
  67. package/lib/_utils/box-bounds.util.js +57 -0
  68. package/lib/_utils/box-bounds.util.js.map +1 -0
  69. package/lib/_utils/index.d.ts +3 -0
  70. package/lib/_utils/index.d.ts.map +1 -1
  71. package/lib/_utils/index.js +3 -0
  72. package/lib/_utils/index.js.map +1 -1
  73. package/lib/_utils/location.util.d.ts.map +1 -1
  74. package/lib/_utils/location.util.js +4 -2
  75. package/lib/_utils/location.util.js.map +1 -1
  76. package/lib/_utils/log.util.d.ts.map +1 -1
  77. package/lib/_utils/log.util.js +4 -1
  78. package/lib/_utils/log.util.js.map +1 -1
  79. package/lib/_utils/math.util.d.ts +10 -0
  80. package/lib/_utils/math.util.d.ts.map +1 -0
  81. package/lib/_utils/math.util.js +32 -0
  82. package/lib/_utils/math.util.js.map +1 -0
  83. package/lib/_utils/metadata.util.d.ts.map +1 -1
  84. package/lib/_utils/metadata.util.js.map +1 -1
  85. package/lib/_utils/random.util.d.ts.map +1 -1
  86. package/lib/_utils/random.util.js +8 -4
  87. package/lib/_utils/random.util.js.map +1 -1
  88. package/lib/_utils/regex/password-regex.util.d.ts +3 -0
  89. package/lib/_utils/regex/password-regex.util.d.ts.map +1 -0
  90. package/lib/_utils/regex/password-regex.util.js +49 -0
  91. package/lib/_utils/regex/password-regex.util.js.map +1 -0
  92. package/lib/_utils/regex/username-regex.util.d.ts +2 -0
  93. package/lib/_utils/regex/username-regex.util.d.ts.map +1 -0
  94. package/lib/_utils/regex/username-regex.util.js +32 -0
  95. package/lib/_utils/regex/username-regex.util.js.map +1 -0
  96. package/lib/_utils/regex.util.d.ts.map +1 -1
  97. package/lib/_utils/regex.util.js +1 -1
  98. package/lib/_utils/regex.util.js.map +1 -1
  99. package/lib/_utils/regions.util.d.ts.map +1 -1
  100. package/lib/_utils/regions.util.js +5 -5
  101. package/lib/_utils/regions.util.js.map +1 -1
  102. package/lib/_utils/round-list.util.d.ts.map +1 -1
  103. package/lib/_utils/round-list.util.js.map +1 -1
  104. package/lib/_utils/shared.static-service.d.ts.map +1 -1
  105. package/lib/_utils/shared.static-service.js +1 -1
  106. package/lib/_utils/shared.static-service.js.map +1 -1
  107. package/lib/_utils/time.util.d.ts +82 -0
  108. package/lib/_utils/time.util.d.ts.map +1 -1
  109. package/lib/_utils/time.util.js +135 -0
  110. package/lib/_utils/time.util.js.map +1 -1
  111. package/lib/_utils/trigonometry.util.d.ts.map +1 -1
  112. package/lib/_utils/trigonometry.util.js +3 -1
  113. package/lib/_utils/trigonometry.util.js.map +1 -1
  114. package/lib/_utils/type-cloning-facility.util.d.ts +27 -0
  115. package/lib/_utils/type-cloning-facility.util.d.ts.map +1 -0
  116. package/lib/_utils/type-cloning-facility.util.js +77 -0
  117. package/lib/_utils/type-cloning-facility.util.js.map +1 -0
  118. package/lib/_utils/utilities.util.d.ts +3 -2
  119. package/lib/_utils/utilities.util.d.ts.map +1 -1
  120. package/lib/_utils/utilities.util.js +8 -4
  121. package/lib/_utils/utilities.util.js.map +1 -1
  122. package/lib/_utils/vector2.util.d.ts +22 -2
  123. package/lib/_utils/vector2.util.d.ts.map +1 -1
  124. package/lib/_utils/vector2.util.js +64 -14
  125. package/lib/_utils/vector2.util.js.map +1 -1
  126. package/lib/tsconfig.tsbuildinfo +1 -1
  127. package/nodemon.json +1 -1
  128. package/package.json +5 -1
  129. package/src/_constants/error-defaults.const.ts +1 -1
  130. package/src/_constants/module-settings/usage-module-settings.const.ts +1 -1
  131. package/src/_enums/day-of-week.enum.ts +27 -0
  132. package/src/_enums/index.ts +4 -0
  133. package/src/_enums/month.enum.ts +16 -0
  134. package/src/_enums/relative-date.enum.ts +13 -0
  135. package/src/_models/control-models/daily-usage-data.control-model.ts +1 -1
  136. package/src/_models/control-models/data-property-params.control-model.ts +12 -4
  137. package/src/_models/control-models/error.control-model.spec.ts +189 -178
  138. package/src/_models/control-models/error.control-model.ts +118 -57
  139. package/src/_models/control-models/poll.control-model.ts +15 -9
  140. package/src/_models/control-models/range-value.control-model.ts +119 -4
  141. package/src/_models/control-models/usage-action.control-model.ts +1 -1
  142. package/src/_models/control-models/usage-data.control-model.ts +1 -1
  143. package/src/_models/data-models/custom-data.data-model.ts +1 -1
  144. package/src/_models/data-models/metadata.data-model.ts +5 -0
  145. package/src/_models/data-models/usage-session.data-model.ts +1 -1
  146. package/src/_models/interfaces/paged.interace.ts +11 -0
  147. package/src/_modules/usage-module.index.ts +1 -0
  148. package/src/_utils/array.util.spec.ts +8 -7
  149. package/src/_utils/array.util.ts +48 -3
  150. package/src/_utils/box-bounds.util.ts +71 -0
  151. package/src/_utils/index.ts +3 -0
  152. package/src/_utils/location.util.ts +11 -3
  153. package/src/_utils/log.util.ts +51 -23
  154. package/src/_utils/math.util.ts +53 -0
  155. package/src/_utils/metadata.util.ts +1 -0
  156. package/src/_utils/random.util.ts +18 -7
  157. package/src/_utils/regex/password-regex.util.ts +53 -0
  158. package/src/_utils/regex/username-regex.util.ts +33 -0
  159. package/src/_utils/regex.util.ts +1 -1
  160. package/src/_utils/regions.util.ts +19 -7
  161. package/src/_utils/round-list.util.ts +1 -0
  162. package/src/_utils/shared.static-service.ts +30 -5
  163. package/src/_utils/time.util.ts +163 -4
  164. package/src/_utils/trigonometry.util.ts +8 -1
  165. package/src/_utils/type-cloning-facility.util.ts +121 -0
  166. package/src/_utils/utilities.util.ts +33 -8
  167. package/src/_utils/vector2.util.ts +83 -16
@@ -33,13 +33,17 @@ export class Dynamo_Shared {
33
33
  */
34
34
  static mapObjList(objList: object[], paths: string[][]): object[] {
35
35
  let newObjList = [...objList];
36
- newObjList = newObjList.map(obj => {
36
+
37
+ newObjList = newObjList.map((obj): any => {
37
38
  const newObj = {};
38
- paths.forEach((path: string[]) => {
39
+
40
+ paths.forEach((path: string[]): void => {
39
41
  newObj[path[path.length - 1]] = this.getNestedData(obj, path);
40
42
  });
43
+
41
44
  return newObj;
42
45
  });
46
+
43
47
  return newObjList;
44
48
  }
45
49
 
@@ -52,11 +56,13 @@ export class Dynamo_Shared {
52
56
  */
53
57
  static getNestedData(parentObj: object, nestedDataKeys: string[]): any {
54
58
  let newData = clone(parentObj); // {...parentObj};
55
- nestedDataKeys.forEach((dk: string) => {
59
+
60
+ nestedDataKeys.forEach((dk: string): void => {
56
61
  if (newData) {
57
62
  newData = newData[dk];
58
63
  }
59
64
  });
65
+
60
66
  return newData;
61
67
  }
62
68
 
@@ -69,13 +75,16 @@ export class Dynamo_Shared {
69
75
  */
70
76
  static nestData(parentObj: object, nestKeys: string[], dataToSet: any): object {
71
77
  const newData = clone(parentObj); // {...parentObj};
78
+
72
79
  if (nestKeys.length > 1) {
73
80
  const keys = [...nestKeys];
74
81
  const nextNestKey = keys.shift();
82
+
75
83
  newData[nextNestKey] = this.nestData(newData[nextNestKey], keys, dataToSet);
76
84
  } else {
77
85
  newData[nestKeys[0]] = dataToSet;
78
86
  }
87
+
79
88
  return newData;
80
89
  }
81
90
 
@@ -88,13 +97,16 @@ export class Dynamo_Shared {
88
97
  */
89
98
  static addToNestedData(parentObj: object, nestKeys: string[], dataToAdd: any): object {
90
99
  const newData = clone(parentObj); // {...parentObj};
100
+
91
101
  if (nestKeys.length > 1) {
92
102
  const keys = [...nestKeys];
93
103
  const nextNestKey = keys.shift();
104
+
94
105
  newData[nextNestKey] = this.addToNestedData(newData[nextNestKey], keys, dataToAdd);
95
106
  } else {
96
107
  newData[nestKeys[0]] += dataToAdd;
97
108
  }
109
+
98
110
  return newData;
99
111
  }
100
112
 
@@ -107,9 +119,11 @@ export class Dynamo_Shared {
107
119
  */
108
120
  static pushToNestedData(parentObj: object, nestKeys: string[], dataToPush: any): object {
109
121
  const newData = clone(parentObj); // {...parentObj};
122
+
110
123
  if (nestKeys.length > 1) {
111
124
  const keys = [...nestKeys];
112
125
  const nextNestKey = keys.shift();
126
+
113
127
  newData[nextNestKey] = this.pushToNestedData(newData[nextNestKey], keys, dataToPush);
114
128
  } else {
115
129
  if (Array.isArray(newData[nestKeys[0]])) {
@@ -118,6 +132,7 @@ export class Dynamo_Shared {
118
132
  newData[nestKeys[0]] = [dataToPush];
119
133
  }
120
134
  }
135
+
121
136
  return newData;
122
137
  }
123
138
 
@@ -129,16 +144,25 @@ export class Dynamo_Shared {
129
144
  * @param dataToSet the actual value that will be setted on location
130
145
  * @returns modified data
131
146
  */
132
- static nestRecursiveListedData<T>(parentObj: T, nestedListKey: string, nestIndexes: number[], dataToSet: any): T {
147
+ static nestRecursiveListedData<T>(
148
+ parentObj: T,
149
+ nestedListKey: string,
150
+ nestIndexes: number[],
151
+ dataToSet: any
152
+ ): T {
133
153
  const newData = clone(parentObj); // parentObj; // {...parentObj};
154
+
134
155
  if (nestIndexes.length > 1) {
135
156
  const indexes = [...nestIndexes];
136
157
  const nextLevelKey = indexes.shift();
158
+
137
159
  newData[nestedListKey][nextLevelKey] = this.nestRecursiveListedData(
138
- newData[nestedListKey][nextLevelKey], nestedListKey, indexes, dataToSet);
160
+ newData[nestedListKey][nextLevelKey], nestedListKey, indexes, dataToSet
161
+ );
139
162
  } else {
140
163
  newData[nestedListKey][nestIndexes[0]] = dataToSet;
141
164
  }
165
+
142
166
  return newData;
143
167
  }
144
168
 
@@ -147,6 +171,7 @@ export class Dynamo_Shared {
147
171
  schema.__createdBy = { type: String };
148
172
  schema.__lastModified = { type: Date };
149
173
  schema.__lastModifiedBy = { type: String };
174
+
150
175
  return schema;
151
176
  }
152
177
  }
@@ -1,49 +1,208 @@
1
1
 
2
2
  import { day, hour, month, week, year } from '../_constants/times.const';
3
+ import { Dynamo_Month } from '../_enums';
4
+ import { Dynamo_DayOfWeek } from '../_enums/day-of-week.enum';
5
+ import { Dynamo_RelativeDate } from '../_enums/relative-date.enum';
3
6
 
4
7
  export type D_Time = Dynamo_Time;
5
8
  export type D_T = Dynamo_Time;
6
9
  export class Dynamo_Time {
7
10
 
8
- static getAge(birthDate: Date | number | string) {
11
+ static getAge(birthDate: Date | number | string): number {
9
12
  return this.getYear(+new Date() - +new Date(birthDate));
10
13
  }
11
14
 
12
- static getYear(date: Date | number | string) {
15
+ /**
16
+ * returns the date as a number of years
17
+ * @param date
18
+ * @returns
19
+ */
20
+ static getYear(date: Date | number | string): number {
13
21
  if (typeof date === 'string') {
14
22
  date = new Date(date);
15
23
  }
24
+
16
25
  return (+date / year);
17
26
  }
18
27
 
19
- static getHour(date: Date | number | string) {
28
+ /**
29
+ * returns the date as a number of hours
30
+ * @param date
31
+ * @returns
32
+ */
33
+ static getHour(date: Date | number | string): number {
20
34
  if (typeof date === 'string') {
21
35
  date = new Date(date);
22
36
  }
37
+
23
38
  return (+date / hour);
24
39
  }
25
40
 
26
- static getDateByAge(age: number) {
41
+ /**
42
+ * calculates the birthdate from the age
43
+ * (with current date so this wont be accurate for days or months, only years)
44
+ * @param date
45
+ * @returns
46
+ */
47
+ static getDateByAge(age: number): Date {
27
48
  return new Date(+new Date() - (year * age));
28
49
  }
29
50
 
51
+ /**
52
+ * returns the date x before the current date
53
+ * @param relativeDate
54
+ * @returns
55
+ */
56
+ static getDateByRelativeDate(relativeDate: Dynamo_RelativeDate): Date {
57
+ switch (relativeDate) {
58
+ case Dynamo_RelativeDate.lastDay:
59
+ return this.oneDayAgo();
60
+
61
+ case Dynamo_RelativeDate.lastWeek:
62
+ return this.oneWeekAgo();
63
+
64
+ case Dynamo_RelativeDate.lastMonth:
65
+ return this.oneMonthAgo();
66
+
67
+ case Dynamo_RelativeDate.lastYear:
68
+ return this.oneYearAgo();
69
+
70
+ case Dynamo_RelativeDate.last10Years:
71
+ return this.tenYearsAgo();
72
+
73
+ case Dynamo_RelativeDate.allTime:
74
+ return new Date(0);
75
+
76
+ default:
77
+ return new Date(0);
78
+ }
79
+ }
80
+
81
+ /**
82
+ * returns the date one hour ago
83
+ * @returns
84
+ */
30
85
  static oneHourAgo(): Date {
31
86
  return new Date(+new Date() - hour);
32
87
  }
33
88
 
89
+ /**
90
+ * returns the date one day ago
91
+ * @returns
92
+ */
34
93
  static oneDayAgo(): Date {
35
94
  return new Date(+new Date() - day);
36
95
  }
37
96
 
97
+ /**
98
+ * returns the date one week ago
99
+ * @returns
100
+ */
38
101
  static oneWeekAgo(): Date {
39
102
  return new Date(+new Date() - week);
40
103
  }
41
104
 
105
+ /**
106
+ * returns the date one month ago
107
+ * @returns
108
+ */
42
109
  static oneMonthAgo(): Date {
43
110
  return new Date(+new Date() - month);
44
111
  }
45
112
 
113
+ /**
114
+ * returns the date one year ago
115
+ * @returns
116
+ */
46
117
  static oneYearAgo(): Date {
47
118
  return new Date(+new Date() - year);
48
119
  }
120
+
121
+ /**
122
+ * returns the date ten years ago
123
+ * @returns
124
+ */
125
+ static tenYearsAgo(): Date {
126
+ return new Date(+new Date() - (10 * year));
127
+ }
128
+
129
+ /**
130
+ * returns the Dynamo_DayOfWeek type of the current day
131
+ * @returns
132
+ */
133
+ static getTodayOfWeek(): Dynamo_DayOfWeek {
134
+ return Dynamo_DayOfWeek[
135
+ new Date().toLocaleString('en-us', { weekday: 'long' }).toLocaleLowerCase()
136
+ ];
137
+ }
138
+
139
+ /**
140
+ * returns the days of the week from today to the end of the week in Dynamo_DayOfWeek format
141
+ * @returns
142
+ */
143
+ static getDaysOfWeekFromToday(): Dynamo_DayOfWeek[] {
144
+ const today: Dynamo_DayOfWeek = this.getTodayOfWeek();
145
+ const daysOfWeek: Dynamo_DayOfWeek[] = Object.values(Dynamo_DayOfWeek);
146
+ const todayIndex: number = daysOfWeek.indexOf(today);
147
+
148
+ return daysOfWeek.slice(todayIndex).concat(daysOfWeek.slice(0, todayIndex));
149
+ }
150
+
151
+ /**
152
+ * returns the days of the week to today to the end of the week in Dynamo_DayOfWeek format
153
+ * @returns
154
+ */
155
+ static getDaysOfWeekToToday(): Dynamo_DayOfWeek[] {
156
+ const today: Dynamo_DayOfWeek = this.getTodayOfWeek();
157
+ const daysOfWeek: Dynamo_DayOfWeek[] = Object.values(Dynamo_DayOfWeek);
158
+ const todayIndex: number = daysOfWeek.indexOf(today);
159
+
160
+ return daysOfWeek.slice(0, todayIndex).reverse().concat(daysOfWeek.slice(todayIndex).reverse());
161
+ }
162
+
163
+ /**
164
+ * returns the Dynamo_Month type of the current month
165
+ * @returns
166
+ */
167
+ static getCurrentMonth(): Dynamo_Month {
168
+ return Dynamo_Month[
169
+ new Date().toLocaleString('en-us', { month: 'long' }).toLocaleLowerCase()
170
+ ];
171
+ }
172
+
173
+ /**
174
+ * returns the number of days in the month
175
+ * @param inYear this value is important for february if you want to know if it is a leap year
176
+ * @returns
177
+ */
178
+ static getMonthLength(month: Dynamo_Month, inYear?: number): number {
179
+ switch (month) {
180
+ case Dynamo_Month.january:
181
+ case Dynamo_Month.march:
182
+ case Dynamo_Month.may:
183
+ case Dynamo_Month.june:
184
+ case Dynamo_Month.august:
185
+ case Dynamo_Month.october:
186
+ return 31;
187
+
188
+ case Dynamo_Month.april:
189
+ case Dynamo_Month.july:
190
+ case Dynamo_Month.september:
191
+ case Dynamo_Month.november:
192
+ case Dynamo_Month.december:
193
+ return 30;
194
+
195
+ case Dynamo_Month.february:
196
+ return this.isLeapYear(inYear ?? new Date().getFullYear()) ? 29 : 28;
197
+ }
198
+ }
199
+
200
+ /**
201
+ * returns year is leap or not
202
+ * @param year
203
+ * @returns
204
+ */
205
+ static isLeapYear(year: number): boolean {
206
+ return year % 4 === 0;
207
+ }
49
208
  }
@@ -15,6 +15,7 @@ export class Dynamo_Trigonometry {
15
15
  */
16
16
  static getClamp(c: number, angle?: number): number {
17
17
  angle = angle !== undefined ? angle : 45;
18
+
18
19
  return Math.sin(this.angleToRadians(angle)) * c;
19
20
  }
20
21
 
@@ -27,8 +28,13 @@ export class Dynamo_Trigonometry {
27
28
  */
28
29
  static getClampByClampAndHypotenuse(a: number, c: number): number {
29
30
  if (a > c) {
30
- throw { errorMessage: `getClampByClampAndHypotenuse error hypotenuse is smaller than clamp (a:${a} > c:${c})` };
31
+
32
+ throw {
33
+ errorMessage:
34
+ `getClampByClampAndHypotenuse error hypotenuse is smaller than clamp (a:${a} > c:${c})`
35
+ };
31
36
  }
37
+
32
38
  return Math.sqrt((c * c) - (a * a));
33
39
  }
34
40
 
@@ -43,6 +49,7 @@ export class Dynamo_Trigonometry {
43
49
  */
44
50
  static getHypotenuse(a: number, b?: number): number {
45
51
  b = b !== undefined ? b : a;
52
+
46
53
  return Math.sqrt((a * a) + (b * b));
47
54
  }
48
55
 
@@ -0,0 +1,121 @@
1
+
2
+ export type Dynamo_TCF = Dynamo_TypeCloningFacility;
3
+ export type D_TypeCloningFacility = Dynamo_TypeCloningFacility;
4
+ export type D_TCF = Dynamo_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 Dynamo_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,9 +1,18 @@
1
1
 
2
+ const defaultErrorMsg = ' failed. ' +
3
+ '\nThis might be happening becouse the object you trying to clone, ' +
4
+ 'containes object hooks for its own objects, therefore its creating an object loop. ' +
5
+ 'See further information in the detailed error:\n\n';
6
+
2
7
  export function clone<T>(object: T): T {
3
8
  try {
4
9
  return object ? JSON.parse(JSON.stringify(object)) as T : object;
5
10
  } catch (error) {
6
- console.error('clone() failed. This might be happening becouse the object you trying to clone, containes object hooks for its own objects, therefore its creating an object loop. See further information in the detailed error:');
11
+ console.error(
12
+ 'clone()' + defaultErrorMsg,
13
+ error
14
+ );
15
+
7
16
  throw error;
8
17
  }
9
18
  }
@@ -12,12 +21,18 @@ export const copy = clone;
12
21
  export function surfaceClone<T>(object: T): T {
13
22
  try {
14
23
  const result = {};
15
- Object.keys(object).forEach((key: string) => {
24
+
25
+ Object.keys(object).forEach((key: string): void => {
16
26
  result[key] = object[key];
17
27
  });
28
+
18
29
  return result as T;
19
30
  } catch (error) {
20
- console.error('clone() failed. This might be happening becouse the object you trying to clone, containes object hooks for its own objects, therefore its creating an object loop. See further information in the detailed error:');
31
+ console.error(
32
+ 'surfaceClone()' + defaultErrorMsg,
33
+ error
34
+ );
35
+
21
36
  throw error;
22
37
  }
23
38
  }
@@ -27,7 +42,11 @@ export function sameObjects<T>(objA: T, objB: T): boolean {
27
42
  try {
28
43
  return JSON.stringify(objA) === JSON.stringify(objB);
29
44
  } catch (error) {
30
- console.error('sameObjects() failed. This might be happening becouse the object you trying to check, containes object hooks for its own objects, therefore its creating an object loop. See further information in the detailed error:');
45
+ console.error(
46
+ 'sameObjects()' + defaultErrorMsg,
47
+ error
48
+ );
49
+
31
50
  throw error;
32
51
  }
33
52
  }
@@ -46,11 +65,13 @@ export function setExisitngValuesOnly(setOn: any, setTo: any): void {
46
65
  }
47
66
 
48
67
  export function delay(ms: number): Promise<void> {
49
- return new Promise(resolve => setTimeout(resolve, ms) );
68
+ return new Promise((resolve): any => setTimeout(resolve, ms));
50
69
  }
51
70
  export const sleep = delay;
52
71
  export const wait = delay;
53
72
 
73
+ export type Dynamo_SortDirection = 0 | 1 | -1
74
+
54
75
  /**
55
76
  * You might be use getSortForTrueFn instead for a shorter expression
56
77
  *
@@ -62,8 +83,9 @@ export const wait = delay;
62
83
  * @example
63
84
  * codes.sort((a,b) => sortForTrue(a,b,(c: Code) => c.haveImg));
64
85
  */
65
- export function sortForTrue<T>(a: T, b: T, check: (a: T) => boolean): 0 | 1 | -1 {
86
+ export function sortForTrue<T>(a: T, b: T, check: (a: T) => boolean): Dynamo_SortDirection {
66
87
  const isA = check(a);
88
+
67
89
  return isA === check(b) ? 0 : isA ? -1 : 1;
68
90
  }
69
91
 
@@ -75,15 +97,18 @@ export function sortForTrue<T>(a: T, b: T, check: (a: T) => boolean): 0 | 1 | -1
75
97
  * @example
76
98
  * codes.sort(getSortForTrueFn((c: Code) => c.haveImg));
77
99
  */
78
- export function getSortForTrueFn<T>(checkFor: (a: T) => boolean): (a: T, b: T) => 0 | 1 | -1 {
79
- return (a: T, b: T) => sortForTrue<T>(a, b, checkFor);
100
+ export function getSortForTrueFn<T>(
101
+ checkFor: (a: T) => boolean): (a: T, b: T) => Dynamo_SortDirection {
102
+ return (a: T, b: T): Dynamo_SortDirection => sortForTrue<T>(a, b, checkFor);
80
103
  }
81
104
 
82
105
  export function JSONListify<T>(JSONList): T[] {
83
106
  const result: T[] = [];
107
+
84
108
  for (let i = 0; JSONList[i]; i++) {
85
109
  result.push(JSONList[i] as T);
86
110
  }
111
+
87
112
  return result;
88
113
  }
89
114