@acorex/core 3.0.21 → 3.0.25

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 (188) hide show
  1. package/acorex-core.d.ts +4 -0
  2. package/acorex-core.metadata.json +1 -0
  3. package/bundles/acorex-core.umd.js +2539 -0
  4. package/bundles/acorex-core.umd.js.map +1 -0
  5. package/bundles/acorex-core.umd.min.js +17 -0
  6. package/bundles/acorex-core.umd.min.js.map +1 -0
  7. package/esm2015/acorex-core.js +5 -0
  8. package/esm2015/lib/classes/base-page.class.js +21 -0
  9. package/esm2015/lib/classes/color.class.js +49 -0
  10. package/esm2015/lib/classes/datetime.class.js +314 -0
  11. package/esm2015/lib/classes/menu.class.js +27 -0
  12. package/esm2015/lib/classes/navigator.class.js +1 -0
  13. package/esm2015/lib/classes/popup.class.js +1 -0
  14. package/esm2015/lib/classes/promise.class.js +19 -0
  15. package/esm2015/lib/classes/sectionlist.class.js +1 -0
  16. package/esm2015/lib/classes/select.class.js +3 -0
  17. package/esm2015/lib/core.module.js +24 -0
  18. package/esm2015/lib/error/error.class.js +1 -0
  19. package/esm2015/lib/error/error.module.js +16 -0
  20. package/esm2015/lib/error/error.service.js +25 -0
  21. package/esm2015/lib/events/keyboard.js +1 -0
  22. package/esm2015/lib/http/http-error.class.js +1 -0
  23. package/esm2015/lib/http/http-events.interceptor.js +3 -0
  24. package/esm2015/lib/http/http-request.class.js +1 -0
  25. package/esm2015/lib/http/http-result.class.js +21 -0
  26. package/esm2015/lib/http/http.module.js +29 -0
  27. package/esm2015/lib/http/http.service.js +149 -0
  28. package/{src → esm2015}/lib/locale/en.json +2 -2
  29. package/{src → esm2015}/lib/locale/fa.json +3 -3
  30. package/esm2015/lib/pipe/datetime.pipe.js +24 -0
  31. package/esm2015/lib/pipe/htmlToText.pipe.js +23 -0
  32. package/esm2015/lib/services/config.js +29 -0
  33. package/esm2015/lib/services/event.service.js +36 -0
  34. package/esm2015/lib/services/navigator.service.js +9 -0
  35. package/esm2015/lib/services/storage.service.js +15 -0
  36. package/esm2015/lib/translator/translator.js +26 -0
  37. package/esm2015/lib/translator/translator.module.js +23 -0
  38. package/esm2015/lib/translator/translator.pipe.js +23 -0
  39. package/esm2015/lib/translator/translator.service.js +21 -0
  40. package/esm2015/lib/utils/array/array-util.js +133 -0
  41. package/esm2015/lib/utils/html/html-util.js +192 -0
  42. package/esm2015/lib/utils/html/html.module.js +16 -0
  43. package/esm2015/lib/utils/math/math-util.js +6 -0
  44. package/esm2015/lib/utils/object/object-util.js +83 -0
  45. package/esm2015/lib/utils/render/on-demand-preload-strategy.service.js +21 -0
  46. package/esm2015/lib/utils/render/render.service.js +112 -0
  47. package/esm2015/lib/utils/render/rendering.module.js +26 -0
  48. package/esm2015/lib/utils/scroll/scroll.directive.js +66 -0
  49. package/esm2015/lib/utils/scroll/scroll.module.js +16 -0
  50. package/esm2015/lib/utils/separator/separator.module.js +16 -0
  51. package/esm2015/lib/utils/separator/separator.pipe.js +22 -0
  52. package/esm2015/public-api.js +36 -0
  53. package/esm5/acorex-core.js +5 -0
  54. package/esm5/lib/classes/base-page.class.js +23 -0
  55. package/esm5/lib/classes/color.class.js +54 -0
  56. package/esm5/lib/classes/datetime.class.js +390 -0
  57. package/esm5/lib/classes/menu.class.js +42 -0
  58. package/esm5/lib/classes/navigator.class.js +1 -0
  59. package/esm5/lib/classes/popup.class.js +1 -0
  60. package/esm5/lib/classes/promise.class.js +22 -0
  61. package/esm5/lib/classes/sectionlist.class.js +1 -0
  62. package/esm5/lib/classes/select.class.js +7 -0
  63. package/esm5/lib/core.module.js +27 -0
  64. package/esm5/lib/error/error.class.js +1 -0
  65. package/esm5/lib/error/error.module.js +19 -0
  66. package/esm5/lib/error/error.service.js +26 -0
  67. package/esm5/lib/events/keyboard.js +1 -0
  68. package/esm5/lib/http/http-error.class.js +1 -0
  69. package/esm5/lib/http/http-events.interceptor.js +3 -0
  70. package/esm5/lib/http/http-request.class.js +1 -0
  71. package/esm5/lib/http/http-result.class.js +24 -0
  72. package/esm5/lib/http/http.module.js +33 -0
  73. package/esm5/lib/http/http.service.js +157 -0
  74. package/esm5/lib/locale/en.json +249 -0
  75. package/esm5/lib/locale/fa.json +238 -0
  76. package/esm5/lib/pipe/datetime.pipe.js +26 -0
  77. package/esm5/lib/pipe/htmlToText.pipe.js +26 -0
  78. package/esm5/lib/services/config.js +37 -0
  79. package/esm5/lib/services/event.service.js +37 -0
  80. package/esm5/lib/services/navigator.service.js +12 -0
  81. package/esm5/lib/services/storage.service.js +18 -0
  82. package/esm5/lib/translator/translator.js +34 -0
  83. package/esm5/lib/translator/translator.module.js +24 -0
  84. package/esm5/lib/translator/translator.pipe.js +25 -0
  85. package/esm5/lib/translator/translator.service.js +24 -0
  86. package/esm5/lib/utils/array/array-util.js +147 -0
  87. package/esm5/lib/utils/html/html-util.js +224 -0
  88. package/esm5/lib/utils/html/html.module.js +19 -0
  89. package/esm5/lib/utils/math/math-util.js +10 -0
  90. package/esm5/lib/utils/object/object-util.js +88 -0
  91. package/esm5/lib/utils/render/on-demand-preload-strategy.service.js +22 -0
  92. package/esm5/lib/utils/render/render.service.js +117 -0
  93. package/esm5/lib/utils/render/rendering.module.js +29 -0
  94. package/esm5/lib/utils/scroll/scroll.directive.js +68 -0
  95. package/esm5/lib/utils/scroll/scroll.module.js +19 -0
  96. package/esm5/lib/utils/separator/separator.module.js +19 -0
  97. package/esm5/lib/utils/separator/separator.pipe.js +25 -0
  98. package/esm5/public-api.js +36 -0
  99. package/fesm2015/acorex-core.js +2057 -0
  100. package/fesm2015/acorex-core.js.map +1 -0
  101. package/fesm5/acorex-core.js +2274 -0
  102. package/fesm5/acorex-core.js.map +1 -0
  103. package/lib/classes/base-page.class.d.ts +10 -0
  104. package/lib/classes/color.class.d.ts +17 -0
  105. package/lib/classes/datetime.class.d.ts +63 -0
  106. package/lib/classes/menu.class.d.ts +34 -0
  107. package/{src/lib/classes/navigator.class.ts → lib/classes/navigator.class.d.ts} +1 -1
  108. package/{src/lib/classes/popup.class.ts → lib/classes/popup.class.d.ts} +0 -2
  109. package/lib/classes/promise.class.d.ts +7 -0
  110. package/{src/lib/classes/sectionlist.class.ts → lib/classes/sectionlist.class.d.ts} +0 -0
  111. package/lib/classes/select.class.d.ts +7 -0
  112. package/lib/core.module.d.ts +2 -0
  113. package/{src/lib/error/error.class.ts → lib/error/error.class.d.ts} +0 -0
  114. package/lib/error/error.module.d.ts +2 -0
  115. package/lib/error/error.service.d.ts +10 -0
  116. package/{src/lib/events/keyboard.ts → lib/events/keyboard.d.ts} +0 -3
  117. package/{src/lib/http/http-error.class.ts → lib/http/http-error.class.d.ts} +2 -2
  118. package/{src/lib/http/http-events.interceptor.ts → lib/http/http-events.interceptor.d.ts} +3 -7
  119. package/{src/lib/http/http-request.class.ts → lib/http/http-request.class.d.ts} +5 -5
  120. package/lib/http/http-result.class.d.ts +11 -0
  121. package/lib/http/http.module.d.ts +4 -0
  122. package/lib/http/http.service.d.ts +20 -0
  123. package/lib/pipe/datetime.pipe.d.ts +5 -0
  124. package/lib/pipe/htmlToText.pipe.d.ts +4 -0
  125. package/lib/services/config.d.ts +9 -0
  126. package/lib/services/event.service.d.ts +6 -0
  127. package/lib/services/navigator.service.d.ts +5 -0
  128. package/lib/services/storage.service.d.ts +4 -0
  129. package/lib/translator/translator.d.ts +9 -0
  130. package/lib/translator/translator.module.d.ts +3 -0
  131. package/lib/translator/translator.pipe.d.ts +5 -0
  132. package/lib/translator/translator.service.d.ts +5 -0
  133. package/lib/utils/array/array-util.d.ts +6 -0
  134. package/lib/utils/html/html-util.d.ts +62 -0
  135. package/lib/utils/html/html.module.d.ts +2 -0
  136. package/lib/utils/math/math-util.d.ts +3 -0
  137. package/lib/utils/object/object-util.d.ts +7 -0
  138. package/lib/utils/render/on-demand-preload-strategy.service.d.ts +7 -0
  139. package/lib/utils/render/render.service.d.ts +14 -0
  140. package/lib/utils/render/rendering.module.d.ts +4 -0
  141. package/lib/utils/scroll/scroll.directive.d.ts +13 -0
  142. package/lib/utils/scroll/scroll.module.d.ts +2 -0
  143. package/lib/utils/separator/separator.module.d.ts +2 -0
  144. package/lib/utils/separator/separator.pipe.d.ts +4 -0
  145. package/package.json +23 -13
  146. package/{src/public-api.ts → public-api.d.ts} +0 -9
  147. package/karma.conf.js +0 -32
  148. package/ng-package.json +0 -10
  149. package/src/lib/classes/base-page.class.ts +0 -27
  150. package/src/lib/classes/color.class.ts +0 -61
  151. package/src/lib/classes/datetime.class.ts +0 -374
  152. package/src/lib/classes/menu.class.ts +0 -37
  153. package/src/lib/classes/promise.class.ts +0 -25
  154. package/src/lib/classes/select.class.ts +0 -7
  155. package/src/lib/core.module.ts +0 -21
  156. package/src/lib/error/error.module.ts +0 -13
  157. package/src/lib/error/error.service.ts +0 -23
  158. package/src/lib/error/index.ts +0 -3
  159. package/src/lib/http/http-result.class.ts +0 -34
  160. package/src/lib/http/http.module.ts +0 -25
  161. package/src/lib/http/http.service.ts +0 -159
  162. package/src/lib/pipe/datetime.pipe.ts +0 -20
  163. package/src/lib/pipe/htmlToText.pipe.ts +0 -18
  164. package/src/lib/services/config.ts +0 -36
  165. package/src/lib/services/event.service.ts +0 -31
  166. package/src/lib/services/navigator.service.ts +0 -8
  167. package/src/lib/services/storage.service.ts +0 -11
  168. package/src/lib/translator/translator.module.ts +0 -19
  169. package/src/lib/translator/translator.pipe.ts +0 -22
  170. package/src/lib/translator/translator.service.ts +0 -19
  171. package/src/lib/translator/translator.ts +0 -31
  172. package/src/lib/utils/array/array-util.ts +0 -140
  173. package/src/lib/utils/html/html-util.ts +0 -264
  174. package/src/lib/utils/html/html.module.ts +0 -11
  175. package/src/lib/utils/math/math-util.ts +0 -5
  176. package/src/lib/utils/object/object-util.ts +0 -87
  177. package/src/lib/utils/render/on-demand-preload-strategy.service.ts +0 -26
  178. package/src/lib/utils/render/render.service.ts +0 -107
  179. package/src/lib/utils/render/rendering.module.ts +0 -25
  180. package/src/lib/utils/scroll/scroll.directive.ts +0 -35
  181. package/src/lib/utils/scroll/scroll.module.ts +0 -11
  182. package/src/lib/utils/separator/separator.module.ts +0 -11
  183. package/src/lib/utils/separator/separator.pipe.ts +0 -15
  184. package/src/test.ts +0 -26
  185. package/tsconfig.lib.json +0 -23
  186. package/tsconfig.lib.prod.json +0 -6
  187. package/tsconfig.spec.json +0 -18
  188. package/tslint.json +0 -17
