namirasoft-core 1.5.3 → 1.5.4

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 (56) hide show
  1. package/SKILL.md +223 -223
  2. package/dist/NamingConvention.js +1 -1
  3. package/dist/NamingConvention.js.map +1 -1
  4. package/package.json +26 -26
  5. package/src/BaseDatabaseRow.ts +6 -6
  6. package/src/BaseLogger.ts +24 -24
  7. package/src/BaseMetaColumn.ts +17 -17
  8. package/src/BaseMetaDatabase.ts +30 -30
  9. package/src/BaseMetaTable.ts +40 -40
  10. package/src/BaseServer.ts +150 -150
  11. package/src/BaseUUID.ts +76 -76
  12. package/src/ByteOperation.ts +57 -57
  13. package/src/CacheService.ts +76 -76
  14. package/src/ColorOperation.ts +153 -153
  15. package/src/ConsoleOperation.ts +68 -68
  16. package/src/ConvertService.ts +123 -123
  17. package/src/CookieService.ts +33 -33
  18. package/src/Countries.ts +486 -486
  19. package/src/Country.ts +21 -21
  20. package/src/CountryOperation.ts +98 -98
  21. package/src/CronOperation.ts +121 -121
  22. package/src/EncodingOperation.ts +46 -46
  23. package/src/EnvService.ts +28 -28
  24. package/src/ErrorOperation.ts +13 -13
  25. package/src/FileOperation.ts +60 -60
  26. package/src/FilterItem.ts +117 -117
  27. package/src/FilterItemColumnType.ts +9 -9
  28. package/src/FilterItemOperator.ts +52 -52
  29. package/src/GeoOperation.ts +18 -18
  30. package/src/HTTPError.ts +8 -8
  31. package/src/HTTPMethod.ts +7 -7
  32. package/src/HashOperation.ts +24 -24
  33. package/src/ILogger.ts +17 -17
  34. package/src/IStorage.ts +5 -5
  35. package/src/IStorageCookie.ts +52 -52
  36. package/src/IStorageJsonFile.ts +45 -45
  37. package/src/IStorageLocal.ts +16 -16
  38. package/src/IStorageMemoryDedicated.ts +17 -17
  39. package/src/IStorageMemoryShared.ts +21 -21
  40. package/src/IStorageSession.ts +16 -16
  41. package/src/LogLevel.ts +11 -11
  42. package/src/NamingConvention.ts +199 -199
  43. package/src/ObjectService.ts +27 -27
  44. package/src/PackageService.ts +76 -76
  45. package/src/PasswordOperation.ts +12 -12
  46. package/src/PhoneOperation.ts +8 -8
  47. package/src/PriceOperation.ts +20 -20
  48. package/src/SearchOperation.ts +31 -31
  49. package/src/SetTimeouService.ts +32 -32
  50. package/src/SortItem.ts +88 -88
  51. package/src/StringOperation.ts +22 -22
  52. package/src/TimeOperation.ts +303 -303
  53. package/src/TimeUnitOperation.ts +82 -82
  54. package/src/URLOperation.ts +66 -66
  55. package/src/VersionOperation.ts +46 -46
  56. package/src/index.ts +52 -52
