@acorex/core 5.0.0 → 5.0.5

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 (64) hide show
  1. package/karma.conf.js +44 -0
  2. package/ng-package.json +11 -0
  3. package/package.json +14 -18
  4. package/src/lib/config/configs.ts +36 -0
  5. package/src/lib/core.module.ts +10 -0
  6. package/src/lib/dateTime/datetime.class.ts +395 -0
  7. package/src/lib/dateTime/datetime.module.ts +11 -0
  8. package/src/lib/dateTime/datetime.pipe.ts +20 -0
  9. package/src/lib/dateTime/georgian.calendar.ts +157 -0
  10. package/{lib/dateTime/index.d.ts → src/lib/dateTime/index.ts} +1 -1
  11. package/src/lib/dateTime/jalali.calendar.ts +376 -0
  12. package/src/lib/http/http-error.class.ts +7 -0
  13. package/src/lib/http/http-events.interceptor.ts +14 -0
  14. package/src/lib/http/http-request.class.ts +14 -0
  15. package/src/lib/http/http-result.class.ts +34 -0
  16. package/src/lib/http/http.module.ts +25 -0
  17. package/src/lib/http/http.service.ts +159 -0
  18. package/src/lib/platform/index.ts +1 -0
  19. package/src/lib/platform/platform.service.ts +185 -0
  20. package/{lib/translation/index.d.ts → src/lib/translation/index.ts} +1 -1
  21. package/src/lib/translation/translation.module.ts +12 -0
  22. package/src/lib/translation/translator.pipe.ts +9 -0
  23. package/src/lib/translation/translator.ts +31 -0
  24. package/src/lib/utils/drawing-util.ts +43 -0
  25. package/src/lib/utils/index.ts +3 -0
  26. package/src/lib/utils/object-util.ts +82 -0
  27. package/src/lib/utils/safe.pipe.ts +24 -0
  28. package/src/public-api.ts +11 -0
  29. package/src/test.ts +26 -0
  30. package/tsconfig.lib.json +20 -0
  31. package/tsconfig.lib.prod.json +10 -0
  32. package/tsconfig.spec.json +17 -0
  33. package/acorex-core.d.ts +0 -5
  34. package/bundles/acorex-core.umd.js +0 -822
  35. package/bundles/acorex-core.umd.js.map +0 -1
  36. package/esm2015/acorex-core.js +0 -5
  37. package/esm2015/lib/config/configs.js +0 -29
  38. package/esm2015/lib/dateTime/datetime.class.js +0 -226
  39. package/esm2015/lib/dateTime/datetime.module.js +0 -18
  40. package/esm2015/lib/dateTime/datetime.pipe.js +0 -25
  41. package/esm2015/lib/dateTime/georgian.calendar.js +0 -145
  42. package/esm2015/lib/dateTime/index.js +0 -5
  43. package/esm2015/lib/platform/index.js +0 -2
  44. package/esm2015/lib/platform/platform.service.js +0 -105
  45. package/esm2015/lib/translation/index.js +0 -4
  46. package/esm2015/lib/translation/translation.module.js +0 -18
  47. package/esm2015/lib/translation/translator.js +0 -26
  48. package/esm2015/lib/translation/translator.pipe.js +0 -15
  49. package/esm2015/lib/utils/object-util.js +0 -83
  50. package/esm2015/public-api.js +0 -6
  51. package/fesm2015/acorex-core.js +0 -679
  52. package/fesm2015/acorex-core.js.map +0 -1
  53. package/lib/config/configs.d.ts +0 -9
  54. package/lib/dateTime/datetime.class.d.ts +0 -83
  55. package/lib/dateTime/datetime.module.d.ts +0 -7
  56. package/lib/dateTime/datetime.pipe.d.ts +0 -8
  57. package/lib/dateTime/georgian.calendar.d.ts +0 -17
  58. package/lib/platform/index.d.ts +0 -1
  59. package/lib/platform/platform.service.d.ts +0 -20
  60. package/lib/translation/translation.module.d.ts +0 -7
  61. package/lib/translation/translator.d.ts +0 -9
  62. package/lib/translation/translator.pipe.d.ts +0 -7
  63. package/lib/utils/object-util.d.ts +0 -7
  64. package/public-api.d.ts +0 -5