@@ -1,159 +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
- .request<T>(config.method, config.url, this.mapOptions(config))
52
- //.pipe(this.retry)
53
- .subscribe(data => {
54
- this.handleResult(data, result, complete, config);
55
- }, c => {
56
- this.handleError(c, error, complete, config);
57
- });
58
- });
59
- })
60
- }
61
-
62
-
63
- private handleResult(data, result, complete, config: AXHttpRequestOptions) {
64
- if (this.interceptor) {
65
- this.interceptor.success(config, data).then(c => {
66
- if (result)
67
- result(c);
68
- this.handleComplete(complete, config);
69
- });
70
- }
71
- else {
72
- //
73
- if (result)
74
- result(data);
75
- this.handleComplete(complete, config);
76
- }
77
- }
78
-
79
- private handleBegin(config: AXHttpRequestOptions): Promise<AXHttpRequestOptions> {
80
- return new Promise((resolve) => {
81
- if (!config.headers)
82
- config.headers = {};
83
- if (!config.params)
84
- config.params = {};
85
- //
86
- if (this.interceptor) {
87
- this.interceptor.begin(config).then(c => {
88
- resolve(c);
89
- });
90
- }
91
- else {
92
- resolve(config)
93
- }
94
- })
95
- }
96
-
97
- private handleComplete(complete: Function, config: AXHttpRequestOptions) {
98
- if (complete)
99
- complete();
100
- if (this.interceptor)
101
- this.interceptor.complete(config);
102
- }
103
-
104
- private handleError(c: HttpErrorResponse, error: Function, complete: Function, config: AXHttpRequestOptions) {
105
- let r: IHttpError = {
106
- message: c.message,
107
- status: c.status,
108
- code: c.status?.toString(),
109
- handled: false,
110
- error: c.error
111
- }
112
- if (error) {
113
- error(r);
114
- }
115
- if (!r.handled) {
116
- if (this.interceptor)
117
- this.interceptor.error(config, r);
118
- }
119
- this.handleComplete(complete, config);
120
- }
121
-
122
- private mapOptions(options: AXHttpRequestOptions) {
123
- let headers = new HttpHeaders();
124
-
125
- for (const key in options.headers) {
126
- if (options.headers.hasOwnProperty(key)) {
127
- const value = options.headers[key];
128
- headers = headers.set(key, value)
129
- }
130
- }
131
- let params = new HttpParams();
132
- for (const key in options.params) {
133
- if (options.params.hasOwnProperty(key)) {
134
- const value = options.params[key];
135
- params = params.set(key, value);
136
- }
137
- }
138
- return {
139
- headers: headers,
140
- params: params,
141
- body: options.body,
142
- responseType: options.responseType || 'json'
143
- };
144
- // if (options.method == "get") {
145
- // return {
146
- // headers: headers,
147
- // params: params
148
- // };
149
- // }
150
- // else {
151
- // return {
152
- // headers: headers,
153
- // params: params,
154
- // body: options.body
155
- // };
156
- // }
157
- }
158
-
159
- }
@@ -1,20 +0,0 @@
1
- import { PipeTransform, Pipe } from '@angular/core';
2
- import { AXDateTime } from '../classes/datetime.class';
3
-
4
- @Pipe({ name: 'dt' })
5
- export class AXDateTimePipe implements PipeTransform {
6
- constructor() { }
7
-
8
- transform(value: any, format?: string): string {
9
- const date: AXDateTime = AXDateTime.convert(value);
10
- if (value == null) {
11
- return '';
12
- }
13
- if (!format) {
14
- return date.toString();
15
- }
16
- else {
17
- return date.format(format);
18
- }
19
- }
20
- }
@@ -1,18 +0,0 @@
1
- import { Pipe, PipeTransform } from '@angular/core';
2
-
3
- @Pipe({ name: 'html2text' })
4
- export class AXHtmlToTextPipe implements PipeTransform {
5
- transform(value: string) {
6
- if (value) {
7
- const regexHtml = /<\/?[^>]+>/gi;
8
- const regexNbsp = /&nbsp;/gi;
9
- const regexAmp = /&amp;/gi;
10
- return value
11
- .replace(regexHtml, '')
12
- .replace(regexNbsp, '')
13
- .replace(regexAmp, '');
14
- } else {
15
- return '';
16
- }
17
- }
18
- }
@@ -1,36 +0,0 @@
1
- import { Subject, Observable } from 'rxjs';
2
- import { getPropByPath, setPropByPath } from '../utils/object/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
- 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): any {
34
- return getPropByPath(AXConfig.dataModel, path);
35
- }
36
- }
@@ -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 => {
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
- }
@@ -1,8 +0,0 @@
1
- import { Injectable } from '@angular/core';
2
- import { AXNavigatorParam } from '../classes/navigator.class';
3
-
4
- @Injectable()
5
- export abstract class AXNavigator {
6
- abstract navigate(params: AXNavigatorParam);
7
- abstract popup(params: AXNavigatorParam);
8
- }
@@ -1,11 +0,0 @@
1
- import { Injectable } from '@angular/core';
2
-
3
- @Injectable()
4
- export class AXStorageService {
5
- get(key: string): any {
6
- return localStorage.getItem(key) as any;
7
- }
8
- set(key: string, value: any): void {
9
- localStorage.setItem(key, value as string);
10
- }
11
- }
@@ -1,19 +0,0 @@
1
- import { NgModule } from '@angular/core';
2
- import { AXTranslatorPipe } from './translator.pipe';
3
- import * as en from '../locale/en.json';
4
- import * as fa from '../locale/fa.json';
5
- import { AXTranslator } from './translator';
6
-
7
-
8
- @NgModule({
9
- imports: [],
10
- exports: [AXTranslatorPipe],
11
- declarations: [AXTranslatorPipe],
12
- providers: [],
13
- })
14
- export class AXTranslatorModule {
15
- constructor() {
16
- AXTranslator.load('en', en);
17
- AXTranslator.load('fa', fa);
18
- }
19
- }
@@ -1,22 +0,0 @@
1
- import { Pipe, PipeTransform } from '@angular/core';
2
- import { AXTranslator } from './translator';
3
-
4
- @Pipe({ name: 'trans', pure: true })
5
- export class AXTranslatorPipe implements PipeTransform {
6
-
7
- constructor() { }
8
-
9
- // transform(value: string, lang?: string): Promise<string> {
10
- // return new Promise<string>((resolve, reject) => {
11
- // if (!value) {
12
- // resolve(value);
13
- // }
14
- // resolve(this.translate.get(value, lang));
15
- // });
16
-
17
- // }
18
-
19
- transform(value: string, lang?: string): string {
20
- return AXTranslator.get(value, lang);
21
- }
22
- }
@@ -1,19 +0,0 @@
1
- import { Injectable } from '@angular/core';
2
- import { AXTranslator } from './translator';
3
-
4
- @Injectable({ providedIn: 'platform' })
5
- export class AXTranslatorService {
6
-
7
- public load(lang: string, value: any) {
8
- AXTranslator.load(lang, value);
9
- }
10
-
11
- public use(lang: string) {
12
- AXTranslator.use(lang);
13
- }
14
-
15
- public get(key: string, lang?: string): string {
16
- return AXTranslator.get(lang, lang);
17
- }
18
- }
19
-
@@ -1,31 +0,0 @@
1
- import { Subject, Observable } from 'rxjs';
2
- import { getPropByPath} from '../utils/object/object-util';
3
- import merge from 'lodash-es/merge';
4
-
5
- // @dynamic
6
- export class AXTranslator {
7
- private static lang: string = 'en';
8
- private static dataChangeSubject = new Subject<any>();
9
-
10
-
11
- static get onChange(): Observable<any> {
12
- return AXTranslator.dataChangeSubject.asObservable();
13
- }
14
-
15
- public static load(lang: string, value: any) {
16
- if (typeof value === 'object') {
17
- if (!AXTranslator[`__data__${lang}`]) {
18
- AXTranslator[`__data__${lang}`] = {};
19
- }
20
- AXTranslator[`__data__${lang}`] = merge(AXTranslator[`__data__${lang}`], value);
21
- }
22
- }
23
-
24
- public static use(lang: string) {
25
- AXTranslator.lang = lang;
26
- }
27
-
28
- public static get(key: string, lang?: string): string {
29
- return getPropByPath(AXTranslator[`__data__${lang || AXTranslator.lang}`], key) || key;
30
- }
31
- }
@@ -1,140 +0,0 @@
1
- import { AXFetchProp } from '../object/object-util';
2
-
3
- // @dynamic
4
- export class AXArrayUtil {
5
-
6
-
7
- static pickRandom(array: any[]): any {
8
- return array[Math.floor(Math.random() * array.length)];
9
- }
10
-
11
-
12
- static insert(array: any[], index, ...rest) {
13
- array.splice.apply(array, [index, 0].concat(Array.prototype.slice.call(rest, 1)));
14
- return array;
15
- }
16
-
17
- static range(min: number, max: number): number[] {
18
- return new Array(max - min).fill(1).map((d, i) => i);
19
- }
20
-
21
- static filter(array: any[], filters: any[]): any[] {
22
- if (filters == null || filters.length === 0) {
23
- return array;
24
- }
25
- const lamda = (item) => {
26
- let result = true;
27
- for (const key in filters) {
28
- if (filters.hasOwnProperty(key)) {
29
- const f = filters[key];
30
- if (f !== 'AND') {
31
- const vals = [];
32
- const mt = f.field.match(/\[\:(.*?)\]/);
33
- if (mt && mt.length > 1) {
34
- const p1 = f.field.replace(mt[0], '');
35
- const p2 = mt[1];
36
- const prop = AXFetchProp(item, p1);
37
- if (prop instanceof Array && prop.length) {
38
- vals.push(...prop.map(m => (AXFetchProp(m, p2))));
39
- } else {
40
- result = false;
41
- }
42
- } else {
43
- vals.push(AXFetchProp(item, f.field));
44
- }
45
- for (const j in vals) {
46
- if (vals.hasOwnProperty(j)) {
47
- let v1 = vals[j];
48
- const v2 = f.value;
49
- if (f.dataType === 'string') {
50
- v1 = v1.toString();
51
- switch (f.condition) {
52
- case 'equal':
53
- result = (v1 && v2) && v1.toLowerCase() === v2.toLowerCase();
54
- break;
55
- case 'not-equal':
56
- result = !((v1 && v2) && v1.toLowerCase() === v2.toLowerCase());
57
- break;
58
- case 'contains':
59
- result = ((v1 && v2) && (v1.toLowerCase().includes(v2.toLowerCase())));
60
- break;
61
- case 'not-contains':
62
- result = !((v1 && v2) && (v1.toLowerCase().includes(v2.toLowerCase())));
63
- break;
64
- case 'start-with':
65
- result = ((v1 && v2) && (v1.toLowerCase().startsWith(v2.toLowerCase())));
66
- break;
67
- case 'end-with':
68
- result = ((v1 && v2) && (v1.toLowerCase().endsWith(v2.toLowerCase())));
69
- break;
70
- case 'is-empty':
71
- result = v1 == null || v1 === undefined;
72
- break;
73
- case 'is-not-empty':
74
- result = !(v1 == null || v1 === undefined);
75
- break;
76
- default:
77
- console.error('The condition is not defined');
78
- result = false;
79
- }
80
- } else if (f.dataType === 'date') {
81
- } else if (f.dataType === 'number') {
82
- v1 = Number(v1);
83
- switch (f.condition) {
84
- case 'equal':
85
- result = v1 === v2;
86
- break;
87
- case 'not-equal':
88
- result = v1 !== v2;
89
- break;
90
- case 'contains':
91
- result = v2 && v2 instanceof Array && v2.includes(v1);
92
- break;
93
- case 'less-than':
94
- result = v1 < v2;
95
- break;
96
- case 'less-than-equal':
97
- result = v1 <= v2;
98
- break;
99
- case 'greater-than':
100
- result = v1 > v2;
101
- break;
102
- case 'greater-than-equal':
103
- result = v1 >= v2;
104
- break;
105
- case 'is-empty':
106
- result = v1 == null || v1 === undefined;
107
- break;
108
- case 'is-not-empty':
109
- result = !(v1 == null || v1 === undefined);
110
- break;
111
- default:
112
- console.error('The condition is not defined');
113
- result = false;
114
- }
115
- } else {
116
- console.error('The datatype is not supported');
117
- result = false;
118
- }
119
- if (result) {
120
- break;
121
- }
122
- }
123
- }
124
- }
125
- if (!result) {
126
- return false;
127
- }
128
- }
129
- }
130
- return true;
131
- };
132
- return array.filter(lamda);
133
- }
134
-
135
- }
136
-
137
-
138
-
139
-
140
-