@@ -1,304 +1,304 @@
1
- import moment from "moment";
2
-
3
- export type YMD = { year: number, month: number, day: number };
4
- export type DateInterval = { start_date: Date, end_date: Date };
5
-
6
- export class TimeOperation
7
- {
8
- static MONTH_NAMES = [
9
- "January", "February", "March", "April", "May", "June",
10
- "July", "August", "September", "October", "November", "December"
11
- ];
12
- static toDBFormat(date: Date): string
13
- {
14
- return date.toISOString().
15
- replace(/T/, ' ').
16
- replace(/\..+/, '');
17
- }
18
- static format(date: Date, format: string): string
19
- {
20
- return moment(date).format(format);
21
- }
22
- static toDate(year: number, month: number, day: number): Date
23
- {
24
- return new Date(`${year}/${month}/${day}`);
25
- }
26
- static toDateByWeek(year: number, week: number, firstDay: number): Date
27
- {
28
- if (!firstDay)
29
- firstDay = 0;
30
- let offset = new Date(year, 0, 1).getDay();
31
- return new Date(year, 0, 1 + firstDay - offset + (week - 1) * 7, 0, 0, 0, 0);
32
- }
33
- static fromDate(date: Date): YMD
34
- {
35
- let year = this.yearNumber(date);
36
- let month = this.monthNumber(date);
37
- let day = this.dayNumber(date);
38
- return { year, month, day };
39
- }
40
- static getLARange(date: Date): DateInterval
41
- {
42
- let start_date = this.hoursLater(8, date);
43
- let end_date = this.daysLater(1, start_date);
44
- return {
45
- start_date,
46
- end_date
47
- };
48
- }
49
- static diffInSecond(t1: Date, t2: Date, abs: boolean): number
50
- {
51
- let ans = (t1.getTime() - t2.getTime()) / 1000;
52
- if (abs)
53
- ans = Math.abs(ans);
54
- return ans;
55
- }
56
- static diffInMinute(t1: Date, t2: Date, abs: boolean): number
57
- {
58
- return this.diffInSecond(t1, t2, abs) / 60;
59
- }
60
- //year
61
- static yearNumber(date: Date | null = null): number
62
- {
63
- if (!date)
64
- date = new Date();
65
- return date.getUTCFullYear();
66
- }
67
- static beginningOfYear(date: Date | null = null): Date
68
- {
69
- date = this.beginningOfMonth(date);
70
- date.setUTCMonth(0);
71
- return date;
72
- }
73
- //month
74
- static monthNumber(date: Date | null = null): number
75
- {
76
- if (!date)
77
- date = new Date();
78
- return date.getUTCMonth() + 1;
79
- }
80
- static beginningOfMonth(date: Date | null = null): Date
81
- {
82
- date = this.beginningOfDay(date);
83
- date.setUTCDate(1);
84
- return date;
85
- }
86
- static endOfMonth(date: Date | null = null): Date
87
- {
88
- date = this.beginningOfMonth(date);
89
- date = this.monthsLater(1, date);
90
- date = this.secondsAgo(1, date);
91
- return date;
92
- }
93
- //week
94
- static weekNumber(date: Date | null = null): number
95
- {
96
- if (!date)
97
- date = new Date();
98
- let first = this.beginningOfYear(date);
99
- let secs = this.diffInSecond(date, first, true);
100
- return (secs / 60 / 60 / 24 / 7) + 1;
101
- }
102
- static beginningOfWeek(date: Date | null = null): Date
103
- {
104
- date = this.beginningOfDay(date);
105
- let day = (date.getDay() - 1) % 7;
106
- return this.daysAgo(day, date);
107
- }
108
- static endOfWeek(date: Date | null = null): Date
109
- {
110
- date = this.beginningOfWeek(date);
111
- return this.secondsAgo(1, this.daysLater(7, date));
112
- }
113
- // day
114
- static dayNumber(date: Date | null = null): number
115
- {
116
- if (!date)
117
- date = new Date();
118
- return date.getUTCDate();
119
- }
120
- static beginningOfDay(date: Date | null = null): Date
121
- {
122
- date = this.beginningOfHour(date);
123
- date.setUTCHours(0);
124
- return date;
125
- }
126
- static endOfDay(date: Date | null = null): Date
127
- {
128
- date = this.beginningOfDay(date);
129
- return this.daysLater(1, date);
130
- }
131
- static dayNumberInYear(date: Date | null = null): number
132
- {
133
- if (!date)
134
- date = new Date();
135
- var start = new Date(date.getFullYear(), 0, 0);
136
- var diff = date.getTime() - start.getTime();
137
- var oneDay = 1000 * 60 * 60 * 24;
138
- return Math.floor(diff / oneDay);
139
- }
140
- static addedDaysInMonth(days: number, date: Date): Date
141
- {
142
- date = this.beginningOfMonth(date);
143
- return this.daysLater(days, date);
144
- }
145
- //hour
146
- static hourNumberInWeek(date: Date | null = null): number
147
- {
148
- if (!date)
149
- date = new Date();
150
- let first = this.beginningOfWeek(date);
151
- let secs = this.diffInSecond(date, first, true);
152
- return (secs / 3600);
153
- }
154
- static hourNumberInMonth(date: Date | null = null): number
155
- {
156
- if (!date)
157
- date = new Date();
158
- let first = this.beginningOfMonth(date);
159
- let secs = this.diffInSecond(date, first, true);
160
- return (secs / 3600);
161
- }
162
- static addedHoursInWeek(hours: number, date: Date): Date
163
- {
164
- date = this.beginningOfWeek(date);
165
- return this.hoursLater(hours, date);
166
- }
167
- static beginningOfHour(date: Date | null = null): Date
168
- {
169
- if (!date)
170
- date = new Date();
171
- else
172
- date = new Date(date);
173
- date.setUTCMilliseconds(0);
174
- date.setUTCSeconds(0);
175
- date.setUTCMinutes(0);
176
- return date;
177
- }
178
- // ago
179
- static yearsAgo(years: number, date: Date): Date
180
- {
181
- return this.yearsLater(years * -1, date);
182
- }
183
- static monthsAgo(months: number, date: Date): Date
184
- {
185
- return this.monthsLater(months * -1, date);
186
- }
187
- static weeksAgo(weeks: number, date: Date): Date
188
- {
189
- return this.weeksLater(weeks * -1, date);
190
- }
191
- static daysAgo(days: number, date: Date): Date
192
- {
193
- return this.daysLater(days * -1, date);
194
- }
195
- static hoursAgo(hours: number, date: Date): Date
196
- {
197
- return this.hoursLater(hours * -1, date);
198
- }
199
- static minutesAgo(minutes: number, date: Date): Date
200
- {
201
- return this.minutesLater(minutes * -1, date);
202
- }
203
- static secondsAgo(seconds: number, date: Date): Date
204
- {
205
- return this.secondsLater(seconds * -1, date);
206
- }
207
- static millisecondsAgo(milliseconds: number, date: Date): Date
208
- {
209
- return this.millisecondsLater(milliseconds * -1, date);
210
- }
211
- // later
212
- static later(num: number, type: moment.DurationInputArg2, date: Date | null = null): Date
213
- {
214
- if (!date)
215
- date = new Date();
216
- else
217
- date = new Date(date);
218
- return moment(date).add(num, type).toDate();
219
- }
220
- static yearsLater(years: number, date: Date): Date
221
- {
222
- return this.later(years, 'years', date);
223
- }
224
- static monthsLater(months: number, date: Date): Date
225
- {
226
- return this.later(months, 'months', date);
227
- }
228
- static weeksLater(weeks: number, date: Date): Date
229
- {
230
- return this.later(weeks, 'weeks', date);
231
- }
232
- static daysLater(days: number, date: Date): Date
233
- {
234
- return this.later(days, 'days', date);
235
- }
236
- static hoursLater(hours: number, date: Date): Date
237
- {
238
- return this.later(hours, 'hours', date);
239
- }
240
- static minutesLater(minutes: number, date: Date): Date
241
- {
242
- return this.later(minutes, 'minutes', date);
243
- }
244
- static secondsLater(seconds: number, date: Date): Date
245
- {
246
- return this.later(seconds, 'seconds', date);
247
- }
248
- static millisecondsLater(milliseconds: number, date: Date): Date
249
- {
250
- return this.later(milliseconds, 'milliseconds', date);
251
- }
252
- static getDuration(startDate: Date, endDate: Date, zeroAllOnPassed: boolean = false)
253
- {
254
- if (!endDate)
255
- endDate = new Date();
256
- let s = moment(startDate);
257
- let e = moment(endDate);
258
- let passed = e < s;
259
- let year = e.diff(s, 'years', false);
260
- s.add(year, 'years');
261
- let month = e.diff(s, 'months', false);
262
- s.add(month, 'months');
263
- let day = e.diff(s, 'days', false);
264
- s.add(day, 'days');
265
- let hour = e.diff(s, 'hours', false);
266
- s.add(hour, 'hours');
267
- let minute = e.diff(s, 'minutes', false);
268
- s.add(minute, 'minutes');
269
- let second = e.diff(s, 'seconds', false);
270
- s.add(second, 'seconds');
271
-
272
- if (passed)
273
- if (zeroAllOnPassed)
274
- year = month = day = hour = minute = second = 0;
275
- let total = year * 12 + month;
276
- total = total * 30 + day;
277
- total = total * 24 + hour;
278
- total = total * 60 + minute;
279
- total += second;
280
-
281
- return {
282
- passed, year, month, day, hour, minute, second, total
283
- };
284
- }
285
- static calculateAge(date: Date): number
286
- {
287
- let birthday = new Date(date);
288
- let ageDifMs = Date.now() - birthday.getTime();
289
- var ageDate = new Date(ageDifMs); // miliseconds from epoch
290
- return Math.abs(ageDate.getUTCFullYear() - 1970);
291
- }
292
- static isValidDate(value: string): boolean
293
- {
294
- return moment(value).isValid();
295
- }
296
- static isValidDateTime(value: string): boolean
297
- {
298
- return moment(value).isValid();
299
- }
300
- static isValidTime(value: string): boolean
301
- {
302
- return moment(value).isValid();
303
- }
1
+ import moment from "moment";
2
+
3
+ export type YMD = { year: number, month: number, day: number };
4
+ export type DateInterval = { start_date: Date, end_date: Date };
5
+
6
+ export class TimeOperation
7
+ {
8
+ static MONTH_NAMES = [
9
+ "January", "February", "March", "April", "May", "June",
10
+ "July", "August", "September", "October", "November", "December"
11
+ ];
12
+ static toDBFormat(date: Date): string
13
+ {
14
+ return date.toISOString().
15
+ replace(/T/, ' ').
16
+ replace(/\..+/, '');
17
+ }
18
+ static format(date: Date, format: string): string
19
+ {
20
+ return moment(date).format(format);
21
+ }
22
+ static toDate(year: number, month: number, day: number): Date
23
+ {
24
+ return new Date(`${year}/${month}/${day}`);
25
+ }
26
+ static toDateByWeek(year: number, week: number, firstDay: number): Date
27
+ {
28
+ if (!firstDay)
29
+ firstDay = 0;
30
+ let offset = new Date(year, 0, 1).getDay();
31
+ return new Date(year, 0, 1 + firstDay - offset + (week - 1) * 7, 0, 0, 0, 0);
32
+ }
33
+ static fromDate(date: Date): YMD
34
+ {
35
+ let year = this.yearNumber(date);
36
+ let month = this.monthNumber(date);
37
+ let day = this.dayNumber(date);
38
+ return { year, month, day };
39
+ }
40
+ static getLARange(date: Date): DateInterval
41
+ {
42
+ let start_date = this.hoursLater(8, date);
43
+ let end_date = this.daysLater(1, start_date);
44
+ return {
45
+ start_date,
46
+ end_date
47
+ };
48
+ }
49
+ static diffInSecond(t1: Date, t2: Date, abs: boolean): number
50
+ {
51
+ let ans = (t1.getTime() - t2.getTime()) / 1000;
52
+ if (abs)
53
+ ans = Math.abs(ans);
54
+ return ans;
55
+ }
56
+ static diffInMinute(t1: Date, t2: Date, abs: boolean): number
57
+ {
58
+ return this.diffInSecond(t1, t2, abs) / 60;
59
+ }
60
+ //year
61
+ static yearNumber(date: Date | null = null): number
62
+ {
63
+ if (!date)
64
+ date = new Date();
65
+ return date.getUTCFullYear();
66
+ }
67
+ static beginningOfYear(date: Date | null = null): Date
68
+ {
69
+ date = this.beginningOfMonth(date);
70
+ date.setUTCMonth(0);
71
+ return date;
72
+ }
73
+ //month
74
+ static monthNumber(date: Date | null = null): number
75
+ {
76
+ if (!date)
77
+ date = new Date();
78
+ return date.getUTCMonth() + 1;
79
+ }
80
+ static beginningOfMonth(date: Date | null = null): Date
81
+ {
82
+ date = this.beginningOfDay(date);
83
+ date.setUTCDate(1);
84
+ return date;
85
+ }
86
+ static endOfMonth(date: Date | null = null): Date
87
+ {
88
+ date = this.beginningOfMonth(date);
89
+ date = this.monthsLater(1, date);
90
+ date = this.secondsAgo(1, date);
91
+ return date;
92
+ }
93
+ //week
94
+ static weekNumber(date: Date | null = null): number
95
+ {
96
+ if (!date)
97
+ date = new Date();
98
+ let first = this.beginningOfYear(date);
99
+ let secs = this.diffInSecond(date, first, true);
100
+ return (secs / 60 / 60 / 24 / 7) + 1;
101
+ }
102
+ static beginningOfWeek(date: Date | null = null): Date
103
+ {
104
+ date = this.beginningOfDay(date);
105
+ let day = (date.getDay() - 1) % 7;
106
+ return this.daysAgo(day, date);
107
+ }
108
+ static endOfWeek(date: Date | null = null): Date
109
+ {
110
+ date = this.beginningOfWeek(date);
111
+ return this.secondsAgo(1, this.daysLater(7, date));
112
+ }
113
+ // day
114
+ static dayNumber(date: Date | null = null): number
115
+ {
116
+ if (!date)
117
+ date = new Date();
118
+ return date.getUTCDate();
119
+ }
120
+ static beginningOfDay(date: Date | null = null): Date
121
+ {
122
+ date = this.beginningOfHour(date);
123
+ date.setUTCHours(0);
124
+ return date;
125
+ }
126
+ static endOfDay(date: Date | null = null): Date
127
+ {
128
+ date = this.beginningOfDay(date);
129
+ return this.daysLater(1, date);
130
+ }
131
+ static dayNumberInYear(date: Date | null = null): number
132
+ {
133
+ if (!date)
134
+ date = new Date();
135
+ var start = new Date(date.getFullYear(), 0, 0);
136
+ var diff = date.getTime() - start.getTime();
137
+ var oneDay = 1000 * 60 * 60 * 24;
138
+ return Math.floor(diff / oneDay);
139
+ }
140
+ static addedDaysInMonth(days: number, date: Date): Date
141
+ {
142
+ date = this.beginningOfMonth(date);
143
+ return this.daysLater(days, date);
144
+ }
145
+ //hour
146
+ static hourNumberInWeek(date: Date | null = null): number
147
+ {
148
+ if (!date)
149
+ date = new Date();
150
+ let first = this.beginningOfWeek(date);
151
+ let secs = this.diffInSecond(date, first, true);
152
+ return (secs / 3600);
153
+ }
154
+ static hourNumberInMonth(date: Date | null = null): number
155
+ {
156
+ if (!date)
157
+ date = new Date();
158
+ let first = this.beginningOfMonth(date);
159
+ let secs = this.diffInSecond(date, first, true);
160
+ return (secs / 3600);
161
+ }
162
+ static addedHoursInWeek(hours: number, date: Date): Date
163
+ {
164
+ date = this.beginningOfWeek(date);
165
+ return this.hoursLater(hours, date);
166
+ }
167
+ static beginningOfHour(date: Date | null = null): Date
168
+ {
169
+ if (!date)
170
+ date = new Date();
171
+ else
172
+ date = new Date(date);
173
+ date.setUTCMilliseconds(0);
174
+ date.setUTCSeconds(0);
175
+ date.setUTCMinutes(0);
176
+ return date;
177
+ }
178
+ // ago
179
+ static yearsAgo(years: number, date: Date): Date
180
+ {
181
+ return this.yearsLater(years * -1, date);
182
+ }
183
+ static monthsAgo(months: number, date: Date): Date
184
+ {
185
+ return this.monthsLater(months * -1, date);
186
+ }
187
+ static weeksAgo(weeks: number, date: Date): Date
188
+ {
189
+ return this.weeksLater(weeks * -1, date);
190
+ }
191
+ static daysAgo(days: number, date: Date): Date
192
+ {
193
+ return this.daysLater(days * -1, date);
194
+ }
195
+ static hoursAgo(hours: number, date: Date): Date
196
+ {
197
+ return this.hoursLater(hours * -1, date);
198
+ }
199
+ static minutesAgo(minutes: number, date: Date): Date
200
+ {
201
+ return this.minutesLater(minutes * -1, date);
202
+ }
203
+ static secondsAgo(seconds: number, date: Date): Date
204
+ {
205
+ return this.secondsLater(seconds * -1, date);
206
+ }
207
+ static millisecondsAgo(milliseconds: number, date: Date): Date
208
+ {
209
+ return this.millisecondsLater(milliseconds * -1, date);
210
+ }
211
+ // later
212
+ static later(num: number, type: moment.DurationInputArg2, date: Date | null = null): Date
213
+ {
214
+ if (!date)
215
+ date = new Date();
216
+ else
217
+ date = new Date(date);
218
+ return moment(date).add(num, type).toDate();
219
+ }
220
+ static yearsLater(years: number, date: Date): Date
221
+ {
222
+ return this.later(years, 'years', date);
223
+ }
224
+ static monthsLater(months: number, date: Date): Date
225
+ {
226
+ return this.later(months, 'months', date);
227
+ }
228
+ static weeksLater(weeks: number, date: Date): Date
229
+ {
230
+ return this.later(weeks, 'weeks', date);
231
+ }
232
+ static daysLater(days: number, date: Date): Date
233
+ {
234
+ return this.later(days, 'days', date);
235
+ }
236
+ static hoursLater(hours: number, date: Date): Date
237
+ {
238
+ return this.later(hours, 'hours', date);
239
+ }
240
+ static minutesLater(minutes: number, date: Date): Date
241
+ {
242
+ return this.later(minutes, 'minutes', date);
243
+ }
244
+ static secondsLater(seconds: number, date: Date): Date
245
+ {
246
+ return this.later(seconds, 'seconds', date);
247
+ }
248
+ static millisecondsLater(milliseconds: number, date: Date): Date
249
+ {
250
+ return this.later(milliseconds, 'milliseconds', date);
251
+ }
252
+ static getDuration(startDate: Date, endDate: Date, zeroAllOnPassed: boolean = false)
253
+ {
254
+ if (!endDate)
255
+ endDate = new Date();
256
+ let s = moment(startDate);
257
+ let e = moment(endDate);
258
+ let passed = e < s;
259
+ let year = e.diff(s, 'years', false);
260
+ s.add(year, 'years');
261
+ let month = e.diff(s, 'months', false);
262
+ s.add(month, 'months');
263
+ let day = e.diff(s, 'days', false);
264
+ s.add(day, 'days');
265
+ let hour = e.diff(s, 'hours', false);
266
+ s.add(hour, 'hours');
267
+ let minute = e.diff(s, 'minutes', false);
268
+ s.add(minute, 'minutes');
269
+ let second = e.diff(s, 'seconds', false);
270
+ s.add(second, 'seconds');
271
+
272
+ if (passed)
273
+ if (zeroAllOnPassed)
274
+ year = month = day = hour = minute = second = 0;
275
+ let total = year * 12 + month;
276
+ total = total * 30 + day;
277
+ total = total * 24 + hour;
278
+ total = total * 60 + minute;
279
+ total += second;
280
+
281
+ return {
282
+ passed, year, month, day, hour, minute, second, total
283
+ };
284
+ }
285
+ static calculateAge(date: Date): number
286
+ {
287
+ let birthday = new Date(date);
288
+ let ageDifMs = Date.now() - birthday.getTime();
289
+ var ageDate = new Date(ageDifMs); // miliseconds from epoch
290
+ return Math.abs(ageDate.getUTCFullYear() - 1970);
291
+ }
292
+ static isValidDate(value: string): boolean
293
+ {
294
+ return moment(value).isValid();
295
+ }
296
+ static isValidDateTime(value: string): boolean
297
+ {
298
+ return moment(value).isValid();
299
+ }
300
+ static isValidTime(value: string): boolean
301
+ {
302
+ return moment(value).isValid();
303
+ }
304
304
  }