package/karma.conf.js ADDED
@@ -0,0 +1,44 @@
1
+ // Karma configuration file, see link for more information
2
+ // https://karma-runner.github.io/1.0/config/configuration-file.html
3
+
4
+ module.exports = function (config) {
5
+ config.set({
6
+ basePath: '',
7
+ frameworks: ['jasmine', '@angular-devkit/build-angular'],
8
+ plugins: [
9
+ require('karma-jasmine'),
10
+ require('karma-chrome-launcher'),
11
+ require('karma-jasmine-html-reporter'),
12
+ require('karma-coverage'),
13
+ require('@angular-devkit/build-angular/plugins/karma')
14
+ ],
15
+ client: {
16
+ jasmine: {
17
+ // you can add configuration options for Jasmine here
18
+ // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
19
+ // for example, you can disable the random execution with `random: false`
20
+ // or set a specific seed with `seed: 4321`
21
+ },
22
+ clearContext: false // leave Jasmine Spec Runner output visible in browser
23
+ },
24
+ jasmineHtmlReporter: {
25
+ suppressAll: true // removes the duplicated traces
26
+ },
27
+ coverageReporter: {
28
+ dir: require('path').join(__dirname, '../../../coverage/acorex/core'),
29
+ subdir: '.',
30
+ reporters: [
31
+ { type: 'html' },
32
+ { type: 'text-summary' }
33
+ ]
34
+ },
35
+ reporters: ['progress', 'kjhtml'],
36
+ port: 9876,
37
+ colors: true,
38
+ logLevel: config.LOG_INFO,
39
+ autoWatch: true,
40
+ browsers: ['Chrome'],
41
+ singleRun: false,
42
+ restartOnFileChange: true
43
+ });
44
+ };
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "dest": "../../../dist/acorex/core",
4
+ "lib": {
5
+ "entryFile": "src/public-api.ts",
6
+ "umdModuleIds": {
7
+ "lodash-es/merge": "lodash-es/merge"
8
+ }
9
+ },
10
+ "allowedNonPeerDependencies": ["lodash-es"]
11
+ }
package/package.json CHANGED
@@ -1,19 +1,15 @@
1
- {
2
- "name": "@acorex/core",
3
- "version": "5.0.0",
4
- "peerDependencies": {
5
- "@angular/common": "^12.2.0",
6
- "@angular/core": "^12.2.0"
7
- },
8
- "dependencies": {
9
- "lodash-es": "^4.17.20",
10
- "tslib": "^2.3.0"
11
- },
12
- "main": "bundles/acorex-core.umd.js",
13
- "module": "fesm2015/acorex-core.js",
14
- "es2015": "fesm2015/acorex-core.js",
15
- "esm2015": "esm2015/acorex-core.js",
16
- "fesm2015": "fesm2015/acorex-core.js",
17
- "typings": "acorex-core.d.ts",
18
- "sideEffects": false
1
+ {
2
+ "name": "@acorex/core",
3
+ "version": "5.0.5",
4
+ "peerDependencies": {
5
+ "@angular/common": "^12.2.6",
6
+ "@angular/core": "^12.2.6"
7
+ },
8
+ "dependencies": {
9
+ "lodash-es": "^4.17.20",
10
+ "tslib": "^2.3.0"
11
+ },
12
+ "devDependencies": {
13
+ "@angular-devkit/build-angular": "^12.2.6"
14
+ }
19
15
  }
@@ -0,0 +1,36 @@
1
+ import { Subject, Observable } from 'rxjs';
2
+ import { AXObjectUtil } from '../utils/object-util';
3
+
4
+ // @dynamic
5
+ export class AXConfig {
6
+ private static dataModel: any = {};
7
+ private static dataChangeSubject = new Subject<any>();
8
+
9
+
10
+ static get onChange(): Observable<any> {
11
+ return AXConfig.dataChangeSubject.asObservable();
12
+ }
13
+
14
+ static set(config: any): any;
15
+ static set(path: string, value?: any): void;
16
+ static set(arg1?: any, arg2?: any) {
17
+
18
+ if (arg1 && typeof arg1 == 'string') {
19
+ AXObjectUtil.setPropByPath(AXConfig.dataModel, arg1, arg2);
20
+ AXConfig.dataChangeSubject.next(AXConfig.dataModel);
21
+ return;
22
+ }
23
+ if (arg1 && typeof arg1 == 'object') {
24
+ Object.assign(AXConfig.dataModel, arg1);
25
+ AXConfig.dataChangeSubject.next(AXConfig.dataModel);
26
+ return;
27
+ }
28
+ if (!arg1 && !arg2) {
29
+ return AXConfig.dataChangeSubject.asObservable();
30
+ }
31
+ }
32
+
33
+ static get(path: string, defaultValue?: any): any {
34
+ return AXObjectUtil.getPropByPath(AXConfig.dataModel, path) || defaultValue;
35
+ }
36
+ }
@@ -0,0 +1,10 @@
1
+ import { NgModule } from "@angular/core";
2
+ import { AXSafePipe } from "./utils";
3
+
4
+ @NgModule({
5
+ imports: [],
6
+ exports: [AXSafePipe],
7
+ declarations: [AXSafePipe],
8
+ providers: [],
9
+ })
10
+ export class AXCoreModule { }
@@ -0,0 +1,395 @@
1
+ import { AXConfig } from '../config/configs';
2
+
3
+
4
+ export const AX_CALENDARS: any[] = [
5
+ {
6
+ name: 'gregorian',
7
+ type: 'GeorgianCalendar'
8
+ },
9
+ {
10
+ name: 'jalali',
11
+ type: 'JalaliCalendar'
12
+ }
13
+ ];
14
+ export type TimeUnit =
15
+ | 'second'
16
+ | 'minute'
17
+ | 'hour'
18
+ | 'day'
19
+ | 'month'
20
+ | 'year'
21
+ | 'week';
22
+
23
+ export interface AXCalendar {
24
+ monthNames: string[];
25
+
26
+ monthShortNames: string[];
27
+
28
+ dayNames: string[];
29
+
30
+ dayShortNames: string[];
31
+
32
+ name(): string;
33
+
34
+ dayInMonth(date: Date): number;
35
+
36
+ dayOfYear(date: Date): number;
37
+
38
+ dayInWeek(date: Date): number;
39
+
40
+ year(date: Date): number;
41
+
42
+ monthOfYear(date: Date): number;
43
+
44
+ add(date: Date, unit: TimeUnit, amount: number): AXDateTime;
45
+
46
+ set(date: Date, unit: TimeUnit, value: number): AXDateTime;
47
+
48
+ startOf(date: Date, unit: TimeUnit): AXDateTime;
49
+
50
+ /**
51
+ * This comment _supports_ [Markdown](https://marked.js.org/)
52
+ */
53
+ endOf(date: Date, unit: TimeUnit): AXDateTime;
54
+ }
55
+
56
+ /**
57
+ * Standard links:
58
+ * {@link Foo} or {@linkplain Foo} or [[Foo]]
59
+ *
60
+ * Code links: (Puts Foo inside <code> tags)
61
+ * {@linkcode Foo} or [[`Foo`]]
62
+ */
63
+ // @dynamic
64
+ export class AXDateTime {
65
+ static convert(
66
+ value: any,
67
+ calendar: string = AXConfig.get('dateTime.type') || 'gregorian'
68
+ ): AXDateTime {
69
+ let date: AXDateTime;
70
+ if (typeof value === 'string' || value instanceof String) {
71
+ date = new AXDateTime(value as string, calendar);
72
+ } else if (value instanceof Date) {
73
+ date = new AXDateTime(value as Date, calendar);
74
+ } else if (value instanceof AXDateTime) {
75
+ date = new AXDateTime(value.date, calendar);
76
+ }
77
+ return date;
78
+ }
79
+
80
+
81
+ private _date: Date;
82
+ /**
83
+ * This comment _supports_ [Markdown](https://marked.js.org/)
84
+ */
85
+ get date(): Date {
86
+ return this._date;
87
+ }
88
+
89
+ private _calendar: AXCalendar;
90
+ get calendar(): AXCalendar {
91
+ return this._calendar;
92
+ }
93
+
94
+ constructor(
95
+ value: Date | string = new Date(),
96
+ calendar: string | AXCalendar = AXConfig.get('dateTime.type') || 'gregorian'
97
+ ) {
98
+ this._calendar =
99
+ typeof calendar == 'string'
100
+ ? eval(`new ${AX_CALENDARS.find((c) => c.name == calendar).type}()`)
101
+ : calendar;
102
+ if (value instanceof Date) {
103
+ this._date = value as Date;
104
+ } else {
105
+ this._date = new Date(value);
106
+ }
107
+ }
108
+
109
+ clone(): AXDateTime {
110
+ return new AXDateTime(this.date, this.calendar.name());
111
+ }
112
+
113
+ get dayInMonth(): number {
114
+ return this._calendar.dayInMonth(this.date);
115
+ }
116
+
117
+ get dayOfYear(): number {
118
+ return this._calendar.dayOfYear(this.date);
119
+ }
120
+
121
+ get dayInWeek(): number {
122
+ return this._calendar.dayInWeek(this.date);
123
+ }
124
+
125
+ get hour(): number {
126
+ return this._date.getHours();
127
+ }
128
+
129
+ get minute(): number {
130
+ return this._date.getMinutes();
131
+ }
132
+
133
+ get second(): number {
134
+ return this._date.getSeconds();
135
+ }
136
+
137
+ get year(): number {
138
+ return this._calendar.year(this.date);
139
+ }
140
+
141
+ get monthOfYear(): number {
142
+ return this._calendar.monthOfYear(this.date);
143
+ }
144
+
145
+ get month(): AXCalendarMonth {
146
+ return new AXCalendarMonth(this);
147
+ }
148
+
149
+ add(unit: TimeUnit, amount: number): AXDateTime {
150
+ return this._calendar.add(this.date, unit, amount);
151
+ }
152
+
153
+ set(unit: TimeUnit = 'day', value: number): AXDateTime {
154
+ return this._calendar.set(this.date, unit, value);
155
+ }
156
+
157
+ duration(
158
+ end: AXDateTime | Date | string,
159
+ unit: TimeUnit = 'day'
160
+ ): AXTimeSpan {
161
+ const range = new AXDateTimeRange(
162
+ this,
163
+ AXDateTime.convert(end, this.calendar.name())
164
+ );
165
+ return range.duration();
166
+ }
167
+
168
+ startOf(unit: TimeUnit = 'day'): AXDateTime {
169
+ return this._calendar.startOf(this.date, unit);
170
+ }
171
+
172
+ endOf(unit: TimeUnit = 'day'): AXDateTime {
173
+ return this._calendar.endOf(this.date, unit);
174
+ }
175
+
176
+ format(
177
+ format: string = AXConfig.get('dateTime.shortDateFormat') ||
178
+ 'DDD, dd MMM yyyy'
179
+ ): string {
180
+ format = format.replace('ss', this.pad(this.date.getSeconds(), 2));
181
+ format = format.replace('s', this.date.getSeconds().toString());
182
+ format = format.replace(
183
+ 'dd',
184
+ this.pad(this.calendar.dayInMonth(this.date), 2)
185
+ );
186
+ format = format.replace(
187
+ 'd',
188
+ this.calendar.dayInMonth(this.date).toString()
189
+ );
190
+ format = format.replace('mm', this.pad(this.date.getMinutes(), 2));
191
+ format = format.replace('m', this.date.getMinutes().toString());
192
+ format = format.replace(
193
+ 'MMMM',
194
+ this.calendar.monthNames[this.calendar.monthOfYear(this.date) - 1]
195
+ );
196
+ format = format.replace(
197
+ 'MMM',
198
+ this.calendar.monthShortNames[this.calendar.monthOfYear(this.date) - 1]
199
+ );
200
+ format = format.replace(
201
+ 'MM',
202
+ this.pad(this.calendar.monthOfYear(this.date), 2)
203
+ );
204
+ format = format.replace(
205
+ /M(?![ao])/,
206
+ this.calendar.monthOfYear(this.date).toString()
207
+ );
208
+ format = format.replace(
209
+ 'DDDD',
210
+ this.calendar.dayNames[this.calendar.dayInWeek(this.date) - 1]
211
+ );
212
+ format = format.replace(
213
+ 'DDD',
214
+ this.calendar.dayShortNames[this.calendar.dayInWeek(this.date) - 1]
215
+ );
216
+ format = format.replace(
217
+ /D(?!e)/,
218
+ this.calendar.dayNames[this.calendar.dayInWeek(this.date) - 1].substring(
219
+ 0,
220
+ 3
221
+ )
222
+ );
223
+ format = format.replace('yyyy', this.calendar.year(this.date).toString());
224
+ format = format.replace('YYYY', this.calendar.year(this.date).toString());
225
+ format = format.replace(
226
+ 'yy',
227
+ this.calendar.year(this.date).toString().substring(2)
228
+ );
229
+ format = format.replace(
230
+ 'YY',
231
+ this.calendar.year(this.date).toString().substring(2)
232
+ );
233
+ format = format.replace('HH', this.pad(this.date.getHours(), 2));
234
+ format = format.replace('H', this.date.getHours().toString());
235
+ return format;
236
+ }
237
+
238
+ private pad(n, width, z = '0') {
239
+ n = n + '';
240
+ return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
241
+ }
242
+
243
+ toString(): string {
244
+ return this.format();
245
+ }
246
+
247
+ equal(value: any, unit: TimeUnit = 'day') {
248
+ return this.compaire(value, unit) == 0;
249
+ }
250
+
251
+ compaire(value: any, unit: TimeUnit = 'day') {
252
+ // TODO:
253
+ const val = AXDateTime.convert(value);
254
+ if (this.date == val.date) {
255
+ return 0;
256
+ } else if (this.date > val.date) {
257
+ return 1;
258
+ } else {
259
+ return -1;
260
+ }
261
+ }
262
+
263
+ convert(calendar: string) {
264
+ return AXDateTime.convert(this, calendar);
265
+ }
266
+ }
267
+
268
+ export class AXCalendarMonth {
269
+ private _range: AXDateTimeRange;
270
+ public get range(): AXDateTimeRange {
271
+ return this._range;
272
+ }
273
+ public set range(v: AXDateTimeRange) {
274
+ this._range = v;
275
+ }
276
+
277
+ constructor(date: AXDateTime) {
278
+ this.index = date.date.getMonth();
279
+ this.name = date.format('MMMM');
280
+ this.range = new AXDateTimeRange(
281
+ new AXDateTime(date.startOf('month').date, date.calendar),
282
+ new AXDateTime(date.endOf('month').date, date.calendar)
283
+ );
284
+ }
285
+
286
+ private readonly index: number;
287
+ private readonly name: string;
288
+ }
289
+
290
+ export interface AXTimeSpanTotal {
291
+ miliseconds: number;
292
+ seconds: number;
293
+ minutes: number;
294
+ hours: number;
295
+ days: number;
296
+ weeks: number;
297
+ months: number;
298
+ years: number;
299
+ }
300
+
301
+ export interface AXTimeSpan {
302
+ miliseconds: number;
303
+ seconds: number;
304
+ minutes: number;
305
+ hours: number;
306
+ days: number;
307
+ months: number;
308
+ years: number;
309
+ total: AXTimeSpanTotal;
310
+ }
311
+
312
+ export class AXDateTimeRange {
313
+ constructor(public startTime: AXDateTime, public endTime: AXDateTime) { }
314
+
315
+ duration(): AXTimeSpan {
316
+ const result: AXTimeSpan = {
317
+ miliseconds: 0,
318
+ seconds: 0,
319
+ minutes: 0,
320
+ hours: 0,
321
+ days: 0,
322
+ months: 0,
323
+ years: 0,
324
+ total: {
325
+ miliseconds: 0,
326
+ seconds: 0,
327
+ minutes: 0,
328
+ hours: 0,
329
+ days: 0,
330
+ weeks: 0,
331
+ months: 0,
332
+ years: 0,
333
+ },
334
+ };
335
+
336
+ const one_second = 1000;
337
+ const one_min = one_second * 60;
338
+ const one_hour = one_min * 60;
339
+ const one_day = one_hour * 24;
340
+ const one_week = one_day * 7;
341
+ const one_year = 365.25 * one_day;
342
+ const one_month = one_year / 12;
343
+ const startTime = this.startTime.date.getTime();
344
+ const endTime = this.endTime.date.getTime();
345
+ const diff = Math.abs(endTime - startTime);
346
+ //
347
+ result.total.miliseconds = diff;
348
+ result.total.seconds = Number((diff / one_second).toFixed(2));
349
+ result.total.minutes = Number((diff / one_min).toFixed(2));
350
+ result.total.hours = Number((diff / one_hour).toFixed(2));
351
+ result.total.days = Number((diff / one_day).toFixed(2));
352
+ result.total.weeks = Number((diff / one_week).toFixed(2));
353
+ //
354
+ // let months = (this.endTime.year - this.startTime.year) * 12;
355
+ // months += this.endTime.monthOfYear - this.startTime.monthOfYear + 1;
356
+ // if (this.endTime.dayOfYear < this.startTime.dayOfYear) {
357
+ // months--;
358
+ // }
359
+ // result.total.months = Math.abs(months);
360
+ // TODO: review
361
+ result.total.months = Number((diff / one_month).toFixed(2));
362
+ result.total.years = Number((diff / one_year).toFixed(2));
363
+ //
364
+ result.miliseconds = result.total.miliseconds % 1000;
365
+ result.seconds = Number((result.total.seconds % 60).toFixed(0));
366
+ result.minutes = Number((result.total.minutes % 60).toFixed(0));
367
+ result.hours = Number((result.total.hours % 24).toFixed(0));
368
+ // TODO: review
369
+ result.days = Number((result.total.days % 30.4).toFixed(0));
370
+ result.months = Number((result.total.months % 12).toFixed(0));
371
+ result.years = Number(result.total.years.toFixed(0));
372
+ return result;
373
+ }
374
+
375
+ enumurate(unit: TimeUnit = 'day'): AXDateTime[] {
376
+ // TODO: ??
377
+ return [];
378
+ }
379
+
380
+ includes(value: AXDateTime, unit: TimeUnit = 'day'): boolean {
381
+ // TODO: ??
382
+ return true;
383
+ }
384
+
385
+ // getViewCompaire(view) {
386
+ // switch (view) {
387
+ // case 'day':
388
+ // return 'YMD';
389
+ // case 'month':
390
+ // return 'YM';
391
+ // case 'year':
392
+ // return 'Y';
393
+ // }
394
+ // }
395
+ }
@@ -0,0 +1,11 @@
1
+ import { NgModule } from '@angular/core';
2
+ import { AXDateTimePipe } from './datetime.pipe';
3
+
4
+
5
+ @NgModule({
6
+ imports: [],
7
+ exports: [AXDateTimePipe],
8
+ declarations: [AXDateTimePipe],
9
+ providers: [],
10
+ })
11
+ export class AXDateTimeModule { }
@@ -0,0 +1,20 @@
1
+ import { PipeTransform, Pipe } from '@angular/core';
2
+ import { AXDateTime } from './datetime.class';
3
+
4
+ @Pipe({ name: 'axDate' })
5
+ export class AXDateTimePipe implements PipeTransform {
6
+ constructor() { }
7
+
8
+ transform(value: any, format?: string, calendar?: string): string {
9
+ if (value == null) {
10
+ return '';
11
+ }
12
+ const date: AXDateTime = value instanceof AXDateTime ? value.clone() : AXDateTime.convert(value, calendar);
13
+ if (!format) {
14
+ return date.toString();
15
+ }
16
+ else {
17
+ return date.format(format);
18
+ }
19
+ }
20
+ }