danholibraryjs 1.11.0 → 2.0.0

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 (204) hide show
  1. package/dist/Classes/DanhoLogger.d.ts +23 -0
  2. package/dist/Classes/DanhoLogger.js +65 -0
  3. package/dist/Classes/Events/Event.d.ts +66 -66
  4. package/dist/Classes/Events/Event.js +114 -114
  5. package/dist/Classes/Events/EventCollection.d.ts +57 -57
  6. package/dist/Classes/Events/EventCollection.js +109 -109
  7. package/dist/Classes/Events/EventEmitter.d.ts +74 -74
  8. package/dist/Classes/Events/EventEmitter.js +97 -97
  9. package/dist/Classes/Events/index.d.ts +3 -3
  10. package/dist/Classes/Events/index.js +19 -19
  11. package/dist/Classes/Time/Date.d.ts +148 -147
  12. package/dist/Classes/Time/Date.js +241 -238
  13. package/dist/Classes/Time/Time.d.ts +66 -65
  14. package/dist/Classes/Time/Time.js +120 -117
  15. package/dist/Classes/Time/TimeProperties.d.ts +3 -3
  16. package/dist/Classes/Time/TimeProperties.js +2 -2
  17. package/dist/Classes/Time/TimeSpan.d.ts +123 -123
  18. package/dist/Classes/Time/TimeSpan.js +179 -179
  19. package/dist/Classes/Time/index.d.ts +4 -4
  20. package/dist/Classes/Time/index.js +20 -20
  21. package/dist/Classes/index.d.ts +4 -3
  22. package/dist/Classes/index.js +20 -19
  23. package/dist/Classes/store.d.ts +75 -75
  24. package/dist/Classes/store.js +84 -84
  25. package/dist/Extensions/Array/array.extension.d.ts +42 -0
  26. package/dist/Extensions/Array/array.extension.js +57 -0
  27. package/dist/Extensions/Array/crud.extension.d.ts +24 -0
  28. package/dist/Extensions/Array/crud.extension.js +28 -0
  29. package/dist/Extensions/Array/index.d.ts +20 -0
  30. package/dist/Extensions/Array/index.js +40 -0
  31. package/dist/Extensions/Array/loop.extension.d.ts +18 -0
  32. package/dist/Extensions/Array/loop.extension.js +23 -0
  33. package/dist/Extensions/Array/random.extension.d.ts +23 -0
  34. package/dist/Extensions/Array/random.extension.js +35 -0
  35. package/dist/Extensions/Array/sort.extension.d.ts +27 -0
  36. package/dist/Extensions/Array/sort.extension.js +31 -0
  37. package/dist/Extensions/Array/string.extension.d.ts +13 -0
  38. package/dist/Extensions/Array/string.extension.js +14 -0
  39. package/dist/Extensions/Array.d.ts +52 -52
  40. package/dist/Extensions/Array.js +51 -51
  41. package/dist/Extensions/Document.d.ts +27 -27
  42. package/dist/Extensions/Document.js +32 -32
  43. package/dist/Extensions/Function.d.ts +29 -14
  44. package/dist/Extensions/Function.js +23 -10
  45. package/dist/Extensions/Map.d.ts +54 -54
  46. package/dist/Extensions/Map.js +42 -42
  47. package/dist/Extensions/Number.d.ts +13 -0
  48. package/dist/Extensions/Number.js +40 -0
  49. package/dist/Extensions/Object/arrays.extension.d.ts +17 -0
  50. package/dist/Extensions/Object/arrays.extension.js +13 -0
  51. package/dist/Extensions/Object/booleans.extension.d.ts +18 -0
  52. package/dist/Extensions/Object/booleans.extension.js +37 -0
  53. package/dist/Extensions/Object/extracts.extension.d.ts +38 -0
  54. package/dist/Extensions/Object/extracts.extension.js +72 -0
  55. package/dist/Extensions/Object/index.d.ts +10 -49
  56. package/dist/Extensions/Object/index.js +36 -38
  57. package/dist/Extensions/Object/properties.d.ts +28 -28
  58. package/dist/Extensions/Object/properties.extension.d.ts +6 -0
  59. package/dist/Extensions/Object/properties.extension.js +4 -0
  60. package/dist/Extensions/Object/properties.js +19 -20
  61. package/dist/Extensions/String/case.extension.d.ts +12 -0
  62. package/dist/Extensions/String/case.extension.js +55 -0
  63. package/dist/Extensions/String/index.d.ts +4 -0
  64. package/dist/Extensions/String/index.js +30 -0
  65. package/dist/Extensions/String.d.ts +36 -36
  66. package/dist/Extensions/String.js +25 -25
  67. package/dist/Extensions/index.d.ts +6 -17
  68. package/dist/Extensions/index.js +22 -30
  69. package/dist/Functions/CopyToClipboard.d.ts +7 -7
  70. package/dist/Functions/CopyToClipboard.js +15 -15
  71. package/dist/Functions/GetCSSProperty.d.ts +15 -15
  72. package/dist/Functions/GetCSSProperty.js +26 -26
  73. package/dist/Functions/GetNestedProperty.d.ts +9 -9
  74. package/dist/Functions/GetNestedProperty.js +23 -23
  75. package/dist/Functions/HTMLEvent.d.ts +11 -11
  76. package/dist/Functions/HTMLEvent.js +14 -14
  77. package/dist/Functions/SetNavigationSelected.d.ts +9 -9
  78. package/dist/Functions/SetNavigationSelected.js +25 -25
  79. package/dist/Functions/index.d.ts +5 -5
  80. package/dist/Functions/index.js +21 -21
  81. package/dist/Interfaces/ElementOptions.d.ts +15 -15
  82. package/dist/Interfaces/ElementOptions.js +2 -2
  83. package/dist/Interfaces/IReplacement.d.ts +12 -12
  84. package/dist/Interfaces/IReplacement.js +2 -2
  85. package/dist/Interfaces/index.d.ts +2 -2
  86. package/dist/Interfaces/index.js +18 -18
  87. package/dist/Types/Able.d.ts +16 -0
  88. package/dist/Types/Able.js +2 -0
  89. package/dist/Types/Array.d.ts +6 -0
  90. package/dist/Types/Array.js +2 -0
  91. package/dist/Types/BetterTypes.d.ts +9 -9
  92. package/dist/Types/BetterTypes.js +2 -2
  93. package/dist/Types/C#.d.ts +8 -0
  94. package/dist/Types/C#.js +2 -0
  95. package/dist/Types/Date.d.ts +6 -6
  96. package/dist/Types/Date.js +2 -2
  97. package/dist/Types/Events.d.ts +10 -10
  98. package/dist/Types/Events.js +2 -2
  99. package/dist/Types/Function.d.ts +5 -0
  100. package/dist/Types/Function.js +2 -0
  101. package/dist/Types/Object.d.ts +4 -0
  102. package/dist/Types/Object.js +2 -0
  103. package/dist/Types/PropertiesWith.d.ts +34 -13
  104. package/dist/Types/PropertiesWith.js +2 -2
  105. package/dist/Types/String.d.ts +1 -0
  106. package/dist/Types/String.js +2 -0
  107. package/dist/Types/TransformTypes.d.ts +22 -16
  108. package/dist/Types/TransformTypes.js +2 -2
  109. package/dist/Types/index.d.ts +24 -65
  110. package/dist/Types/index.js +27 -21
  111. package/dist/Utils/ApiUtil/ApiTypes.d.ts +15 -15
  112. package/dist/Utils/ApiUtil/ApiTypes.js +15 -15
  113. package/dist/Utils/ApiUtil/RequestUtil.d.ts +19 -19
  114. package/dist/Utils/ApiUtil/RequestUtil.js +73 -73
  115. package/dist/Utils/ApiUtil/index.d.ts +20 -20
  116. package/dist/Utils/ApiUtil/index.js +33 -33
  117. package/dist/Utils/ApiUtils/ApiTypes.d.ts +15 -0
  118. package/dist/Utils/ApiUtils/ApiTypes.js +15 -0
  119. package/dist/Utils/ApiUtils/RequestUtil.d.ts +19 -0
  120. package/dist/Utils/ApiUtils/RequestUtil.js +73 -0
  121. package/dist/Utils/ApiUtils/index.d.ts +20 -0
  122. package/dist/Utils/ApiUtils/index.js +33 -0
  123. package/dist/Utils/ColorUtils.d.ts +11 -0
  124. package/dist/Utils/ColorUtils.js +93 -0
  125. package/dist/Utils/FormUtil.d.ts +6 -6
  126. package/dist/Utils/FormUtil.js +35 -35
  127. package/dist/Utils/FormUtils.d.ts +6 -0
  128. package/dist/Utils/FormUtils.js +35 -0
  129. package/dist/Utils/NumberUtils.d.ts +1 -0
  130. package/dist/Utils/NumberUtils.js +7 -0
  131. package/dist/Utils/PatcherUtils.d.ts +6 -0
  132. package/dist/Utils/PatcherUtils.js +80 -0
  133. package/dist/Utils/StringUtils.d.ts +3 -0
  134. package/dist/Utils/StringUtils.js +47 -0
  135. package/dist/Utils/TimeUtils/debounce.util.d.ts +22 -0
  136. package/dist/Utils/TimeUtils/debounce.util.js +78 -0
  137. package/dist/Utils/TimeUtils/functions.util.d.ts +4 -0
  138. package/dist/Utils/TimeUtils/functions.util.js +21 -0
  139. package/dist/Utils/TimeUtils/index.d.ts +15 -0
  140. package/dist/Utils/TimeUtils/index.js +34 -0
  141. package/dist/Utils/TimeUtils/throttle.util.d.ts +15 -0
  142. package/dist/Utils/TimeUtils/throttle.util.js +43 -0
  143. package/dist/Utils/index.d.ts +7 -2
  144. package/dist/Utils/index.js +23 -18
  145. package/dist/index.d.ts +5 -5
  146. package/dist/index.js +21 -21
  147. package/package.json +4 -2
  148. package/src/Classes/DanhoLogger.ts +78 -0
  149. package/src/Classes/Events/Event.ts +96 -96
  150. package/src/Classes/Events/EventCollection.ts +90 -90
  151. package/src/Classes/Events/EventEmitter.ts +68 -68
  152. package/src/Classes/Time/Date.ts +219 -216
  153. package/src/Classes/Time/Time.ts +109 -104
  154. package/src/Classes/Time/TimeSpan.ts +171 -171
  155. package/src/Classes/index.ts +1 -0
  156. package/src/Classes/store.ts +22 -22
  157. package/src/Extensions/Array/array.extension.ts +103 -0
  158. package/src/Extensions/Array/crud.extension.ts +46 -0
  159. package/src/Extensions/Array/index.ts +15 -0
  160. package/src/Extensions/Array/loop.extension.ts +38 -0
  161. package/src/Extensions/Array/random.extension.ts +56 -0
  162. package/src/Extensions/Array/sort.extension.ts +52 -0
  163. package/src/Extensions/Array/string.extension.ts +22 -0
  164. package/src/Extensions/Document.ts +39 -39
  165. package/src/Extensions/Function.ts +37 -10
  166. package/src/Extensions/Map.ts +56 -56
  167. package/src/Extensions/Number.ts +50 -0
  168. package/src/Extensions/Object/arrays.extension.ts +27 -0
  169. package/src/Extensions/Object/booleans.extension.ts +46 -0
  170. package/src/Extensions/Object/extracts.extension.ts +102 -0
  171. package/src/Extensions/Object/index.ts +9 -80
  172. package/src/Extensions/Object/properties.extension.ts +11 -0
  173. package/src/Extensions/Object/properties.ts +35 -36
  174. package/src/Extensions/String/case.extension.ts +95 -0
  175. package/src/Extensions/String/index.ts +5 -0
  176. package/src/Extensions/index.ts +2 -20
  177. package/src/Interfaces/ElementOptions.ts +7 -7
  178. package/src/Interfaces/IReplacement.ts +2 -2
  179. package/src/Types/Able.ts +22 -0
  180. package/src/Types/Array.ts +7 -0
  181. package/src/Types/C#.ts +9 -0
  182. package/src/Types/Date.ts +1 -1
  183. package/src/Types/Events.ts +12 -12
  184. package/src/Types/Function.ts +10 -0
  185. package/src/Types/Object.ts +4 -0
  186. package/src/Types/PropertiesWith.ts +35 -4
  187. package/src/Types/String.ts +1 -0
  188. package/src/Types/TransformTypes.ts +21 -13
  189. package/src/Types/index.ts +7 -69
  190. package/src/Utils/{ApiUtil → ApiUtils}/ApiTypes.ts +2 -1
  191. package/src/Utils/{ApiUtil → ApiUtils}/index.ts +1 -1
  192. package/src/Utils/ColorUtils.ts +102 -0
  193. package/src/Utils/{FormUtil.ts → FormUtils.ts} +2 -2
  194. package/src/Utils/NumberUtils.ts +3 -0
  195. package/src/Utils/PatcherUtils.ts +111 -0
  196. package/src/Utils/StringUtils.ts +44 -0
  197. package/src/Utils/TimeUtils/debounce.util.ts +85 -0
  198. package/src/Utils/TimeUtils/functions.util.ts +18 -0
  199. package/src/Utils/TimeUtils/index.ts +9 -0
  200. package/src/Utils/TimeUtils/throttle.util.ts +44 -0
  201. package/src/Utils/index.ts +8 -2
  202. package/src/Extensions/Array.ts +0 -95
  203. package/src/Extensions/String.ts +0 -54
  204. /package/src/Utils/{ApiUtil → ApiUtils}/RequestUtil.ts +0 -0
