@acorex/core 6.0.1 → 6.0.2

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 (169) hide show
  1. package/config/index.d.ts +5 -0
  2. package/config/public-api.d.ts +1 -0
  3. package/config/src/configs.d.ts +9 -0
  4. package/dateTime/index.d.ts +5 -0
  5. package/dateTime/{public-api.ts → public-api.d.ts} +1 -1
  6. package/dateTime/src/datetime.class.d.ts +100 -0
  7. package/dateTime/src/datetime.module.d.ts +8 -0
  8. package/dateTime/src/datetime.pipe.d.ts +8 -0
  9. package/dateTime/src/georgian.calendar.d.ts +20 -0
  10. package/dateTime/src/jalali.calendar.d.ts +35 -0
  11. package/esm2020/acorex-core.mjs +5 -0
  12. package/esm2020/config/acorex-core-config.mjs +5 -0
  13. package/esm2020/config/public-api.mjs +2 -0
  14. package/esm2020/config/src/configs.mjs +32 -0
  15. package/esm2020/dateTime/acorex-core-dateTime.mjs +5 -0
  16. package/esm2020/dateTime/public-api.mjs +6 -0
  17. package/esm2020/dateTime/src/datetime.class.mjs +295 -0
  18. package/esm2020/dateTime/src/datetime.module.mjs +33 -0
  19. package/esm2020/dateTime/src/datetime.pipe.mjs +26 -0
  20. package/esm2020/dateTime/src/georgian.calendar.mjs +189 -0
  21. package/esm2020/dateTime/src/jalali.calendar.mjs +359 -0
  22. package/esm2020/events/acorex-core-events.mjs +5 -0
  23. package/esm2020/events/public-api.mjs +2 -0
  24. package/esm2020/events/src/event.service.mjs +36 -0
  25. package/esm2020/http/acorex-core-http.mjs +5 -0
  26. package/esm2020/http/public-api.mjs +6 -0
  27. package/esm2020/http/src/http-error.class.mjs +2 -0
  28. package/esm2020/http/src/http-events.interceptor.mjs +3 -0
  29. package/esm2020/http/src/http-request.class.mjs +2 -0
  30. package/esm2020/http/src/http-result.class.mjs +21 -0
  31. package/esm2020/http/src/http.module.mjs +29 -0
  32. package/esm2020/http/src/http.service.mjs +147 -0
  33. package/esm2020/pipes/acorex-core-pipes.mjs +5 -0
  34. package/esm2020/pipes/public-api.mjs +3 -0
  35. package/esm2020/pipes/src/pipes.module.mjs +19 -0
  36. package/esm2020/pipes/src/safe.pipe.mjs +30 -0
  37. package/esm2020/platform/acorex-core-platform.mjs +5 -0
  38. package/esm2020/platform/public-api.mjs +2 -0
  39. package/esm2020/platform/src/platform.service.mjs +141 -0
  40. package/esm2020/public-api.mjs +5 -0
  41. package/esm2020/translation/acorex-core-translation.mjs +5 -0
  42. package/esm2020/translation/public-api.mjs +4 -0
  43. package/esm2020/translation/src/translation.module.mjs +18 -0
  44. package/esm2020/translation/src/translator.mjs +43 -0
  45. package/esm2020/translation/src/translator.pipe.mjs +15 -0
  46. package/esm2020/utils/acorex-core-utils.mjs +5 -0
  47. package/esm2020/utils/public-api.mjs +5 -0
  48. package/esm2020/utils/src/color-util.mjs +71 -0
  49. package/esm2020/utils/src/drawing-util.mjs +27 -0
  50. package/esm2020/utils/src/object-util.mjs +39 -0
  51. package/esm2020/utils/src/string-util.mjs +19 -0
  52. package/events/index.d.ts +5 -0
  53. package/events/public-api.d.ts +1 -0
  54. package/events/src/event.service.d.ts +9 -0
  55. package/fesm2015/acorex-core-config.mjs +39 -0
  56. package/fesm2015/acorex-core-config.mjs.map +1 -0
  57. package/fesm2015/acorex-core-dateTime.mjs +899 -0
  58. package/fesm2015/acorex-core-dateTime.mjs.map +1 -0
  59. package/fesm2015/acorex-core-events.mjs +43 -0
  60. package/fesm2015/acorex-core-events.mjs.map +1 -0
  61. package/fesm2015/acorex-core-http.mjs +201 -0
  62. package/fesm2015/acorex-core-http.mjs.map +1 -0
  63. package/fesm2015/acorex-core-pipes.mjs +53 -0
  64. package/fesm2015/acorex-core-pipes.mjs.map +1 -0
  65. package/fesm2015/acorex-core-platform.mjs +148 -0
  66. package/fesm2015/acorex-core-platform.mjs.map +1 -0
  67. package/fesm2015/acorex-core-translation.mjs +80 -0
  68. package/fesm2015/acorex-core-translation.mjs.map +1 -0
  69. package/fesm2015/acorex-core-utils.mjs +163 -0
  70. package/fesm2015/acorex-core-utils.mjs.map +1 -0
  71. package/fesm2015/acorex-core.mjs +11 -0
  72. package/fesm2015/acorex-core.mjs.map +1 -0
  73. package/fesm2020/acorex-core-config.mjs +39 -0
  74. package/fesm2020/acorex-core-config.mjs.map +1 -0
  75. package/fesm2020/acorex-core-dateTime.mjs +899 -0
  76. package/fesm2020/acorex-core-dateTime.mjs.map +1 -0
  77. package/fesm2020/acorex-core-events.mjs +43 -0
  78. package/fesm2020/acorex-core-events.mjs.map +1 -0
  79. package/fesm2020/acorex-core-http.mjs +200 -0
  80. package/fesm2020/acorex-core-http.mjs.map +1 -0
  81. package/fesm2020/acorex-core-pipes.mjs +53 -0
  82. package/fesm2020/acorex-core-pipes.mjs.map +1 -0
  83. package/fesm2020/acorex-core-platform.mjs +148 -0
  84. package/fesm2020/acorex-core-platform.mjs.map +1 -0
  85. package/fesm2020/acorex-core-translation.mjs +79 -0
  86. package/fesm2020/acorex-core-translation.mjs.map +1 -0
  87. package/fesm2020/acorex-core-utils.mjs +163 -0
  88. package/fesm2020/acorex-core-utils.mjs.map +1 -0
  89. package/fesm2020/acorex-core.mjs +11 -0
  90. package/fesm2020/acorex-core.mjs.map +1 -0
  91. package/http/index.d.ts +5 -0
  92. package/http/{public-api.ts → public-api.d.ts} +1 -1
  93. package/http/src/{http-error.class.ts → http-error.class.d.ts} +2 -2
  94. package/http/src/{http-events.interceptor.ts → http-events.interceptor.d.ts} +3 -7
  95. package/http/src/{http-request.class.ts → http-request.class.d.ts} +5 -5
  96. package/http/src/http-result.class.d.ts +11 -0
  97. package/http/src/http.module.d.ts +8 -0
  98. package/http/src/http.service.d.ts +23 -0
  99. package/index.d.ts +5 -0
  100. package/package.json +106 -23
  101. package/pipes/index.d.ts +5 -0
  102. package/pipes/public-api.d.ts +2 -0
  103. package/pipes/src/pipes.module.d.ts +8 -0
  104. package/pipes/src/safe.pipe.d.ts +10 -0
  105. package/platform/index.d.ts +5 -0
  106. package/platform/public-api.d.ts +1 -0
  107. package/platform/src/platform.service.d.ts +25 -0
  108. package/public-api.d.ts +1 -0
  109. package/translation/index.d.ts +5 -0
  110. package/translation/{public-api.ts → public-api.d.ts} +1 -1
  111. package/translation/src/translation.module.d.ts +7 -0
  112. package/translation/src/translator.d.ts +11 -0
  113. package/translation/src/translator.pipe.d.ts +7 -0
  114. package/utils/index.d.ts +5 -0
  115. package/utils/{public-api.ts → public-api.d.ts} +1 -1
  116. package/utils/src/color-util.d.ts +20 -0
  117. package/utils/src/drawing-util.d.ts +17 -0
  118. package/utils/src/object-util.d.ts +4 -0
  119. package/utils/src/string-util.d.ts +6 -0
  120. package/.browserslistrc +0 -16
  121. package/config/ax-preset.js +0 -186
  122. package/config/index.ts +0 -1
  123. package/config/ng-package.json +0 -6
  124. package/config/public-api.ts +0 -1
  125. package/config/src/configs.ts +0 -37
  126. package/dateTime/index.ts +0 -1
  127. package/dateTime/ng-package.json +0 -6
  128. package/dateTime/src/datetime.class.ts +0 -452
  129. package/dateTime/src/datetime.module.ts +0 -29
  130. package/dateTime/src/datetime.pipe.ts +0 -21
  131. package/dateTime/src/georgian.calendar.ts +0 -205
  132. package/dateTime/src/jalali.calendar.ts +0 -416
  133. package/events/index.ts +0 -1
  134. package/events/ng-package.json +0 -6
  135. package/events/public-api.ts +0 -1
  136. package/events/src/event.service.ts +0 -31
  137. package/http/index.ts +0 -1
  138. package/http/ng-package.json +0 -6
  139. package/http/src/http-result.class.ts +0 -34
  140. package/http/src/http.module.ts +0 -25
  141. package/http/src/http.service.ts +0 -161
  142. package/index.ts +0 -1
  143. package/karma.conf.js +0 -44
  144. package/ng-package.json +0 -7
  145. package/pipes/index.ts +0 -1
  146. package/pipes/ng-package.json +0 -6
  147. package/pipes/public-api.ts +0 -2
  148. package/pipes/src/pipes.module.ts +0 -11
  149. package/pipes/src/safe.pipe.ts +0 -24
  150. package/platform/index.ts +0 -1
  151. package/platform/ng-package.json +0 -6
  152. package/platform/public-api.ts +0 -1
  153. package/platform/src/platform.service.ts +0 -207
  154. package/public-api.ts +0 -4
  155. package/test.ts +0 -27
  156. package/translation/index.ts +0 -1
  157. package/translation/ng-package.json +0 -6
  158. package/translation/src/translation.module.ts +0 -12
  159. package/translation/src/translator.pipe.ts +0 -9
  160. package/translation/src/translator.ts +0 -49
  161. package/tsconfig.lib.json +0 -15
  162. package/tsconfig.lib.prod.json +0 -10
  163. package/tsconfig.spec.json +0 -17
  164. package/utils/index.ts +0 -1
  165. package/utils/ng-package.json +0 -6
  166. package/utils/src/color-util.ts +0 -83
  167. package/utils/src/drawing-util.ts +0 -43
  168. package/utils/src/object-util.ts +0 -82
  169. package/utils/src/string-util.ts +0 -25
