danholibraryjs 1.10.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 (158) hide show
  1. package/dist/Classes/DanhoLogger.d.ts +23 -0
  2. package/dist/Classes/DanhoLogger.js +65 -0
  3. package/dist/Classes/Events/EventEmitter.d.ts +1 -1
  4. package/dist/Classes/Events/EventEmitter.js +1 -1
  5. package/dist/Classes/Time/Date.d.ts +1 -0
  6. package/dist/Classes/Time/Date.js +4 -1
  7. package/dist/Classes/Time/Time.d.ts +5 -4
  8. package/dist/Classes/Time/Time.js +7 -4
  9. package/dist/Classes/index.d.ts +1 -0
  10. package/dist/Classes/index.js +1 -0
  11. package/dist/Classes/store.d.ts +5 -9
  12. package/dist/Extensions/Array/array.extension.d.ts +42 -0
  13. package/dist/Extensions/Array/array.extension.js +57 -0
  14. package/dist/Extensions/Array/crud.extension.d.ts +24 -0
  15. package/dist/Extensions/Array/crud.extension.js +28 -0
  16. package/dist/Extensions/Array/index.d.ts +20 -0
  17. package/dist/Extensions/Array/index.js +40 -0
  18. package/dist/Extensions/Array/loop.extension.d.ts +18 -0
  19. package/dist/Extensions/Array/loop.extension.js +23 -0
  20. package/dist/Extensions/Array/random.extension.d.ts +23 -0
  21. package/dist/Extensions/Array/random.extension.js +35 -0
  22. package/dist/Extensions/Array/sort.extension.d.ts +27 -0
  23. package/dist/Extensions/Array/sort.extension.js +31 -0
  24. package/dist/Extensions/Array/string.extension.d.ts +13 -0
  25. package/dist/Extensions/Array/string.extension.js +14 -0
  26. package/dist/Extensions/Array.d.ts +17 -3
  27. package/dist/Extensions/Array.js +0 -12
  28. package/dist/Extensions/Function.d.ts +17 -2
  29. package/dist/Extensions/Function.js +15 -2
  30. package/dist/Extensions/Number.d.ts +13 -0
  31. package/dist/Extensions/Number.js +40 -0
  32. package/dist/Extensions/Object/arrays.extension.d.ts +17 -0
  33. package/dist/Extensions/Object/arrays.extension.js +13 -0
  34. package/dist/Extensions/Object/booleans.extension.d.ts +18 -0
  35. package/dist/Extensions/Object/booleans.extension.js +37 -0
  36. package/dist/Extensions/Object/extracts.extension.d.ts +38 -0
  37. package/dist/Extensions/Object/extracts.extension.js +72 -0
  38. package/dist/Extensions/Object/index.d.ts +8 -47
  39. package/dist/Extensions/Object/index.js +31 -33
  40. package/dist/Extensions/Object/properties.extension.d.ts +6 -0
  41. package/dist/Extensions/Object/properties.extension.js +4 -0
  42. package/dist/Extensions/Object/properties.js +1 -2
  43. package/dist/Extensions/String/case.extension.d.ts +12 -0
  44. package/dist/Extensions/String/case.extension.js +55 -0
  45. package/dist/Extensions/String/index.d.ts +4 -0
  46. package/dist/Extensions/String/index.js +30 -0
  47. package/dist/Extensions/index.d.ts +1 -12
  48. package/dist/Extensions/index.js +1 -9
  49. package/dist/Types/Able.d.ts +16 -0
  50. package/dist/Types/Able.js +2 -0
  51. package/dist/Types/Array.d.ts +6 -0
  52. package/dist/Types/Array.js +2 -0
  53. package/dist/Types/C#.d.ts +8 -0
  54. package/dist/Types/C#.js +2 -0
  55. package/dist/Types/Date.d.ts +1 -1
  56. package/dist/Types/Events.d.ts +2 -2
  57. package/dist/Types/Function.d.ts +5 -0
  58. package/dist/Types/Function.js +2 -0
  59. package/dist/Types/Object.d.ts +4 -0
  60. package/dist/Types/Object.js +2 -0
  61. package/dist/Types/PropertiesWith.d.ts +21 -0
  62. package/dist/Types/String.d.ts +1 -0
  63. package/dist/Types/String.js +2 -0
  64. package/dist/Types/TransformTypes.d.ts +9 -0
  65. package/dist/Types/index.d.ts +6 -28
  66. package/dist/Types/index.js +6 -0
  67. package/dist/Utils/ApiUtil/ApiTypes.d.ts +15 -0
  68. package/dist/Utils/ApiUtil/ApiTypes.js +15 -0
  69. package/dist/Utils/ApiUtil/RequestUtil.d.ts +19 -0
  70. package/dist/Utils/ApiUtil/RequestUtil.js +73 -0
  71. package/dist/Utils/ApiUtil/index.d.ts +20 -0
  72. package/dist/Utils/ApiUtil/index.js +33 -0
  73. package/dist/Utils/ApiUtils/ApiTypes.d.ts +15 -0
  74. package/dist/Utils/ApiUtils/ApiTypes.js +15 -0
  75. package/dist/Utils/ApiUtils/RequestUtil.d.ts +19 -0
  76. package/dist/Utils/ApiUtils/RequestUtil.js +73 -0
  77. package/dist/Utils/ApiUtils/index.d.ts +20 -0
  78. package/dist/Utils/ApiUtils/index.js +33 -0
  79. package/dist/Utils/ColorUtils.d.ts +11 -0
  80. package/dist/Utils/ColorUtils.js +93 -0
  81. package/dist/Utils/FormUtil.d.ts +6 -0
  82. package/dist/Utils/FormUtil.js +35 -0
  83. package/dist/Utils/FormUtils.d.ts +6 -0
  84. package/dist/Utils/FormUtils.js +35 -0
  85. package/dist/Utils/NumberUtils.d.ts +1 -0
  86. package/dist/Utils/NumberUtils.js +7 -0
  87. package/dist/Utils/PatcherUtils.d.ts +6 -0
  88. package/dist/Utils/PatcherUtils.js +80 -0
  89. package/dist/Utils/StringUtils.d.ts +3 -0
  90. package/dist/Utils/StringUtils.js +47 -0
  91. package/dist/Utils/TimeUtils/debounce.util.d.ts +22 -0
  92. package/dist/Utils/TimeUtils/debounce.util.js +78 -0
  93. package/dist/Utils/TimeUtils/functions.util.d.ts +4 -0
  94. package/dist/Utils/TimeUtils/functions.util.js +21 -0
  95. package/dist/Utils/TimeUtils/index.d.ts +15 -0
  96. package/dist/Utils/TimeUtils/index.js +34 -0
  97. package/dist/Utils/TimeUtils/throttle.util.d.ts +15 -0
  98. package/dist/Utils/TimeUtils/throttle.util.js +43 -0
  99. package/dist/Utils/index.d.ts +7 -0
  100. package/dist/Utils/index.js +23 -0
  101. package/package.json +4 -2
  102. package/src/Classes/DanhoLogger.ts +78 -0
  103. package/src/Classes/Events/Event.ts +96 -96
  104. package/src/Classes/Events/EventCollection.ts +90 -90
  105. package/src/Classes/Events/EventEmitter.ts +68 -68
  106. package/src/Classes/Time/Date.ts +219 -216
  107. package/src/Classes/Time/Time.ts +109 -104
  108. package/src/Classes/Time/TimeSpan.ts +171 -171
  109. package/src/Classes/index.ts +1 -0
  110. package/src/Classes/store.ts +22 -22
  111. package/src/Extensions/Array/array.extension.ts +103 -0
  112. package/src/Extensions/Array/crud.extension.ts +46 -0
  113. package/src/Extensions/Array/index.ts +15 -0
  114. package/src/Extensions/Array/loop.extension.ts +38 -0
  115. package/src/Extensions/Array/random.extension.ts +56 -0
  116. package/src/Extensions/Array/sort.extension.ts +52 -0
  117. package/src/Extensions/Array/string.extension.ts +22 -0
  118. package/src/Extensions/Document.ts +39 -39
  119. package/src/Extensions/Function.ts +37 -10
  120. package/src/Extensions/Map.ts +56 -56
  121. package/src/Extensions/Number.ts +50 -0
  122. package/src/Extensions/Object/arrays.extension.ts +27 -0
  123. package/src/Extensions/Object/booleans.extension.ts +46 -0
  124. package/src/Extensions/Object/extracts.extension.ts +102 -0
  125. package/src/Extensions/Object/index.ts +9 -80
  126. package/src/Extensions/Object/properties.extension.ts +11 -0
  127. package/src/Extensions/Object/properties.ts +35 -36
  128. package/src/Extensions/String/case.extension.ts +95 -0
  129. package/src/Extensions/String/index.ts +5 -0
  130. package/src/Extensions/index.ts +2 -20
  131. package/src/Interfaces/ElementOptions.ts +7 -7
  132. package/src/Interfaces/IReplacement.ts +2 -2
  133. package/src/Types/Able.ts +22 -0
  134. package/src/Types/Array.ts +7 -0
  135. package/src/Types/C#.ts +9 -0
  136. package/src/Types/Date.ts +1 -1
  137. package/src/Types/Events.ts +12 -12
  138. package/src/Types/Function.ts +10 -0
  139. package/src/Types/Object.ts +4 -0
  140. package/src/Types/PropertiesWith.ts +35 -4
  141. package/src/Types/String.ts +1 -0
  142. package/src/Types/TransformTypes.ts +23 -5
  143. package/src/Types/index.ts +7 -41
  144. package/src/Utils/ApiUtils/ApiTypes.ts +43 -0
  145. package/src/Utils/ApiUtils/RequestUtil.ts +87 -0
  146. package/src/Utils/ApiUtils/index.ts +39 -0
  147. package/src/Utils/ColorUtils.ts +102 -0
  148. package/src/Utils/FormUtils.ts +33 -0
  149. package/src/Utils/NumberUtils.ts +3 -0
  150. package/src/Utils/PatcherUtils.ts +111 -0
  151. package/src/Utils/StringUtils.ts +44 -0
  152. package/src/Utils/TimeUtils/debounce.util.ts +85 -0
  153. package/src/Utils/TimeUtils/functions.util.ts +18 -0
  154. package/src/Utils/TimeUtils/index.ts +9 -0
  155. package/src/Utils/TimeUtils/throttle.util.ts +44 -0
  156. package/src/Utils/index.ts +8 -0
  157. package/src/Extensions/Array.ts +0 -95
  158. package/src/Extensions/String.ts +0 -54