@@ -1,179 +1,179 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TimeSpan = void 0;
7
- const Date_1 = __importDefault(require("./Date"));
8
- const Time_1 = __importDefault(require("./Time"));
9
- /**
10
- * Timespan between 2 dates.
11
- * @borrows TimeSpanValue
12
- * @borrows Time
13
- * @borrows TimeProperties
14
- */
15
- class TimeSpan {
16
- constructor(from, to = Date.now()) {
17
- //General properties
18
- this.from = new Date_1.default(from);
19
- this.to = new Date_1.default(to);
20
- //Ensure from < to
21
- this._highest = this.from.time > this.to.time ? this.from : this.to;
22
- this._lowest = this.from == this._highest ? this.to : this.from;
23
- this.pastTense = this._highest !== this.to;
24
- this._highest = new Date_1.default(this._highest.time + Time_1.default.millisecond);
25
- let timeDifference = this._getTimeDifference();
26
- //Calculate time difference between from & to and set to object properties
27
- [this.years, timeDifference] = this._reduceTime(Time_1.default.year, timeDifference);
28
- [this.months, timeDifference] = this._reduceTime(Time_1.default.month, timeDifference);
29
- [this.weeks, timeDifference] = this._reduceTime(Time_1.default.week, timeDifference);
30
- [this.days, timeDifference] = this._reduceTime(Time_1.default.day, timeDifference);
31
- [this.hours, timeDifference] = this._reduceTime(Time_1.default.hour, timeDifference);
32
- [this.minutes, timeDifference] = this._reduceTime(Time_1.default.minute, timeDifference);
33
- [this.seconds, timeDifference] = this._reduceTime(Time_1.default.second, timeDifference);
34
- [this.milliseconds, timeDifference] = this._reduceTime(Time_1.default.millisecond, timeDifference);
35
- }
36
- /**
37
- * Which of the dates in constructor had the highest getTime()
38
- */
39
- _highest;
40
- /**
41
- * Which of the dates in constructor had the lowest getTime()
42
- */
43
- _lowest;
44
- /**
45
- * The time difference between highest and lowest
46
- * @returns Time difference in ms between this._highest and this._lowest
47
- */
48
- _getTimeDifference() {
49
- return Math.round(this._highest.time - this._lowest.time);
50
- }
51
- /**
52
- * Reduces ms into provided timeDifference
53
- * @param ms Millisecond value to reduce
54
- * @param timeDifference Time difference in ms that for each timeDifference in ms, add 1 to result
55
- * @returns How many times timeDifference fits in ms
56
- */
57
- _reduceTime(ms, timeDifference) {
58
- let result = 0;
59
- while (timeDifference > ms) {
60
- timeDifference -= ms;
61
- result++;
62
- }
63
- return [result, timeDifference];
64
- }
65
- /**
66
- * Total years between dates
67
- */
68
- years;
69
- /**
70
- * Total months between dates
71
- */
72
- months;
73
- /**
74
- * Total weeks between dates
75
- */
76
- weeks;
77
- /**
78
- * Total days between dates
79
- */
80
- days;
81
- /**
82
- * Total hours between dates
83
- */
84
- hours;
85
- /**
86
- * Total minutes between dates
87
- */
88
- minutes;
89
- /**
90
- * Total seconds between dates
91
- */
92
- seconds;
93
- /**
94
- * Total milliseconds between dates
95
- */
96
- milliseconds;
97
- /**
98
- * Get the total unit time between the two dates
99
- * @param unit Time unit in milliseconds
100
- * @returns How many times that unit fits in total ms between the two dates
101
- */
102
- _getTotalUnit(unit) {
103
- return this._reduceTime(unit, this._getTimeDifference())[0];
104
- }
105
- /**
106
- * Get the maximum amount of months between the two dates
107
- * @returns Number of max amount of months that are between the two dates
108
- */
109
- getTotalMonths() {
110
- return this._getTotalUnit(Time_1.default.month);
111
- }
112
- /**
113
- * Get the maximum amount of weeks between the two dates
114
- * @returns Number of max amount of weeks that are between the two dates
115
- */
116
- getTotalWeeks() {
117
- return this._getTotalUnit(Time_1.default.week);
118
- }
119
- /**
120
- * Get the maximum amount of days between the two dates
121
- * @returns Number of max amount of days that are between the two dates
122
- */
123
- getTotalDays() {
124
- return this._getTotalUnit(Time_1.default.day);
125
- }
126
- /**
127
- * Get the maximum amount of hours between the two dates
128
- * @returns Number of max amount of hours that are between the two dates
129
- */
130
- getTotalHours() {
131
- return this._getTotalUnit(Time_1.default.hour);
132
- }
133
- /**
134
- * Get the maximum amount of minutes between the two dates
135
- * @returns Number of max amount of minutes that are between the two dates
136
- */
137
- getTotalMinutes() {
138
- return this._getTotalUnit(Time_1.default.minute);
139
- }
140
- /**
141
- * Get the maximum amount of seconds between the two dates
142
- * @returns Number of max amount of seconds that are between the two dates
143
- */
144
- getTotalSeconds() {
145
- return this._getTotalUnit(Time_1.default.second);
146
- }
147
- /**
148
- * Get the maximum amount of milliseconds between the two dates
149
- * @returns Number of max amount of milliseconds that are between the two dates
150
- */
151
- getTotalMilliseconds() {
152
- return this._getTotalUnit(Time_1.default.millisecond);
153
- }
154
- /**
155
- * Start date of timespan
156
- */
157
- from;
158
- /**
159
- * End date of timespan
160
- */
161
- to;
162
- /**
163
- * Timespan is in the past
164
- */
165
- pastTense;
166
- toString(format) {
167
- //console.log(`${this.years}Y ${this.months}M ${this.weeks}w ${this.days}d ${this.hours}h ${this.minutes}m ${this.seconds}s ${this.milliseconds}ms`);
168
- const times = [this.years, this.months, this.weeks, this.days, this.hours, this.minutes, this.seconds, this.milliseconds];
169
- const timeMsg = ["year", "month", "week", "day", "hour", "minute", "second", "millisecond"];
170
- const result = times.reduce((result, time, i) => (
171
- // If time is above 0, format is provided, a property matches current property and said property is true, append addition else return result
172
- time > 0 && (format ? timeMsg[i] in format && format[timeMsg[i]] === true : true) ?
173
- `${result}${times[i]} ${timeMsg[i]}${times[i] != 1 ? 's' : ''}, ` :
174
- result), '');
175
- return result.length > 2 && result.substring(0, result.length - 2) || '';
176
- }
177
- }
178
- exports.TimeSpan = TimeSpan;
179
- exports.default = TimeSpan;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TimeSpan = void 0;
7
+ const Date_1 = __importDefault(require("./Date"));
8
+ const Time_1 = __importDefault(require("./Time"));
9
+ /**
10
+ * Timespan between 2 dates.
11
+ * @borrows TimeSpanValue
12
+ * @borrows Time
13
+ * @borrows TimeProperties
14
+ */
15
+ class TimeSpan {
16
+ constructor(from, to = Date.now()) {
17
+ //General properties
18
+ this.from = new Date_1.default(from);
19
+ this.to = new Date_1.default(to);
20
+ //Ensure from < to
21
+ this._highest = this.from.time > this.to.time ? this.from : this.to;
22
+ this._lowest = this.from == this._highest ? this.to : this.from;
23
+ this.pastTense = this._highest !== this.to;
24
+ this._highest = new Date_1.default(this._highest.time + Time_1.default.millisecond);
25
+ let timeDifference = this._getTimeDifference();
26
+ //Calculate time difference between from & to and set to object properties
27
+ [this.years, timeDifference] = this._reduceTime(Time_1.default.year, timeDifference);
28
+ [this.months, timeDifference] = this._reduceTime(Time_1.default.month, timeDifference);
29
+ [this.weeks, timeDifference] = this._reduceTime(Time_1.default.week, timeDifference);
30
+ [this.days, timeDifference] = this._reduceTime(Time_1.default.day, timeDifference);
31
+ [this.hours, timeDifference] = this._reduceTime(Time_1.default.hour, timeDifference);
32
+ [this.minutes, timeDifference] = this._reduceTime(Time_1.default.minute, timeDifference);
33
+ [this.seconds, timeDifference] = this._reduceTime(Time_1.default.second, timeDifference);
34
+ [this.milliseconds, timeDifference] = this._reduceTime(Time_1.default.millisecond, timeDifference);
35
+ }
36
+ /**
37
+ * Which of the dates in constructor had the highest getTime()
38
+ */
39
+ _highest;
40
+ /**
41
+ * Which of the dates in constructor had the lowest getTime()
42
+ */
43
+ _lowest;
44
+ /**
45
+ * The time difference between highest and lowest
46
+ * @returns Time difference in ms between this._highest and this._lowest
47
+ */
48
+ _getTimeDifference() {
49
+ return Math.round(this._highest.time - this._lowest.time);
50
+ }
51
+ /**
52
+ * Reduces ms into provided timeDifference
53
+ * @param ms Millisecond value to reduce
54
+ * @param timeDifference Time difference in ms that for each timeDifference in ms, add 1 to result
55
+ * @returns How many times timeDifference fits in ms
56
+ */
57
+ _reduceTime(ms, timeDifference) {
58
+ let result = 0;
59
+ while (timeDifference > ms) {
60
+ timeDifference -= ms;
61
+ result++;
62
+ }
63
+ return [result, timeDifference];
64
+ }
65
+ /**
66
+ * Total years between dates
67
+ */
68
+ years;
69
+ /**
70
+ * Total months between dates
71
+ */
72
+ months;
73
+ /**
74
+ * Total weeks between dates
75
+ */
76
+ weeks;
77
+ /**
78
+ * Total days between dates
79
+ */
80
+ days;
81
+ /**
82
+ * Total hours between dates
83
+ */
84
+ hours;
85
+ /**
86
+ * Total minutes between dates
87
+ */
88
+ minutes;
89
+ /**
90
+ * Total seconds between dates
91
+ */
92
+ seconds;
93
+ /**
94
+ * Total milliseconds between dates
95
+ */
96
+ milliseconds;
97
+ /**
98
+ * Get the total unit time between the two dates
99
+ * @param unit Time unit in milliseconds
100
+ * @returns How many times that unit fits in total ms between the two dates
101
+ */
102
+ _getTotalUnit(unit) {
103
+ return this._reduceTime(unit, this._getTimeDifference())[0];
104
+ }
105
+ /**
106
+ * Get the maximum amount of months between the two dates
107
+ * @returns Number of max amount of months that are between the two dates
108
+ */
109
+ getTotalMonths() {
110
+ return this._getTotalUnit(Time_1.default.month);
111
+ }
112
+ /**
113
+ * Get the maximum amount of weeks between the two dates
114
+ * @returns Number of max amount of weeks that are between the two dates
115
+ */
116
+ getTotalWeeks() {
117
+ return this._getTotalUnit(Time_1.default.week);
118
+ }
119
+ /**
120
+ * Get the maximum amount of days between the two dates
121
+ * @returns Number of max amount of days that are between the two dates
122
+ */
123
+ getTotalDays() {
124
+ return this._getTotalUnit(Time_1.default.day);
125
+ }
126
+ /**
127
+ * Get the maximum amount of hours between the two dates
128
+ * @returns Number of max amount of hours that are between the two dates
129
+ */
130
+ getTotalHours() {
131
+ return this._getTotalUnit(Time_1.default.hour);
132
+ }
133
+ /**
134
+ * Get the maximum amount of minutes between the two dates
135
+ * @returns Number of max amount of minutes that are between the two dates
136
+ */
137
+ getTotalMinutes() {
138
+ return this._getTotalUnit(Time_1.default.minute);
139
+ }
140
+ /**
141
+ * Get the maximum amount of seconds between the two dates
142
+ * @returns Number of max amount of seconds that are between the two dates
143
+ */
144
+ getTotalSeconds() {
145
+ return this._getTotalUnit(Time_1.default.second);
146
+ }
147
+ /**
148
+ * Get the maximum amount of milliseconds between the two dates
149
+ * @returns Number of max amount of milliseconds that are between the two dates
150
+ */
151
+ getTotalMilliseconds() {
152
+ return this._getTotalUnit(Time_1.default.millisecond);
153
+ }
154
+ /**
155
+ * Start date of timespan
156
+ */
157
+ from;
158
+ /**
159
+ * End date of timespan
160
+ */
161
+ to;
162
+ /**
163
+ * Timespan is in the past
164
+ */
165
+ pastTense;
166
+ toString(format) {
167
+ //console.log(`${this.years}Y ${this.months}M ${this.weeks}w ${this.days}d ${this.hours}h ${this.minutes}m ${this.seconds}s ${this.milliseconds}ms`);
168
+ const times = [this.years, this.months, this.weeks, this.days, this.hours, this.minutes, this.seconds, this.milliseconds];
169
+ const timeMsg = ["year", "month", "week", "day", "hour", "minute", "second", "millisecond"];
170
+ const result = times.reduce((result, time, i) => (
171
+ // If time is above 0, format is provided, a property matches current property and said property is true, append addition else return result
172
+ time > 0 && (format ? timeMsg[i] in format && format[timeMsg[i]] === true : true) ?
173
+ `${result}${times[i]} ${timeMsg[i]}${times[i] != 1 ? 's' : ''}, ` :
174
+ result), '');
175
+ return result.length > 2 && result.substring(0, result.length - 2) || '';
176
+ }
177
+ }
178
+ exports.TimeSpan = TimeSpan;
179
+ exports.default = TimeSpan;
@@ -1,4 +1,4 @@
1
- export * from './Date';
2
- export * from './Time';
3
- export * from './TimeProperties';
4
- export * from './TimeSpan';
1
+ export * from './Date';
2
+ export * from './Time';
3
+ export * from './TimeProperties';
4
+ export * from './TimeSpan';
@@ -1,20 +1,20 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Date"), exports);
18
- __exportStar(require("./Time"), exports);
19
- __exportStar(require("./TimeProperties"), exports);
20
- __exportStar(require("./TimeSpan"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Date"), exports);
18
+ __exportStar(require("./Time"), exports);
19
+ __exportStar(require("./TimeProperties"), exports);
20
+ __exportStar(require("./TimeSpan"), exports);
@@ -1,3 +1,4 @@
1
- export * from './Events';
2
- export * from './Time';
3
- export * from './store';
1
+ export * from './Events';
2
+ export * from './Time';
3
+ export * from './DanhoLogger';
4
+ export * from './store';
@@ -1,19 +1,20 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Events"), exports);
18
- __exportStar(require("./Time"), exports);
19
- __exportStar(require("./store"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Events"), exports);
18
+ __exportStar(require("./Time"), exports);
19
+ __exportStar(require("./DanhoLogger"), exports);
20
+ __exportStar(require("./store"), exports);
@@ -1,75 +1,75 @@
1
- import { Arrayable } from "../Types";
2
- import { EventEmitter } from "./Events";
3
- export type Reducer<State, Types extends Record<string, any[]>, Action extends keyof Types> = (state: State, ...args: Types[Action]) => State;
4
- export type Actions<State, ActionTypes extends Record<string, any[]>> = {
5
- [Action in keyof ActionTypes]?: Arrayable<Reducer<State, ActionTypes, Action>>;
6
- };
7
- /**
8
- * EventEmitter, but it stores state and handles state change with reducers
9
- *
10
- * @Initialization Actions & initial state must be defined in type parameters. InitialState must be provided in constructor, whereas reducer is optional.
11
- * The ActionType must have properties as strings and values as arrays.
12
- *
13
- * @HandlingActions Reducers can be added through constructor or using Store.on('action', reducer) or Store.once('action', reducer).
14
- * Every state change must return the next state, apart from 'stateChange', which returns void/any
15
- * Emit/Dispatch an action using Store.dispatch('action', ...args), ...args being the parameters from the ActionType.
16
- * Store.emit should NOT be used, as it doesn't update the Store's state.
17
- *
18
- * Reducer functions can be removed using Store.off('action', reducer);
19
- *
20
- * @borrows EventEmitter
21
- * @borrows Arrayable
22
- *
23
- * @example ```ts
24
- * import { Store } from 'danholibraryjs';
25
- *
26
- * type Todo = {
27
- * id: string,
28
- * text: string,
29
- * completed: boolean
30
- * }
31
- *
32
- * type TodoActions = {
33
- * create: [text: string],
34
- * update: [id: string, text: string],
35
- * toggleComplete: [id: string, force?: boolean],
36
- * delete: [id: string],
37
- * }
38
- *
39
- * const store = new Store<Array<Todo>, TodoActions>(new Array<Todo>(), new Map([
40
- * create: (state, text) => {
41
- * return [...state, {
42
- * id: Math.random().toString(),
43
- * text,
44
- * completed: false
45
- * }];
46
- * },
47
- * toggleComplete: (state, id, force) => {
48
- * const todo = state.find(todo => todo.id === id);
49
- * if (!todo) return state;
50
- *
51
- * return state.map(todo => (
52
- * todo.id === id ? {
53
- * ...todo,
54
- * completed: force === undefined ? !todo.completed : force
55
- * } : todo
56
- * ));
57
- * }
58
- * ]));
59
- *
60
- * store.on('delete', (state, id) => {
61
- * return state.filter(todo => todo.id !== id);
62
- * });
63
- *
64
- * store.on('stateChange', (prevState, currentState) => console.log('State change', prevState, currentState));
65
- *
66
- * store.dispatch('create', 'Make store!');
67
- *
68
- * ```
69
- */
70
- export declare class Store<State extends object, ActionTypes extends Record<string, any[]>, StoreActions extends Actions<State, ActionTypes> = Actions<State, ActionTypes>> extends EventEmitter<Record<keyof StoreActions, ActionTypes[keyof ActionTypes]> & Record<'stateChange', [previous: State, current: State]>> {
71
- constructor(state: State, actions?: StoreActions);
72
- private _state;
73
- get state(): State;
74
- dispatch<Action extends keyof ActionTypes>(action: Action, ...args: ActionTypes[Action]): State;
75
- }
1
+ import { Arrayable } from "../Types";
2
+ import { EventEmitter } from "./Events";
3
+ export type Reducer<State, Types extends Record<string, any[]>, Action extends keyof Types> = (state: State, ...args: Types[Action]) => State;
4
+ export type Actions<State, ActionTypes extends Record<string, any[]>> = {
5
+ [Action in keyof ActionTypes]?: Arrayable<Reducer<State, ActionTypes, Action>>;
6
+ };
7
+ /**
8
+ * EventEmitter, but it stores state and handles state change with reducers
9
+ *
10
+ * @Initialization Actions & initial state must be defined in type parameters. InitialState must be provided in constructor, whereas reducer is optional.
11
+ * The ActionType must have properties as strings and values as arrays.
12
+ *
13
+ * @HandlingActions Reducers can be added through constructor or using Store.on('action', reducer) or Store.once('action', reducer).
14
+ * Every state change must return the next state, apart from 'stateChange', which returns void/any
15
+ * Emit/Dispatch an action using Store.dispatch('action', ...args), ...args being the parameters from the ActionType.
16
+ * Store.emit should NOT be used, as it doesn't update the Store's state.
17
+ *
18
+ * Reducer functions can be removed using Store.off('action', reducer);
19
+ *
20
+ * @borrows EventEmitter
21
+ * @borrows Arrayable
22
+ *
23
+ * @example ```ts
24
+ * import { Store } from 'danholibraryjs';
25
+ *
26
+ * type Todo = {
27
+ * id: string,
28
+ * text: string,
29
+ * completed: boolean
30
+ * }
31
+ *
32
+ * type TodoActions = {
33
+ * create: [text: string],
34
+ * update: [id: string, text: string],
35
+ * toggleComplete: [id: string, force?: boolean],
36
+ * delete: [id: string],
37
+ * }
38
+ *
39
+ * const store = new Store<Array<Todo>, TodoActions>(new Array<Todo>(), new Map([
40
+ * create: (state, text) => {
41
+ * return [...state, {
42
+ * id: Math.random().toString(),
43
+ * text,
44
+ * completed: false
45
+ * }];
46
+ * },
47
+ * toggleComplete: (state, id, force) => {
48
+ * const todo = state.find(todo => todo.id === id);
49
+ * if (!todo) return state;
50
+ *
51
+ * return state.map(todo => (
52
+ * todo.id === id ? {
53
+ * ...todo,
54
+ * completed: force === undefined ? !todo.completed : force
55
+ * } : todo
56
+ * ));
57
+ * }
58
+ * ]));
59
+ *
60
+ * store.on('delete', (state, id) => {
61
+ * return state.filter(todo => todo.id !== id);
62
+ * });
63
+ *
64
+ * store.on('stateChange', (prevState, currentState) => console.log('State change', prevState, currentState));
65
+ *
66
+ * store.dispatch('create', 'Make store!');
67
+ *
68
+ * ```
69
+ */
70
+ export declare class Store<State extends object, ActionTypes extends Record<string, any[]>, StoreActions extends Actions<State, ActionTypes> = Actions<State, ActionTypes>> extends EventEmitter<Record<keyof StoreActions, ActionTypes[keyof ActionTypes]> & Record<'stateChange', [previous: State, current: State]>> {
71
+ constructor(state: State, actions?: StoreActions);
72
+ private _state;
73
+ get state(): State;
74
+ dispatch<Action extends keyof ActionTypes>(action: Action, ...args: ActionTypes[Action]): State;
75
+ }