@@ -1,416 +0,0 @@
1
- import { AXCalendar, AXDateTime, AXDateValue, TimeUnit } from "./datetime.class";
2
-
3
- export class JalaliCalendar implements AXCalendar {
4
-
5
- monthNames = ("فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند").split("_");
6
-
7
- monthShortNames = ("فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند").split("_");
8
-
9
- dayNames = ("شنبه_یکشنبه_دوشنبه_سه شنبه_چهارشنبه_پنج شنبه_جمعه").split("_");
10
-
11
- dayShortNames = "ش_ی_د_س_چ_پ_ج".split("_");
12
-
13
-
14
- create(value: AXDateValue): AXDateTime {
15
- const a = this.toGregorian(value.year, value.month, value.date);
16
- return new AXDateTime(new Date(a.getFullYear(), a.getMonth(), a.getDate(), value.hours || 0, value.minutes || 0, value.seconds || 0, value.ms || 0), this.name());
17
- }
18
-
19
- name(): string {
20
- return 'jalali'
21
- }
22
-
23
- dayOfMonth(date: Date): number {
24
- return this.toJalali(date).day;
25
- }
26
-
27
- dayOfYear(date: Date): number {
28
- const j = this.toJalali(date);
29
- return (j.month <= 6 ? ((j.month - 1) * 31) : ((6 * 31) + (j.month - 7) * 30)) + j.day;
30
- }
31
-
32
- dayOfWeek(date: Date): number {
33
- return date.getDay() == 6 ? 1 : date.getDay() + 2;
34
- }
35
-
36
- weekOfYear(date: Date): number {
37
- //TODO : apply jalali
38
- const firstDay = new AXDateTime(date).startOf('year');
39
- return Math.ceil((((date.getTime() - firstDay.date.getTime()) / 86400000) + firstDay.date.getDay() + 1) / 7);
40
- }
41
-
42
- year(date: Date): number {
43
- return this.toJalali(date).year;
44
- }
45
-
46
- monthOfYear(date: Date): number {
47
- return this.toJalali(date).month;
48
- }
49
-
50
-
51
- add(date: Date, unit: TimeUnit, amount: number): AXDateTime {
52
- let value = date.valueOf();
53
- switch (unit) {
54
- case 'second':
55
- value += 1000 * amount;
56
- break
57
- case 'minute':
58
- value += 60000 * amount;
59
- break
60
- case 'hour':
61
- value += 3600000 * amount;
62
- break
63
- case 'month':
64
- {
65
- const v = new Date(value);
66
- let jd = this.dayOfMonth(date);
67
- let jm = this.monthOfYear(date);
68
- let jy = this.year(date);
69
- const nm = (jm + amount);
70
- const ny = (nm % 12) ? Math.floor(nm / 12) : 0;
71
- jy += ny;
72
- jm = nm - (ny * 12);
73
- const vv = this.toGregorian(jy, jm, jd);
74
- v.setFullYear(vv.getFullYear());
75
- v.setMonth(vv.getMonth());
76
- v.setDate(vv.getDate());
77
- value = v.valueOf();
78
- break
79
- }
80
- case 'week':
81
- value += 7 * 86400000 * amount;
82
- break
83
- case 'year':
84
- {
85
- // const v = new Date(value);
86
- // v.setFullYear(v.getFullYear() + amount);
87
- // value = v.valueOf();
88
- // break
89
- const v = new Date(value);
90
- let jd = this.dayOfMonth(date);
91
- let jm = this.monthOfYear(date);
92
- let jy = this.year(date);
93
- const vv = this.toGregorian(jy + amount, jm, jd);
94
- v.setFullYear(vv.getFullYear());
95
- v.setMonth(vv.getMonth());
96
- v.setDate(vv.getDate());
97
- value = v.valueOf();
98
- break
99
- }
100
- case 'day':
101
- default:
102
- value += 86400000 * amount;
103
- }
104
- return new AXDateTime(new Date(value), this.name());
105
- }
106
-
107
- set(date: Date, unit: TimeUnit, value: number): AXDateTime {
108
- const clone = new Date(date.valueOf());
109
- const jDate = this.toJalali(clone);
110
- switch (unit) {
111
- case 'second':
112
- clone.setHours(clone.getHours(), clone.getMinutes(), value, clone.getMilliseconds());
113
- break;
114
- case 'minute':
115
- clone.setHours(clone.getHours(), value, clone.getSeconds(), clone.getMilliseconds());
116
- break;
117
- case 'hour':
118
- clone.setHours(value, clone.getMinutes(), clone.getSeconds(), clone.getMilliseconds());
119
- break;
120
- default:
121
- case 'day':
122
- const gDate = this.toGregorian(jDate.year, jDate.month, value);
123
- clone.setDate(gDate.getDate());
124
- break;
125
- case "week":
126
- break;
127
- case "month":
128
- const gDate2 = this.toGregorian(jDate.year, value, jDate.day);
129
- clone.setMonth(gDate2.getMonth());
130
- break;
131
- case "year":
132
- const gDate3 = this.toGregorian(value, jDate.month, jDate.day);
133
- clone.setFullYear(gDate3.getFullYear());
134
- break;
135
- }
136
- return new AXDateTime(clone, this.name());
137
- }
138
-
139
- startOf(date: Date, unit: TimeUnit): AXDateTime {
140
- const clone = new Date(date.valueOf());
141
- switch (unit) {
142
- case 'second':
143
- clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 0);
144
- return new AXDateTime(clone, this.name());
145
- case 'minute':
146
- clone.setHours(clone.getHours(), clone.getMinutes(), 0, 0);
147
- return new AXDateTime(clone, this.name());
148
- case 'hour':
149
- clone.setHours(clone.getHours(), 0, 0, 0);
150
- return new AXDateTime(clone, this.name());
151
- default:
152
- case 'day':
153
- clone.setHours(0, 0, 0, 0);
154
- return new AXDateTime(clone, this.name());
155
- case "week":
156
- return new AXDateTime(clone, this.name()).add('day', -this.dayOfWeek(clone) + 1).startOf('day');
157
- case "month":
158
- {
159
- const jy = this.year(date);
160
- const jm = this.monthOfYear(date);
161
- const gDate = this.toGregorian(jy, jm, 1);
162
- return new AXDateTime(gDate, this.name()).startOf('day');
163
- }
164
- case "year":
165
- {
166
- const jy = this.year(date);
167
- const gDate = this.toGregorian(jy, 1, 1);
168
- return new AXDateTime(gDate, this.name()).startOf('day');
169
- }
170
- }
171
- }
172
-
173
- endOf(date: Date, unit: TimeUnit): AXDateTime {
174
- const clone = new Date(date.valueOf());
175
- switch (unit) {
176
- case 'second':
177
- clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 999);
178
- return new AXDateTime(clone, this.name());
179
- case 'minute':
180
- clone.setHours(clone.getHours(), clone.getMinutes(), 59, 999);
181
- return new AXDateTime(clone, this.name());
182
- case 'hour':
183
- clone.setHours(clone.getHours(), 59, 59, 999);
184
- return new AXDateTime(clone, this.name());
185
- default:
186
- case 'day':
187
- clone.setHours(23, 59, 59, 999);
188
- return new AXDateTime(clone, this.name());
189
- case 'week':
190
- {
191
- return this.startOf(date, 'week').add('day', 6).endOf('day');
192
- }
193
- case 'month':
194
- {
195
- const jy = this.year(date);
196
- const jm = this.monthOfYear(date);
197
- const jd = this.monthLength(jy, jm);
198
- const gDate = this.toGregorian(jy, jm, jd);
199
- return new AXDateTime(gDate, this.name()).endOf('day');
200
- }
201
- case "year":
202
- let jy = this.year(date);
203
- const gDate = this.toGregorian(jy, 12, this.monthLength(jy, 12));
204
- return new AXDateTime(gDate, this.name()).endOf('day');
205
- }
206
- }
207
-
208
-
209
-
210
- toJalali(date: Date): { year: number, month: number, day: number } {
211
- const gy = date.getFullYear();
212
- const gm = date.getMonth() + 1;
213
- const gd = date.getDate();
214
- const r = this.d2j(this.g2d(gy, gm, gd))
215
- return {
216
- year: r.jy,
217
- month: r.jm,
218
- day: r.jd,
219
- }
220
- }
221
-
222
- /*
223
- Converts a Jalaali date to Gregorian.
224
- */
225
- toGregorian(jy, jm, jd) {
226
- const g = this.d2g(this.j2d(jy, jm, jd))
227
- return new Date(g.gy, g.gm - 1, g.gd);
228
- }
229
-
230
- /*
231
- Checks whether a Jalaali date is valid or not.
232
- */
233
- isValid(jy, jm, jd) {
234
- return jy >= -61 && jy <= 3177 &&
235
- jm >= 1 && jm <= 12 &&
236
- jd >= 1 && jd <= this.monthLength(jy, jm)
237
- }
238
-
239
- /*
240
- Is this a leap year or not?
241
- */
242
- isLeapYear(jy) {
243
- return this.jalCal(jy).leap === 0
244
- }
245
-
246
- /*
247
- Number of days in a given month in a Jalaali year.
248
- */
249
- monthLength(jy, jm) {
250
- if (jm <= 6) return 31
251
- if (jm <= 11) return 30
252
- if (this.isLeapYear(jy)) return 30
253
- return 29
254
- }
255
-
256
-
257
- private jalCal(jy) {
258
- // Jalaali years starting the 33-year rule.
259
- let breaks = [-61, 9, 38, 199, 426, 686, 756, 818, 1111, 1181, 1210
260
- , 1635, 2060, 2097, 2192, 2262, 2324, 2394, 2456, 3178
261
- ]
262
- , bl = breaks.length
263
- , gy = jy + 621
264
- , leapJ = -14
265
- , jp = breaks[0]
266
- , jm
267
- , jump
268
- , leap
269
- , leapG
270
- , march
271
- , n
272
- , i
273
-
274
- if (jy < jp || jy >= breaks[bl - 1])
275
- throw new Error('Invalid Jalaali year ' + jy)
276
-
277
- // Find the limiting years for the Jalaali year jy.
278
- for (i = 1; i < bl; i += 1) {
279
- jm = breaks[i]
280
- jump = jm - jp
281
- if (jy < jm)
282
- break
283
- leapJ = leapJ + this.div(jump, 33) * 8 + this.div(this.mod(jump, 33), 4)
284
- jp = jm
285
- }
286
- n = jy - jp
287
-
288
- // Find the number of leap years from AD 621 to the beginning
289
- // of the current Jalaali year in the Persian calendar.
290
- leapJ = leapJ + this.div(n, 33) * 8 + this.div(this.mod(n, 33) + 3, 4)
291
- if (this.mod(jump, 33) === 4 && jump - n === 4)
292
- leapJ += 1
293
-
294
- // And the same in the Gregorian calendar (until the year gy).
295
- leapG = this.div(gy, 4) - this.div((this.div(gy, 100) + 1) * 3, 4) - 150
296
-
297
- // Determine the Gregorian date of Farvardin the 1st.
298
- march = 20 + leapJ - leapG
299
-
300
- // Find how many years have passed since the last leap year.
301
- if (jump - n < 6)
302
- n = n - jump + this.div(jump + 4, 33) * 33
303
- leap = this.mod(this.mod(n + 1, 33) - 1, 4)
304
- if (leap === -1) {
305
- leap = 4
306
- }
307
-
308
- return {
309
- leap: leap
310
- , gy: gy
311
- , march: march
312
- }
313
- }
314
-
315
- /*
316
- Converts a date of the Jalaali calendar to the Julian Day number.
317
- @param jy Jalaali year (1 to 3100)
318
- @param jm Jalaali month (1 to 12)
319
- @param jd Jalaali day (1 to 29/31)
320
- @return Julian Day number
321
- */
322
- private j2d(jy, jm, jd) {
323
- let r = this.jalCal(jy)
324
- return this.g2d(r.gy, 3, r.march) + (jm - 1) * 31 - this.div(jm, 7) * (jm - 7) + jd - 1
325
- }
326
-
327
- /*
328
- Converts the Julian Day number to a date in the Jalaali calendar.
329
- @param jdn Julian Day number
330
- @return
331
- jy: Jalaali year (1 to 3100)
332
- jm: Jalaali month (1 to 12)
333
- jd: Jalaali day (1 to 29/31)
334
- */
335
- private d2j(jdn) {
336
- let gy = this.d2g(jdn).gy // Calculate Gregorian year (gy).
337
- , jy = gy - 621
338
- , r = this.jalCal(jy)
339
- , jdn1f = this.g2d(gy, 3, r.march)
340
- , jd
341
- , jm
342
- , k
343
-
344
- // Find number of days that passed since 1 Farvardin.
345
- k = jdn - jdn1f
346
- if (k >= 0) {
347
- if (k <= 185) {
348
- // The first 6 months.
349
- jm = 1 + this.div(k, 31)
350
- jd = this.mod(k, 31) + 1
351
- return {
352
- jy: jy
353
- , jm: jm
354
- , jd: jd
355
- }
356
- } else {
357
- // The remaining months.
358
- k -= 186
359
- }
360
- } else {
361
- // Previous Jalaali year.
362
- jy -= 1
363
- k += 179
364
- if (r.leap === 1)
365
- k += 1
366
- }
367
- jm = 7 + this.div(k, 30)
368
- jd = this.mod(k, 30) + 1
369
- return {
370
- jy: jy
371
- , jm: jm
372
- , jd: jd
373
- }
374
- }
375
-
376
-
377
- private g2d(gy, gm, gd) {
378
- let d = this.div((gy + this.div(gm - 8, 6) + 100100) * 1461, 4)
379
- + this.div(153 * this.mod(gm + 9, 12) + 2, 5)
380
- + gd - 34840408
381
- d = d - this.div(this.div(gy + 100100 + this.div(gm - 8, 6), 100) * 3, 4) + 752
382
- return d
383
- }
384
-
385
-
386
- private d2g(jdn) {
387
- let j
388
- , i
389
- , gd
390
- , gm
391
- , gy
392
- j = 4 * jdn + 139361631
393
- j = j + this.div(this.div(4 * jdn + 183187720, 146097) * 3, 4) * 4 - 3908
394
- i = this.div(this.mod(j, 1461), 4) * 5 + 308
395
- gd = this.div(this.mod(i, 153), 5) + 1
396
- gm = this.mod(this.div(i, 153), 12) + 1
397
- gy = this.div(j, 1461) - 100100 + this.div(8 - gm, 6)
398
- return {
399
- gy: gy
400
- , gm: gm
401
- , gd: gd
402
- }
403
- }
404
-
405
- /*
406
- Utility helper functions.
407
- */
408
- private div(a, b) {
409
- return ~~(a / b)
410
- }
411
-
412
- private mod(a, b) {
413
- return a - ~~(a / b) * b
414
- }
415
-
416
- }
package/events/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './public-api'
@@ -1,6 +0,0 @@
1
- {
2
- "$schema": "../../../../node_modules/ng-packagr/ng-package.schema.json",
3
- "lib": {
4
- "entryFile": "public-api.ts"
5
- }
6
- }
@@ -1 +0,0 @@
1
- export * from './src/event.service';
@@ -1,31 +0,0 @@
1
- import { Injectable } from '@angular/core';
2
-
3
- @Injectable({ providedIn: 'root' })
4
- export class AXEventService {
5
- private list: any[] = [];
6
-
7
- public broadcast(key: string, options?: any): void {
8
- const d = this.list.find(c => c.key === key);
9
- if (d) {
10
- d.events.forEach((c:any) => {
11
- c(options);
12
- });
13
- }
14
- }
15
-
16
- public on(key: string, callback: (options?: any) => void) {
17
- let d = this.list.find(c => c.key === key);
18
- if (!d) {
19
- d = { key, events: [] };
20
- this.list.push(d);
21
- }
22
- d.events.push(callback);
23
- }
24
-
25
- public destroy(key: string, callback: (options?: any) => void): void {
26
- const d = this.list.find(c => c.key === key);
27
- if (d) {
28
- d.events = [];
29
- }
30
- }
31
- }
package/http/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './public-api'
@@ -1,6 +0,0 @@
1
- {
2
- "$schema": "../../../../node_modules/ng-packagr/ng-package.schema.json",
3
- "lib": {
4
- "entryFile": "public-api.ts"
5
- }
6
- }
@@ -1,34 +0,0 @@
1
- import { IHttpError } from './http-error.class';
2
-
3
- export class HttpResult<T> {
4
- private _executor: (result: (e?: T) => void, error: (e?: IHttpError) => void, complete: () => void) => void;
5
- constructor(
6
- executor: (
7
- result: (e?: T) => void,
8
- error: (e?: IHttpError) => void,
9
- complete: () => void
10
- ) => void
11
- ) {
12
- this._executor = executor;
13
- setTimeout(() => {
14
- this._executor(this.resultAction, this.errorAction, this.completeAction);
15
- }, 50);
16
- }
17
-
18
- private resultAction: (e?: T) => void;
19
- private errorAction: (e?: IHttpError) => void;
20
- private completeAction: () => void;
21
-
22
- result(action: (e?: T) => void): HttpResult<T> {
23
- this.resultAction = action;
24
- return this;
25
- }
26
- error(action: (e?: IHttpError) => void): HttpResult<T> {
27
- this.errorAction = action;
28
- return this;
29
- }
30
- complete(action: () => void): HttpResult<T> {
31
- this.completeAction = action;
32
- return this;
33
- }
34
- }
@@ -1,25 +0,0 @@
1
- import { NgModule, ModuleWithProviders } from '@angular/core';
2
- import { CommonModule } from '@angular/common';
3
- import { HttpClientModule } from '@angular/common/http';
4
- import { AXHttpService } from './http.service';
5
-
6
-
7
- @NgModule({
8
- declarations: [],
9
- imports: [
10
- CommonModule,
11
- HttpClientModule
12
- ],
13
- exports: [HttpClientModule],
14
- providers: [
15
- AXHttpService
16
- ]
17
- })
18
- export class AXHttpModule {
19
- // static forRoot(): ModuleWithProviders {
20
- // return {
21
- // ngModule: AXHttpModule,
22
- // providers: [AXHttpService]
23
- // };
24
- // }
25
- }
@@ -1,161 +0,0 @@
1
- import { Injectable, Injector, InjectFlags } from '@angular/core';
2
- import { HttpClient, HttpHeaders, HttpParams, HttpErrorResponse } from '@angular/common/http';
3
- import { HttpResult } from './http-result.class';
4
- import { IHttpError } from './http-error.class';
5
- import { AXHttpRequestOptions } from './http-request.class';
6
- import {
7
- AX_HTTP_EVENT_INTERCEPTOR, AXHttpEventInterceptor
8
- } from './http-events.interceptor';
9
- // import { catchError, retry, retryWhen, mergeMap, delay, switchMap, scan, takeWhile, flatMap } from 'rxjs/operators';
10
- // import { of, concat, throwError } from 'rxjs';
11
-
12
-
13
- @Injectable()
14
- export class AXHttpService {
15
-
16
- private interceptor: AXHttpEventInterceptor;
17
- constructor(private http: HttpClient, private injector: Injector) {
18
- this.interceptor = this.injector.get(AX_HTTP_EVENT_INTERCEPTOR);
19
- }
20
-
21
-
22
- get<T>(url: string, config: AXHttpRequestOptions = {}): HttpResult<T> {
23
- config.url = url;
24
- config.method = "get";
25
- return this.request(config);
26
- }
27
-
28
- post<T>(url: string, config: AXHttpRequestOptions = {}): HttpResult<T> {
29
- config.url = url;
30
- config.method = "post";
31
- return this.request(config);
32
- }
33
-
34
- delete<T>(url: string, config: AXHttpRequestOptions = {}): HttpResult<T> {
35
- config.url = url;
36
- config.method = "delete";
37
- return this.request(config);
38
- }
39
-
40
- put<T>(url: string, config: AXHttpRequestOptions = {}): HttpResult<T> {
41
- config.url = url;
42
- config.method = "put";
43
- return this.request(config);
44
- }
45
-
46
-
47
- request<T>(config: AXHttpRequestOptions): HttpResult<T> {
48
- return new HttpResult<T>((result?, error?, complete?) => {
49
- this.handleBegin(config).then(c => {
50
- this.http
51
- //TODO: check ts error
52
- //@ts-ignore
53
- .request<T>(config.method, config.url, this.mapOptions(config))
54
- //.pipe(this.retry)
55
- .subscribe(data => {
56
- this.handleResult(data, result, complete, config);
57
- }, c => {
58
- this.handleError(c, error, complete, config);
59
- });
60
- });
61
- })
62
- }
63
-
64
-
65
- private handleResult(data, result, complete, config: AXHttpRequestOptions) {
66
- if (this.interceptor) {
67
- this.interceptor.success(config, data).then(c => {
68
- if (result)
69
- result(c);
70
- this.handleComplete(complete, config);
71
- });
72
- }
73
- else {
74
- //
75
- if (result)
76
- result(data);
77
- this.handleComplete(complete, config);
78
- }
79
- }
80
-
81
- private handleBegin(config: AXHttpRequestOptions): Promise<AXHttpRequestOptions> {
82
- return new Promise((resolve) => {
83
- if (!config.headers)
84
- config.headers = {};
85
- if (!config.params)
86
- config.params = {};
87
- //
88
- if (this.interceptor) {
89
- this.interceptor.begin(config).then(c => {
90
- resolve(c);
91
- });
92
- }
93
- else {
94
- resolve(config)
95
- }
96
- })
97
- }
98
-
99
- private handleComplete(complete: Function, config: AXHttpRequestOptions) {
100
- if (complete)
101
- complete();
102
- if (this.interceptor)
103
- this.interceptor.complete(config);
104
- }
105
-
106
- private handleError(c: HttpErrorResponse, error: Function, complete: Function, config: AXHttpRequestOptions) {
107
- let r: IHttpError = {
108
- message: c.message,
109
- status: c.status,
110
- code: c.status?.toString(),
111
- handled: false,
112
- error: c.error
113
- }
114
- if (error) {
115
- error(r);
116
- }
117
- if (!r.handled) {
118
- if (this.interceptor)
119
- this.interceptor.error(config, r);
120
- }
121
- this.handleComplete(complete, config);
122
- }
123
-
124
- private mapOptions(options: AXHttpRequestOptions) {
125
- let headers = new HttpHeaders();
126
-
127
- for (const key in options.headers) {
128
- if (options.headers.hasOwnProperty(key)) {
129
- const value = options.headers[key];
130
- headers = headers.set(key, value)
131
- }
132
- }
133
- let params = new HttpParams();
134
- for (const key in options.params) {
135
- if (options.params.hasOwnProperty(key)) {
136
- const value = options.params[key];
137
- params = params.set(key, value);
138
- }
139
- }
140
- return {
141
- headers: headers,
142
- params: params,
143
- body: options.body,
144
- responseType: options.responseType || 'json'
145
- };
146
- // if (options.method == "get") {
147
- // return {
148
- // headers: headers,
149
- // params: params
150
- // };
151
- // }
152
- // else {
153
- // return {
154
- // headers: headers,
155
- // params: params,
156
- // body: options.body
157
- // };
158
- // }
159
- }
160
-
161
- }
package/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './public-api'