@@ -15,250 +15,253 @@ type DateFormat = `${Double}/${Double}/${Quadruple}`;
15
15
  export type DanhoDateConstructor = Data | DateFormat | number | Date;
16
16
 
17
17
  class DanhoDate {
18
- /**
19
- * Returns the value of the current irl time
20
- */
21
- public static get now() {
22
- return Date.now();
23
- }
24
-
25
- constructor(data?: DanhoDateConstructor) {
26
- // data not provided
27
- if (!data) this.date = new Date();
28
- // data is typeof Date
29
- else if (typeof data === 'object' && data instanceof Date) {
30
- this.date = new Date(data);
31
- }
32
- // data is typeof Data
33
- else if (typeof data === 'object') {
34
- this.date = new Date(data.years, data.months - 1);
35
- if (data.days) this.date.setDate(data.days);
36
- if (data.hours) this.date.setHours(data.hours);
37
- if (data.minutes) this.date.setMinutes(data.minutes);
38
- if (data.seconds) this.date.setSeconds(data.seconds);
39
- if (data.milliseconds) this.date.setMilliseconds(data.milliseconds);
40
- }
41
- // data is string or number
42
- else this.date = new Date(data);
18
+ /**
19
+ * Returns the value of the current irl time
20
+ */
21
+ public static get now() {
22
+ return Date.now();
23
+ }
43
24
 
44
- this._formats = new Map<string, string | number>([
45
- ['year', this.year],
46
- ['daysInMonth', this.daysInMonth],
47
- ['monthShort', this.monthNameShort],
48
- ['month', this.monthName],
49
- ['MM', Time.DoubleDigit(this.month)],
50
- ['M', this.month],
25
+ constructor(data?: DanhoDateConstructor) {
26
+ // data not provided
27
+ if (!data) this.date = new Date();
28
+ // data is typeof Date
29
+ else if (typeof data === 'object' && data instanceof Date) {
30
+ this.date = new Date(data);
31
+ }
32
+ // data is typeof Data
33
+ else if (typeof data === 'object') {
34
+ this.date = new Date(data.years, data.months - 1);
35
+ if (data.days) this.date.setDate(data.days);
36
+ if (data.hours) this.date.setHours(data.hours);
37
+ if (data.minutes) this.date.setMinutes(data.minutes);
38
+ if (data.seconds) this.date.setSeconds(data.seconds);
39
+ if (data.milliseconds) this.date.setMilliseconds(data.milliseconds);
40
+ }
41
+ // data is string or number
42
+ else this.date = new Date(data);
51
43
 
52
- ['weekMonth', this.weekOfMonth],
53
- ['weekDay', this.weekDay],
54
- ['weekDayShort', this.weekDayShort],
55
- ['week', this.week],
44
+ this._formats = new Map<string, string | number>([
45
+ ['year', this.year],
46
+ ['daysInMonth', this.daysInMonth],
47
+ ['monthShort', this.monthNameShort],
48
+ ['month', this.monthName],
49
+ ['MM', Time.DoubleDigit(this.month)],
50
+ ['M', this.month],
56
51
 
57
- ['dd', Time.DoubleDigit(this.day)],
58
- ['ddth', `${Time.DoubleDigit(this.day)}${Time.th(this.day)}`],
59
- ['d', this.day],
60
- ['dth', Time.th(this.day, true)],
52
+ ['weekMonth', this.weekOfMonth],
53
+ ['weekDay', this.weekDay],
54
+ ['weekDayShort', this.weekDayShort],
55
+ ['week', this.week],
61
56
 
62
- ['hh12', `${Time.DoubleDigit(this.hours)}${this.hours < 12 ? 'AM' : 'PM'}`],
63
- ['h12', `${this.hours > 12 ? 12 - this.hours : this.hours}${this.hours < 12 ? 'AM' : 'PM'}`],
64
- ['hh24', Time.DoubleDigit(this.hours)],
65
- ['h24', this.hours],
66
- ['mm', Time.DoubleDigit(this.minutes)],
67
- ['m', this.minutes],
68
- ['ss', Time.DoubleDigit(this.seconds)],
69
- ['s', this.seconds],
70
- ['msms', Time.DoubleDigit(this.milliseconds)],
71
- ['ms', this.milliseconds]
72
- ]).map((v, k) => [k, v.toString()])
73
- }
57
+ ['dd', Time.DoubleDigit(this.day)],
58
+ ['ddth', `${Time.DoubleDigit(this.day)}${Time.th(this.day)}`],
59
+ ['d', this.day],
60
+ ['dth', Time.th(this.day, true)],
74
61
 
75
- private _formats: Map<string, string>;
76
- private _format(format: string) {
77
- return format
78
- .split(/\$/)
79
- .map(v => v.split(/\W/)[0])
80
- .filter(v => v)
81
- .reduce((result, key) => result.replaceAll(key, this._formats.get(key)!), format.replaceAll('$', ''));
82
- }
62
+ ['hh12', `${Time.DoubleDigit(this.hours)}${this.hours < 12 ? 'AM' : 'PM'}`],
63
+ ['h12', `${this.hours > 12 ? 12 - this.hours : this.hours}${this.hours < 12 ? 'AM' : 'PM'}`],
64
+ ['hh24', Time.DoubleDigit(this.hours)],
65
+ ['h24', this.hours],
66
+ ['mm', Time.DoubleDigit(this.minutes)],
67
+ ['m', this.minutes],
68
+ ['ss', Time.DoubleDigit(this.seconds)],
69
+ ['s', this.seconds],
70
+ ['msms', Time.DoubleDigit(this.milliseconds)],
71
+ ['ms', this.milliseconds]
72
+ ]).map((v, k) => [k, v.toString()]);
73
+ }
83
74
 
84
- public date: Date
75
+ private _formats: Map<string, string>;
76
+ private _format(format: string) {
77
+ return format
78
+ .split(/\$/)
79
+ .map(v => v.split(/\W/)[0])
80
+ .filter(v => v)
81
+ .reduce((result, key) => result.replaceAll(key, this._formats.get(key)!), format.replaceAll('$', ''));
82
+ }
85
83
 
86
- /**
87
- * Year of the date
88
- */
89
- public get year(): number { return this.date.getFullYear() }
90
- public set year(value: number) { this.date.setFullYear(value); }
84
+ public date: Date;
91
85
 
92
- /**
93
- * Month of the date
94
- */
95
- public get month(): number { return this.date.getMonth() + 1 }
96
- public set month(value: number) { this.date.setMonth(value) }
86
+ /**
87
+ * Year of the date
88
+ */
89
+ public get year(): number { return this.date.getFullYear(); }
90
+ public set year(value: number) { this.date.setFullYear(value); }
97
91
 
98
- /**
99
- * Days in the month of the date
100
- */
101
- public get daysInMonth() { return Time.daysInMonth[this.month - 1]; }
92
+ /**
93
+ * Month of the date
94
+ */
95
+ public get month(): number { return this.date.getMonth() + 1; }
96
+ public set month(value: number) { this.date.setMonth(value); }
102
97
 
103
- /**
104
- * Week of the year the day is in
105
- */
106
- public get week(): number {
107
- const firstMonday = new Date(this.year, 1, 1);
98
+ /**
99
+ * Days in the month of the date
100
+ */
101
+ public get daysInMonth() { return Time.daysInMonth[this.month - 1]; }
108
102
 
109
- if (firstMonday.getDay() !== 1) {
110
- const daysToMon = Time.DayNames.reverse().reduce((result, day, i) =>
111
- result.set(day, i + 1)
112
- , new Map<LongDay, number>()).get(Time.DayNames[firstMonday.getDay() - 1])!;
113
- firstMonday.setDate(firstMonday.getDate() + daysToMon);
114
- }
103
+ /**
104
+ * Week of the year the day is in
105
+ */
106
+ public get week(): number {
107
+ const firstMonday = new Date(this.year, 1, 1);
115
108
 
116
- const timeDiff = Math.round(firstMonday.getTime() - this.time);
117
- const timeSince = Time.millisecond % timeDiff;
118
- const result = Math.ceil(timeSince / Time.week);
119
- return result;
109
+ if (firstMonday.getDay() !== 1) {
110
+ const daysToMon = Time.DayNames.reverse().reduce((result, day, i) =>
111
+ result.set(day, i + 1)
112
+ , new Map<LongDay, number>()).get(Time.DayNames[firstMonday.getDay() - 1])!;
113
+ firstMonday.setDate(firstMonday.getDate() + daysToMon);
120
114
  }
121
- public set week(value: number) { this.date.setDate(value * Time.week / Time.day); }
122
115
 
123
- /**
124
- * Week of the month the day is in
125
- */
126
- public get weekOfMonth(): number { return Math.round(this.daysInMonth / (Time.week / Time.day)); }
116
+ const timeDiff = Math.round(firstMonday.getTime() - this.time);
117
+ const timeSince = Time.millisecond % timeDiff;
118
+ const result = Math.ceil(timeSince / Time.week);
119
+ return result;
120
+ }
121
+ public set week(value: number) { this.date.setDate(value * Time.week / Time.day); }
127
122
 
128
- /**
129
- * Day of the date
130
- */
131
- public get day(): number { return this.date.getDate(); }
132
- public set day(value: number) { this.date.setDate(value); }
123
+ /**
124
+ * Week of the month the day is in
125
+ */
126
+ public get weekOfMonth(): number { return Math.round(this.daysInMonth / (Time.week / Time.day)); }
133
127
 
134
- public get dayOfWeek(): number { return this.date.getDay() }
135
- public set dayOfWeek(value: number) {
136
- const current = this.dayOfWeek;
128
+ /**
129
+ * Day of the date
130
+ */
131
+ public get day(): number { return this.date.getDate(); }
132
+ public set day(value: number) { this.date.setDate(value); }
137
133
 
138
- if (value > current) var diff = value - current;
139
- else diff = current - value;
134
+ public get dayOfWeek(): number { return this.date.getDay(); }
135
+ public set dayOfWeek(value: number) {
136
+ const current = this.dayOfWeek;
140
137
 
141
- this.day -= diff;
142
- }
138
+ if (value > current) var diff = value - current;
139
+ else diff = current - value;
143
140
 
144
- /**
145
- * Hours of the date
146
- */
147
- public get hours(): number { return this.date.getHours(); }
148
- public set hours(value: number) { this.date.setHours(value); }
141
+ this.day -= diff;
142
+ }
149
143
 
150
- public get isPM(): boolean {
151
- return this.hours > 11;
152
- }
144
+ /**
145
+ * Hours of the date
146
+ */
147
+ public get hours(): number { return this.date.getHours(); }
148
+ public set hours(value: number) { this.date.setHours(value); }
153
149
 
154
- /**
155
- * Minutes of the date
156
- */
157
- public get minutes(): number { return this.date.getMinutes(); }
158
- public set minutes(value: number) { this.date.setMinutes(value); }
150
+ public get isAM(): boolean {
151
+ return this.hours < 12;
152
+ }
153
+ public get isPM(): boolean {
154
+ return this.hours >= 12;
155
+ }
159
156
 
160
- /**
161
- * Seconds of the date
162
- */
163
- public get seconds(): number { return this.date.getSeconds(); }
164
- public set seconds(value: number) { this.date.setSeconds(value); }
157
+ /**
158
+ * Minutes of the date
159
+ */
160
+ public get minutes(): number { return this.date.getMinutes(); }
161
+ public set minutes(value: number) { this.date.setMinutes(value); }
165
162
 
166
- /**
167
- * Milliseconds of the date
168
- */
169
- public get milliseconds(): number { return this.date.getMilliseconds(); }
170
- public set milliseconds(value: number) { this.date.setMilliseconds(value); }
163
+ /**
164
+ * Seconds of the date
165
+ */
166
+ public get seconds(): number { return this.date.getSeconds(); }
167
+ public set seconds(value: number) { this.date.setSeconds(value); }
171
168
 
172
- /**
173
- * Millisecond value of internal time
174
- */
175
- public get time(): number { return this.date.getTime(); }
176
- public set time(value: number) { this.date.setTime(value) }
169
+ /**
170
+ * Milliseconds of the date
171
+ */
172
+ public get milliseconds(): number { return this.date.getMilliseconds(); }
173
+ public set milliseconds(value: number) { this.date.setMilliseconds(value); }
177
174
 
178
- /**
179
- * Week day i.e. Monday
180
- */
181
- public get weekDay(): LongDay { return Time.DayNames[this.dayOfWeek - 1] || Time.DayNames.at(-1); }
182
- /**
183
- * Short week day i.e. Mon
184
- */
185
- public get weekDayShort(): ShortDay { return this.weekDay.substring(0, 3) as ShortDay; }
186
- /**
187
- * Month name i.e. February
188
- */
189
- public get monthName(): LongMonth { return Time.MonthNames[this.month - 1] || Time.MonthNames.at(-1); }
190
- /**
191
- * Short month name i.e. Feb
192
- */
193
- public get monthNameShort(): ShortMonth { return this.monthName.substring(0, 3) as ShortMonth; }
175
+ /**
176
+ * Millisecond value of internal time
177
+ */
178
+ public get time(): number { return this.date.getTime(); }
179
+ public set time(value: number) { this.date.setTime(value); }
194
180
 
195
- /**
196
- * Sets internal date property
197
- * @param data Time properties to set - replacement of i.e. Date.setHours(value: number): number
198
- * @returns This, with updated properties
199
- */
200
- public set(data: Partial<Data>) {
201
- const { years, months, days, hours, minutes, seconds, milliseconds } = data;
202
- const ymd = this.date.setFullYear(years || this.year, months, days);
203
- const hmsms = new Date(ymd).setHours(hours || this.hours, minutes, seconds, milliseconds);
204
- this.date = new Date(hmsms);
205
- return this;
206
- }
181
+ /**
182
+ * Week day i.e. Monday
183
+ */
184
+ public get weekDay(): LongDay { return Time.DayNames[this.dayOfWeek - 1] || Time.DayNames.at(-1); }
185
+ /**
186
+ * Short week day i.e. Mon
187
+ */
188
+ public get weekDayShort(): ShortDay { return this.weekDay.substring(0, 3) as ShortDay; }
189
+ /**
190
+ * Month name i.e. February
191
+ */
192
+ public get monthName(): LongMonth { return Time.MonthNames[this.month - 1] || Time.MonthNames.at(-1); }
193
+ /**
194
+ * Short month name i.e. Feb
195
+ */
196
+ public get monthNameShort(): ShortMonth { return this.monthName.substring(0, 3) as ShortMonth; }
207
197
 
208
- /**
209
- * Calculates the time between this and provided date
210
- * @param date Date information
211
- * @returns TimeSpan between this and provided date
212
- */
213
- public between(date?: DanhoDate | DanhoDateConstructor): TimeSpan {
214
- if (!date) return new TimeSpan(this.date, new Date());
215
- else if (date instanceof DanhoDate) return new TimeSpan(this.date, date.date);
216
- else if (date instanceof Date) return new TimeSpan(this.date, date);
217
- else if (typeof date === 'object') return new DanhoDate(date).between(this.date);
218
- return new TimeSpan(this.date, new Date(date));
219
- }
198
+ /**
199
+ * Sets internal date property
200
+ * @param data Time properties to set - replacement of i.e. Date.setHours(value: number): number
201
+ * @returns This, with updated properties
202
+ */
203
+ public set(data: Partial<Data>) {
204
+ const { years, months, days, hours, minutes, seconds, milliseconds } = data;
205
+ const ymd = this.date.setFullYear(years || this.year, months, days);
206
+ const hmsms = new Date(ymd).setHours(hours || this.hours, minutes, seconds, milliseconds);
207
+ this.date = new Date(hmsms);
208
+ return this;
209
+ }
220
210
 
221
- /**
222
- * String representation of this
223
- * @param format String format of date
224
- * @returns String representation of this
225
- *
226
- * @$year Replaced with year of the date i.e. 2022
227
- *
228
- * @$month Replaced with month name i.e. March
229
- * @$daysInMonth Replaced with the amount of days in the month i.e. 31
230
- * @$MM replaced with double digit month i.e. 01
231
- * @$M replaced with single digit month i.e. 1
232
- *
233
- * @$week Replaced with week of the year i.e. 32
234
- * @$weekOfMonth Replaced with the week of the month i.e. 3
235
- *
236
- * @$weekday Replaced with day of the week i.e. Wednesday
237
- * @$dd Replaced with double digit day i.e. 02
238
- * @$d Replaced with single digit day i.e. 2
239
- * @$ddth Replaced with double digit day + "th" i.e. 05th
240
- * @$dth Replaced with double digit day + "th" i.e. 5th
241
- *
242
- * @$hh12 Replaced with double digit hour in 12-hour format i.e. 09
243
- * @$hh24 Replaced with double digit hour in 24-hour format i.e. 21
244
- * @$h12 Replaced with single digit hour in 12-hour format i.e. 9
245
- * @$h24 Replaced with single digit hour in 24-hour format i.e. 9
246
- *
247
- * @$mm Replaced with double digit minute i.e. 05
248
- * @$m Replaced with single digit minute i.e. 5
249
- *
250
- * @$ss Replaced with double digit second i.e. 03
251
- * @$s Replaced with single digit second i.e. 3
252
- *
253
- * @msms Replaced with double digit millisecond i.e. 02
254
- * @ms Replaced with single digit millisecond i.e. 2
255
- *
256
- * @$relative Replaced with relative timeformat as TimeSpan
257
- */
258
- public toString(format = "$dd/$MM/$year", relativeFormat?: TimeSpanFormat) {
259
- return this._format(format.replaceAll('$relative', this.between(new Date()).toString(relativeFormat)))
260
- }
211
+ /**
212
+ * Calculates the time between this and provided date
213
+ * @param date Date information
214
+ * @returns TimeSpan between this and provided date
215
+ */
216
+ public between(date?: DanhoDate | DanhoDateConstructor): TimeSpan {
217
+ if (!date) return new TimeSpan(this.date, new Date());
218
+ else if (date instanceof DanhoDate) return new TimeSpan(this.date, date.date);
219
+ else if (date instanceof Date) return new TimeSpan(this.date, date);
220
+ else if (typeof date === 'object') return new DanhoDate(date).between(this.date);
221
+ return new TimeSpan(this.date, new Date(date));
222
+ }
223
+
224
+ /**
225
+ * String representation of this
226
+ * @param format String format of date
227
+ * @returns String representation of this
228
+ *
229
+ * @$year Replaced with year of the date i.e. 2022
230
+ *
231
+ * @$month Replaced with month name i.e. March
232
+ * @$daysInMonth Replaced with the amount of days in the month i.e. 31
233
+ * @$MM replaced with double digit month i.e. 01
234
+ * @$M replaced with single digit month i.e. 1
235
+ *
236
+ * @$week Replaced with week of the year i.e. 32
237
+ * @$weekOfMonth Replaced with the week of the month i.e. 3
238
+ *
239
+ * @$weekday Replaced with day of the week i.e. Wednesday
240
+ * @$dd Replaced with double digit day i.e. 02
241
+ * @$d Replaced with single digit day i.e. 2
242
+ * @$ddth Replaced with double digit day + "th" i.e. 05th
243
+ * @$dth Replaced with double digit day + "th" i.e. 5th
244
+ *
245
+ * @$hh12 Replaced with double digit hour in 12-hour format i.e. 09
246
+ * @$hh24 Replaced with double digit hour in 24-hour format i.e. 21
247
+ * @$h12 Replaced with single digit hour in 12-hour format i.e. 9
248
+ * @$h24 Replaced with single digit hour in 24-hour format i.e. 9
249
+ *
250
+ * @$mm Replaced with double digit minute i.e. 05
251
+ * @$m Replaced with single digit minute i.e. 5
252
+ *
253
+ * @$ss Replaced with double digit second i.e. 03
254
+ * @$s Replaced with single digit second i.e. 3
255
+ *
256
+ * @msms Replaced with double digit millisecond i.e. 02
257
+ * @ms Replaced with single digit millisecond i.e. 2
258
+ *
259
+ * @$relative Replaced with relative timeformat as TimeSpan
260
+ */
261
+ public toString(format = "$dd/$MM/$year", relativeFormat?: TimeSpanFormat) {
262
+ return this._format(format.replaceAll('$relative', this.between(new Date()).toString(relativeFormat)));
263
+ }
261
264
 
262
265
  }
263
- export { DanhoDate as Date }
266
+ export { DanhoDate as Date };
264
267
  export default DanhoDate;