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