coer-elements 0.0.7 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- package/components/index.d.ts +2 -0
- package/components/lib/coer-alert/coer-alert.component.d.ts +23 -0
- package/components/lib/components.module.d.ts +10 -0
- package/esm2022/coer-elements.mjs +2 -2
- package/esm2022/components/index.mjs +3 -0
- package/esm2022/components/lib/coer-alert/coer-alert.component.mjs +227 -0
- package/esm2022/components/lib/components.module.mjs +92 -0
- package/esm2022/public_api.mjs +2 -0
- package/fesm2022/coer-elements.mjs +309 -0
- package/fesm2022/coer-elements.mjs.map +1 -1
- package/index.d.ts +5 -1
- package/package.json +1 -1
- package/public_api.d.ts +1 -0
- package/src/styles/bootstrap.scss +15 -0
- package/src/styles/coer-elements.scss +29 -0
- package/{styles → src/styles}/colors.scss +27 -1
- package/src/styles/containers.scss +34 -0
- package/src/styles/cursores.scss +11 -0
- package/src/styles/layout.scss +21 -0
- package/src/styles/scroll-bar.scss +20 -0
- package/styles/{index.css → coer-elements.css} +268 -26
- package/components/index.ts +0 -2
- package/components/src/coer-alert/coer-alert.component.html +0 -56
- package/components/src/coer-alert/coer-alert.component.scss +0 -100
- package/components/src/coer-alert/coer-alert.component.ts +0 -249
- package/components/src/components.module.ts +0 -97
- package/esm2022/index.mjs +0 -2
- package/interfaces/index.ts +0 -6
- package/interfaces/src/IAppSource.interface.ts +0 -4
- package/interfaces/src/IBreadcrumb.interface.ts +0 -6
- package/interfaces/src/ICoerRef.interface.ts +0 -11
- package/interfaces/src/IGoBack.interface.ts +0 -6
- package/interfaces/src/IPatch.interface.ts +0 -5
- package/interfaces/src/IScreenSize.interface.ts +0 -5
- package/styles/index.scss +0 -98
- package/tools/index.ts +0 -8
- package/tools/src/Breadcrumbs.class.ts +0 -84
- package/tools/src/ControlValue.ts +0 -63
- package/tools/src/DateTime.class.ts +0 -27
- package/tools/src/Files.class.ts +0 -119
- package/tools/src/Page.class.ts +0 -197
- package/tools/src/Screen.class.ts +0 -50
- package/tools/src/Source.class.ts +0 -107
- package/tools/src/Tools.ts +0 -217
package/tools/src/Files.class.ts
DELETED
@@ -1,119 +0,0 @@
|
|
1
|
-
import * as XLSX from 'xlsx';
|
2
|
-
import { Tools } from './Tools';
|
3
|
-
|
4
|
-
export class Files {
|
5
|
-
public static readonly EXCEL_EXTENSIONS: string[] = ['xls', 'xlsx', 'csv'];
|
6
|
-
|
7
|
-
/** Get Extension File */
|
8
|
-
public static GetExtension(file: File): string | null {
|
9
|
-
const fileName = file.name;
|
10
|
-
|
11
|
-
if (fileName.includes('.')) {
|
12
|
-
let worlds = fileName.split('.') as string[];
|
13
|
-
|
14
|
-
if (worlds.length > 0) {
|
15
|
-
let extension = worlds.pop()!;
|
16
|
-
extension = extension.trim().toLowerCase();
|
17
|
-
if (extension.length > 0) return extension;
|
18
|
-
}
|
19
|
-
}
|
20
|
-
|
21
|
-
return null;
|
22
|
-
}
|
23
|
-
|
24
|
-
|
25
|
-
/** Is Excel File */
|
26
|
-
public static IsExcel(file: File): boolean {
|
27
|
-
const EXTENSION = Files.GetExtension(file);
|
28
|
-
|
29
|
-
return Tools.IsNotNull(EXTENSION)
|
30
|
-
? this.EXCEL_EXTENSIONS.includes(EXTENSION!)
|
31
|
-
: false;
|
32
|
-
}
|
33
|
-
|
34
|
-
|
35
|
-
/** Read excel file */
|
36
|
-
public static ReadExcel<T>(file: File) {
|
37
|
-
return new Promise<{ columns: string[]; rows: T[]; }>(Resolve => {
|
38
|
-
let columns: string[] = [];
|
39
|
-
let rows: T[] = [];
|
40
|
-
|
41
|
-
const reader = new FileReader();
|
42
|
-
reader.readAsArrayBuffer(file);
|
43
|
-
|
44
|
-
reader.onload = () => {
|
45
|
-
const dataBytes = new Uint8Array(reader.result as any);
|
46
|
-
|
47
|
-
if (dataBytes) {
|
48
|
-
const workbook = XLSX.read(dataBytes, {});
|
49
|
-
const sheet = workbook.Sheets[workbook.SheetNames[0]];
|
50
|
-
let dataSheet: any[] = XLSX.utils.sheet_to_json(sheet, {
|
51
|
-
header: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
|
52
|
-
});
|
53
|
-
|
54
|
-
//Get Headers
|
55
|
-
for(const column in dataSheet[0]) {
|
56
|
-
columns.push(Tools.FirstCharToLower(String(dataSheet[0][column]).replaceAll(' ', '')));
|
57
|
-
}
|
58
|
-
|
59
|
-
//Get Rows
|
60
|
-
rows = XLSX.utils.sheet_to_json(sheet, { header: columns });
|
61
|
-
rows.shift();
|
62
|
-
|
63
|
-
rows = rows.map(row => {
|
64
|
-
const item = Tools.BreakReference<any>(row);
|
65
|
-
delete item['__rowNum__'];
|
66
|
-
return item;
|
67
|
-
});
|
68
|
-
}
|
69
|
-
|
70
|
-
Resolve({ columns, rows });
|
71
|
-
}
|
72
|
-
|
73
|
-
reader.onerror = () => { Resolve({ columns, rows }) }
|
74
|
-
});
|
75
|
-
}
|
76
|
-
|
77
|
-
|
78
|
-
/** Export to excel file */
|
79
|
-
public static ExportExcel<T>(data: T[], fileName: string = 'coer_report', sheetName: string = 'Sheet1') {
|
80
|
-
sheetName = Tools.CleanUpBlanks(sheetName);
|
81
|
-
fileName = Tools.CleanUpBlanks(fileName);
|
82
|
-
|
83
|
-
if(fileName.endsWith('.xls') || fileName.endsWith('.xlsx') || fileName.endsWith('.csv')) {
|
84
|
-
if (fileName.includes('.xls')) {
|
85
|
-
fileName = fileName.replaceAll('.xls', '.xlsx');
|
86
|
-
}
|
87
|
-
|
88
|
-
if (fileName.includes('.csv')) {
|
89
|
-
fileName = fileName.replaceAll('.csv', '.xlsx');
|
90
|
-
}
|
91
|
-
}
|
92
|
-
|
93
|
-
else {
|
94
|
-
fileName += '.xlsx';
|
95
|
-
}
|
96
|
-
|
97
|
-
const WORK_SHEET = XLSX.utils.json_to_sheet(data);
|
98
|
-
const WORK_BOOK = XLSX.utils.book_new();
|
99
|
-
XLSX.utils.book_append_sheet(WORK_BOOK, WORK_SHEET, 'Sheet1');
|
100
|
-
XLSX.writeFile(WORK_BOOK, fileName);
|
101
|
-
}
|
102
|
-
|
103
|
-
|
104
|
-
/** Convert file to string base64 */
|
105
|
-
public static ConvertToBase64(file: File) {
|
106
|
-
return new Promise<string>(Resolve => {
|
107
|
-
const reader = new FileReader();
|
108
|
-
reader.readAsDataURL(file);
|
109
|
-
|
110
|
-
reader.onload = () => {
|
111
|
-
Resolve(reader.result?.toString() || '');
|
112
|
-
}
|
113
|
-
|
114
|
-
reader.onerror = () => {
|
115
|
-
Resolve('');
|
116
|
-
}
|
117
|
-
});
|
118
|
-
}
|
119
|
-
}
|
package/tools/src/Page.class.ts
DELETED
@@ -1,197 +0,0 @@
|
|
1
|
-
import { ActivatedRoute, Router } from '@angular/router';
|
2
|
-
import { AfterViewInit, Component, Inject, inject, OnDestroy } from '@angular/core';
|
3
|
-
import { IAppSource, IBreadcrumb, IGoBack } from '../../interfaces';
|
4
|
-
import { CoerAlert } from '../../components';
|
5
|
-
import { Source } from './Source.class';
|
6
|
-
import { Tools } from './Tools';
|
7
|
-
import { Breadcrumbs } from './Breadcrumbs.class';
|
8
|
-
|
9
|
-
@Component({ template: '' })
|
10
|
-
export class Page implements AfterViewInit, OnDestroy {
|
11
|
-
|
12
|
-
//Injection
|
13
|
-
protected readonly alert = inject(CoerAlert);
|
14
|
-
protected readonly router = inject(Router);
|
15
|
-
private readonly activatedRoute = inject(ActivatedRoute);
|
16
|
-
|
17
|
-
/** */
|
18
|
-
protected isUpdate: boolean = false;
|
19
|
-
|
20
|
-
/** */
|
21
|
-
protected isLoading: boolean = false;
|
22
|
-
|
23
|
-
/** */
|
24
|
-
protected isReady: boolean = false;
|
25
|
-
|
26
|
-
/** */
|
27
|
-
protected enableAnimations: boolean = false;
|
28
|
-
|
29
|
-
/** */
|
30
|
-
protected routeParams: any;
|
31
|
-
|
32
|
-
/** */
|
33
|
-
protected queryParams: any;
|
34
|
-
|
35
|
-
/** */
|
36
|
-
protected breadcrumbs: IBreadcrumb[] = [];
|
37
|
-
|
38
|
-
/** */
|
39
|
-
protected pageResponse: any = null;
|
40
|
-
|
41
|
-
/** */
|
42
|
-
protected goBack: IGoBack = { show: false };
|
43
|
-
|
44
|
-
//Private Variables
|
45
|
-
private _page: string = '';
|
46
|
-
private _source: IAppSource | null = null;
|
47
|
-
private _preventDestroy: boolean = false;
|
48
|
-
|
49
|
-
|
50
|
-
constructor(@Inject(String) page: string) {
|
51
|
-
this.SetPageName(page);
|
52
|
-
this.SetSource();
|
53
|
-
this.GetSource();
|
54
|
-
this.GetNavigation();
|
55
|
-
this.SetGoBack();
|
56
|
-
this.GetPageResponse();
|
57
|
-
}
|
58
|
-
|
59
|
-
ngAfterViewInit() {
|
60
|
-
this.routeParams = this.activatedRoute.snapshot.params;
|
61
|
-
this.queryParams = this.activatedRoute.snapshot.queryParams;
|
62
|
-
|
63
|
-
setTimeout(() => {
|
64
|
-
this.isReady = true;
|
65
|
-
this.RunPage();
|
66
|
-
setTimeout(() => { this.enableAnimations = true }, 1000);
|
67
|
-
});
|
68
|
-
|
69
|
-
}
|
70
|
-
|
71
|
-
ngOnDestroy() {
|
72
|
-
if (!this._preventDestroy) Source.ClearPageResponse();
|
73
|
-
}
|
74
|
-
|
75
|
-
/** Main method. Starts after ngAfterViewInit() */
|
76
|
-
protected RunPage(): void {};
|
77
|
-
|
78
|
-
|
79
|
-
/** Rename the last breadcrumb and update the url id */
|
80
|
-
protected SetPageName(name: string, id: string | number | null = null): void {
|
81
|
-
this._page = name;
|
82
|
-
|
83
|
-
let path = this.router.url;
|
84
|
-
if (path.includes('?')) path = path.split('?')[0];
|
85
|
-
|
86
|
-
if (id) {
|
87
|
-
const PATH_ARRAY = path.split('/');
|
88
|
-
const PATH_ID = Tools.BreakReference(PATH_ARRAY).pop();
|
89
|
-
if (PATH_ID) {
|
90
|
-
PATH_ARRAY[PATH_ARRAY.length - 1] = String(id);
|
91
|
-
path = PATH_ARRAY.join('/');
|
92
|
-
}
|
93
|
-
}
|
94
|
-
|
95
|
-
if (this.breadcrumbs.length > 0) {
|
96
|
-
this.breadcrumbs[this.breadcrumbs.length - 1].page = name;
|
97
|
-
this.breadcrumbs[this.breadcrumbs.length - 1].path = path;
|
98
|
-
Breadcrumbs.SetLast(name, path);
|
99
|
-
}
|
100
|
-
|
101
|
-
this.router.navigateByUrl(path)
|
102
|
-
}
|
103
|
-
|
104
|
-
|
105
|
-
/** */
|
106
|
-
private SetSource(): void {
|
107
|
-
Source.Set(this._page);
|
108
|
-
}
|
109
|
-
|
110
|
-
|
111
|
-
/** */
|
112
|
-
private GetSource(): void {
|
113
|
-
this._source = Source.Get();
|
114
|
-
}
|
115
|
-
|
116
|
-
|
117
|
-
/** */
|
118
|
-
protected GetPageResponse(): void {
|
119
|
-
this.pageResponse = Source.GetPageResponse();
|
120
|
-
}
|
121
|
-
|
122
|
-
|
123
|
-
/** */
|
124
|
-
private GetNavigation(): void {
|
125
|
-
if (this._source) {
|
126
|
-
this.breadcrumbs = Breadcrumbs.Get().map(item => Object.assign({
|
127
|
-
page: item.page,
|
128
|
-
path: item.path,
|
129
|
-
click: this.GoBack(item.path)
|
130
|
-
}));
|
131
|
-
}
|
132
|
-
|
133
|
-
else this.breadcrumbs = [{ page: this._page }];
|
134
|
-
}
|
135
|
-
|
136
|
-
|
137
|
-
/** */
|
138
|
-
private SetGoBack(): void {
|
139
|
-
if (this._source) {
|
140
|
-
this.goBack = {
|
141
|
-
show: true,
|
142
|
-
path: this._source.path,
|
143
|
-
click: this.GoBack()
|
144
|
-
};
|
145
|
-
}
|
146
|
-
}
|
147
|
-
|
148
|
-
|
149
|
-
/** */
|
150
|
-
private GoBack = (path?: string) => (() => {
|
151
|
-
if (path) Breadcrumbs.Remove(path);
|
152
|
-
else Breadcrumbs.RemoveLast();
|
153
|
-
});
|
154
|
-
|
155
|
-
|
156
|
-
/** Navigate to previous page */
|
157
|
-
protected GoToSource<T>(pageResponse: T | null = null): void {
|
158
|
-
if(this._source) {
|
159
|
-
Breadcrumbs.RemoveLast();
|
160
|
-
this.SetPageResponse(pageResponse);
|
161
|
-
Tools.Sleep().then(_ => this.router.navigateByUrl(this._source!.path));
|
162
|
-
}
|
163
|
-
};
|
164
|
-
|
165
|
-
|
166
|
-
/** */
|
167
|
-
protected SetPageResponse<T>(pageResponse: T | null = null): void {
|
168
|
-
if (Tools.IsNotNull(pageResponse)) {
|
169
|
-
this._preventDestroy = true;
|
170
|
-
Source.SetPageResponse(pageResponse);
|
171
|
-
}
|
172
|
-
};
|
173
|
-
|
174
|
-
|
175
|
-
/** */
|
176
|
-
protected ReloadPage(): void {
|
177
|
-
Breadcrumbs.RemoveLast();
|
178
|
-
Tools.Sleep().then(_ => window.location.reload());
|
179
|
-
}
|
180
|
-
|
181
|
-
|
182
|
-
/** */
|
183
|
-
protected Log(value: any, log: string | null = null): void {
|
184
|
-
if (Tools.IsNotNull(log)) console.log({ log, value });
|
185
|
-
else console.log(value);
|
186
|
-
}
|
187
|
-
|
188
|
-
|
189
|
-
/** Returns true if the value is null or undefined, false otherwise */
|
190
|
-
protected IsNotNull = Tools.IsNotNull;
|
191
|
-
|
192
|
-
/** Returns true if the value is null or undefined, false otherwise */
|
193
|
-
protected IsNull = Tools.IsNull;
|
194
|
-
|
195
|
-
/** Returns true if the value is null or undefined or contains only whitespace, false otherwise */
|
196
|
-
protected IsOnlyWhiteSpace = Tools.IsOnlyWhiteSpace;
|
197
|
-
}
|
@@ -1,50 +0,0 @@
|
|
1
|
-
import { IScreenSize } from "../../interfaces";
|
2
|
-
import { Observable } from "rxjs";
|
3
|
-
|
4
|
-
export class Screen {
|
5
|
-
|
6
|
-
public static get WINDOW_WIDTH(): number {
|
7
|
-
return window.innerWidth;
|
8
|
-
}
|
9
|
-
|
10
|
-
|
11
|
-
public static get WINDOW_HEIGHT(): number {
|
12
|
-
return window.innerHeight;
|
13
|
-
}
|
14
|
-
|
15
|
-
|
16
|
-
public static get DEVICE_WIDTH(): number {
|
17
|
-
return window.screen.width;
|
18
|
-
}
|
19
|
-
|
20
|
-
|
21
|
-
public static get DEVICE_HEIGHT(): number {
|
22
|
-
return window.screen.height;
|
23
|
-
}
|
24
|
-
|
25
|
-
|
26
|
-
public static get BREAKPOINT(): 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl' {
|
27
|
-
if (window.innerWidth < 576) return 'xs';
|
28
|
-
else if (window.innerWidth >= 576 && window.innerWidth < 768) return 'sm';
|
29
|
-
else if (window.innerWidth >= 768 && window.innerWidth < 992) return 'md';
|
30
|
-
else if (window.innerWidth >= 992 && window.innerWidth < 1200) return 'lg';
|
31
|
-
else if (window.innerWidth >= 1200 && window.innerWidth < 1400) return 'xl';
|
32
|
-
else return 'xxl';
|
33
|
-
}
|
34
|
-
|
35
|
-
|
36
|
-
/** */
|
37
|
-
public static Resize = new Observable<IScreenSize>(subscriber => {
|
38
|
-
window.addEventListener("load", () => {
|
39
|
-
window.dispatchEvent(new Event('resize'));
|
40
|
-
});
|
41
|
-
|
42
|
-
window.onresize = () => {
|
43
|
-
subscriber.next({
|
44
|
-
width: window.innerWidth,
|
45
|
-
height: window.innerHeight,
|
46
|
-
breakpoin: this.BREAKPOINT
|
47
|
-
});
|
48
|
-
}
|
49
|
-
});
|
50
|
-
}
|
@@ -1,107 +0,0 @@
|
|
1
|
-
import { Router } from '@angular/router';
|
2
|
-
import { inject } from "@angular/core";
|
3
|
-
import { IAppSource } from '../../interfaces';
|
4
|
-
import { Breadcrumbs } from './Breadcrumbs.class';
|
5
|
-
import { Tools } from './Tools';
|
6
|
-
|
7
|
-
export class Source {
|
8
|
-
|
9
|
-
private static readonly storage = 'COER-System';
|
10
|
-
|
11
|
-
/** */
|
12
|
-
public static Set(page: string): void {
|
13
|
-
const ROUTER = inject(Router);
|
14
|
-
|
15
|
-
let path = ROUTER.url;
|
16
|
-
if (path.includes('?')) path = path.split('?')[0];
|
17
|
-
|
18
|
-
Breadcrumbs.Add(page, path);
|
19
|
-
|
20
|
-
const breadcrumbs = Breadcrumbs.Get();
|
21
|
-
|
22
|
-
if(breadcrumbs.length >= 2) {
|
23
|
-
breadcrumbs.pop();
|
24
|
-
const breadcrumb = breadcrumbs.pop()!;
|
25
|
-
this.Save({ page: breadcrumb.page, path: breadcrumb.path });
|
26
|
-
}
|
27
|
-
|
28
|
-
else this.Save(null);
|
29
|
-
}
|
30
|
-
|
31
|
-
|
32
|
-
/** */
|
33
|
-
private static Save(source: IAppSource | null): void {
|
34
|
-
let storage = sessionStorage.getItem(this.storage) as any;
|
35
|
-
if (storage) storage = JSON.parse(storage);
|
36
|
-
storage = Object.assign({}, storage, { source });
|
37
|
-
sessionStorage.setItem(this.storage, JSON.stringify(storage));
|
38
|
-
}
|
39
|
-
|
40
|
-
|
41
|
-
/** */
|
42
|
-
public static Get(): IAppSource | null {
|
43
|
-
let storage = sessionStorage.getItem(this.storage) as any;
|
44
|
-
|
45
|
-
if (storage) {
|
46
|
-
storage = JSON.parse(storage);
|
47
|
-
|
48
|
-
if (storage.hasOwnProperty('source')) {
|
49
|
-
return storage.source;
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
return null;
|
54
|
-
}
|
55
|
-
|
56
|
-
|
57
|
-
/** */
|
58
|
-
public static GetRoot(): IAppSource | null {
|
59
|
-
const breadcrumbs = Breadcrumbs.Get();
|
60
|
-
return (breadcrumbs.length > 0) ? breadcrumbs.shift()! : null;
|
61
|
-
}
|
62
|
-
|
63
|
-
|
64
|
-
/** */
|
65
|
-
public static SetPageResponse<T>(pageResponse: T): void {
|
66
|
-
let storage = sessionStorage.getItem(this.storage) as any;
|
67
|
-
storage = JSON.parse(storage);
|
68
|
-
storage = Object.assign({}, storage, { pageResponse });
|
69
|
-
sessionStorage.setItem(this.storage, JSON.stringify(storage));
|
70
|
-
}
|
71
|
-
|
72
|
-
|
73
|
-
/** */
|
74
|
-
public static GetPageResponse<T>(): T | null {
|
75
|
-
let storage = sessionStorage.getItem(this.storage) as any;
|
76
|
-
|
77
|
-
if (storage) {
|
78
|
-
storage = JSON.parse(storage);
|
79
|
-
|
80
|
-
if (storage.hasOwnProperty('pageResponse')) {
|
81
|
-
return Tools.BreakReference(storage.pageResponse);
|
82
|
-
}
|
83
|
-
}
|
84
|
-
|
85
|
-
return null;
|
86
|
-
}
|
87
|
-
|
88
|
-
|
89
|
-
/** */
|
90
|
-
public static ClearPageResponse(): void {
|
91
|
-
let storage = sessionStorage.getItem(this.storage) as any;
|
92
|
-
storage = JSON.parse(storage);
|
93
|
-
|
94
|
-
if (storage.hasOwnProperty('pageResponse')) {
|
95
|
-
delete storage.pageResponse;
|
96
|
-
}
|
97
|
-
|
98
|
-
storage = Object.assign({}, storage);
|
99
|
-
sessionStorage.setItem(this.storage, JSON.stringify(storage));
|
100
|
-
}
|
101
|
-
|
102
|
-
|
103
|
-
/** Clear Source */
|
104
|
-
public static Reset(): void {
|
105
|
-
sessionStorage.removeItem(this.storage);
|
106
|
-
}
|
107
|
-
}
|
package/tools/src/Tools.ts
DELETED
@@ -1,217 +0,0 @@
|
|
1
|
-
import { signal } from "@angular/core";
|
2
|
-
const reference_signal = signal<any>({});
|
3
|
-
|
4
|
-
export const Tools = {
|
5
|
-
/** Generate a Guid */
|
6
|
-
GetGuid: (seed: string = 'coer-system') => {
|
7
|
-
let time = new Date().getTime();
|
8
|
-
seed = seed.toString().trim()
|
9
|
-
return seed + `-xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g, (c) => {
|
10
|
-
const random = (time + Math.random() * 16) % 16 | 0
|
11
|
-
time = Math.floor(time / 16)
|
12
|
-
return (c == 'x' ? random : (random & 0x3 | 0x8)).toString(16)
|
13
|
-
})
|
14
|
-
},
|
15
|
-
|
16
|
-
|
17
|
-
/** Returns true if the value is null or undefined, false otherwise */
|
18
|
-
IsNull: <T>(value: T | null | undefined): boolean => {
|
19
|
-
if (value === undefined) return true;
|
20
|
-
if (value === null) return true;
|
21
|
-
return false;
|
22
|
-
},
|
23
|
-
|
24
|
-
|
25
|
-
/** Returns true if the value is not null or undefined, false otherwise */
|
26
|
-
IsNotNull: <T>(value: T | null | undefined): boolean => {
|
27
|
-
if (value === undefined) return false;
|
28
|
-
if (value === null) return false;
|
29
|
-
return true;
|
30
|
-
},
|
31
|
-
|
32
|
-
|
33
|
-
/** Returns true if the value is null or undefined or contains only whitespace, false otherwise */
|
34
|
-
IsOnlyWhiteSpace: <T>(value: T | null | undefined): boolean => {
|
35
|
-
if (value === undefined) return true;
|
36
|
-
if (value === null) return true;
|
37
|
-
if((value as string).toString().trim() === '') return true;
|
38
|
-
return false;
|
39
|
-
},
|
40
|
-
|
41
|
-
|
42
|
-
/** Break reference of a object or array */
|
43
|
-
BreakReference: <T>(object: T): T => {
|
44
|
-
if (object === undefined) return undefined as T;
|
45
|
-
if (object === null) return null as T;
|
46
|
-
const OBJECT = JSON.parse(JSON.stringify(object))
|
47
|
-
return (Array.isArray(OBJECT)) ? [...OBJECT] : { ...OBJECT }
|
48
|
-
},
|
49
|
-
|
50
|
-
|
51
|
-
/** Clean extra whitespaces */
|
52
|
-
CleanUpBlanks: (text: string | number): string => {
|
53
|
-
if(Tools.IsNull(text)) return '';
|
54
|
-
let worlds: string[] = String(text).split(' ');
|
55
|
-
worlds = worlds.filter(x => x.length > 0);
|
56
|
-
return worlds.join(' ');
|
57
|
-
},
|
58
|
-
|
59
|
-
|
60
|
-
/** Get properties of an object */
|
61
|
-
GetObjectProperties: <T>(obj: T | null | undefined): string[] => {
|
62
|
-
const properties: string[] = [];
|
63
|
-
if(Tools.IsNull(obj)) return properties;
|
64
|
-
for(const property in obj) properties.push(String(property));
|
65
|
-
return properties;
|
66
|
-
},
|
67
|
-
|
68
|
-
|
69
|
-
/**
|
70
|
-
* Set an index and merge more arrays of the same type
|
71
|
-
* @returns A new array
|
72
|
-
* */
|
73
|
-
SetIndex: <T>(array: T[], ...args: T[][]): T[] => {
|
74
|
-
let index = 0;
|
75
|
-
for (const arg of args) {
|
76
|
-
array = Tools.BreakReference(array).concat(Tools.BreakReference(arg));
|
77
|
-
}
|
78
|
-
|
79
|
-
return Tools.BreakReference(array).map(item => Object.assign({ index: index++ }, item));
|
80
|
-
},
|
81
|
-
|
82
|
-
|
83
|
-
/** Set First Char To Lower */
|
84
|
-
FirstCharToLower: (text: string | null | undefined): string => {
|
85
|
-
if (Tools.IsNull(text)) return '';
|
86
|
-
|
87
|
-
const textArray: string[] = [];
|
88
|
-
for(let i = 0; i < text!.length; i++) {
|
89
|
-
if(i === 0) textArray.push(text![i].toLowerCase());
|
90
|
-
else textArray.push(text![i]);
|
91
|
-
}
|
92
|
-
|
93
|
-
return textArray.join('');
|
94
|
-
},
|
95
|
-
|
96
|
-
|
97
|
-
/** Set First Char To Upper */
|
98
|
-
FirstCharToUpper: (text: string | null | undefined): string => {
|
99
|
-
if (Tools.IsNull(text)) return '';
|
100
|
-
|
101
|
-
const textArray: string[] = [];
|
102
|
-
for(let i = 0; i < text!.length; i++) {
|
103
|
-
if(i === 0) textArray.push(text![i].toUpperCase());
|
104
|
-
else textArray.push(text![i]);
|
105
|
-
}
|
106
|
-
|
107
|
-
return textArray.join('');
|
108
|
-
},
|
109
|
-
|
110
|
-
|
111
|
-
/** Sort an array in ascending order by property */
|
112
|
-
SortBy: <T>(array: T[], property: string, propertyType: 'string' | 'number' = 'string'): T[] => {
|
113
|
-
switch (propertyType) {
|
114
|
-
case 'string': {
|
115
|
-
return array.sort((x: any, y: any) => {
|
116
|
-
if (String(x[property]).toUpperCase().trim() < String(y[property]).toUpperCase().trim()) return -1;
|
117
|
-
else if (String(x[property]).toUpperCase().trim() > String(y[property]).toUpperCase().trim()) return 1;
|
118
|
-
else return 0;
|
119
|
-
});
|
120
|
-
}
|
121
|
-
|
122
|
-
case 'number': {
|
123
|
-
return array.sort((x: any, y: any) => Number(x[property] - Number(y[property])));
|
124
|
-
}
|
125
|
-
}
|
126
|
-
},
|
127
|
-
|
128
|
-
|
129
|
-
/** Sort an array in descending order by property */
|
130
|
-
SortByDesc: <T>(array: T[], property: string, propertyType: 'string' | 'number' = 'string'): T[] => {
|
131
|
-
switch (propertyType) {
|
132
|
-
case 'string': {
|
133
|
-
return array.sort((x: any, y: any) => {
|
134
|
-
if (String(x[property]).toUpperCase().trim() < String(y[property]).toUpperCase().trim()) return 1;
|
135
|
-
else if (String(x[property]).toUpperCase().trim() > String(y[property]).toUpperCase().trim()) return -1;
|
136
|
-
else return 0;
|
137
|
-
});
|
138
|
-
}
|
139
|
-
|
140
|
-
case 'number': {
|
141
|
-
return array.sort((x: any, y: any) => Number(Number(y[property])) - x[property]);
|
142
|
-
}
|
143
|
-
}
|
144
|
-
},
|
145
|
-
|
146
|
-
|
147
|
-
/** Return a string with forman numeric */
|
148
|
-
GetNumericFormat: (value: string | number | null | undefined, decimals: number = 0): string => {
|
149
|
-
if (value == undefined
|
150
|
-
|| value == null
|
151
|
-
|| value.toString().trim() == ''
|
152
|
-
|| isNaN(Number(value))) {
|
153
|
-
return '0';
|
154
|
-
}
|
155
|
-
|
156
|
-
let valueInteger = '';
|
157
|
-
let valueDecimal = '';
|
158
|
-
value = value.toString().replaceAll(' ', '');
|
159
|
-
|
160
|
-
if (value.includes('.') || (decimals > 0)) {
|
161
|
-
valueInteger = value.includes('.') ? value.split('.')[0] : value;
|
162
|
-
|
163
|
-
if (decimals > 0) {
|
164
|
-
const PADDING = decimals - valueDecimal.length;
|
165
|
-
valueDecimal = value.includes('.') ? value.split('.')[1] : '';
|
166
|
-
for(let i = 0; i < PADDING; i++) valueDecimal += '0';
|
167
|
-
valueDecimal = valueDecimal.substring(0, decimals);
|
168
|
-
valueDecimal = `.${valueDecimal}`;
|
169
|
-
}
|
170
|
-
}
|
171
|
-
|
172
|
-
else {
|
173
|
-
valueInteger = value;
|
174
|
-
}
|
175
|
-
|
176
|
-
let counter = 0;
|
177
|
-
const VALUE_INTEGER_ARRAY: string[] = [];
|
178
|
-
for(const char of valueInteger.split('').reverse()) {
|
179
|
-
if (counter == 3) {
|
180
|
-
VALUE_INTEGER_ARRAY.push(',');
|
181
|
-
counter = 0;
|
182
|
-
}
|
183
|
-
|
184
|
-
VALUE_INTEGER_ARRAY.push(char);
|
185
|
-
++counter;
|
186
|
-
}
|
187
|
-
|
188
|
-
valueInteger = VALUE_INTEGER_ARRAY.reverse().join('');
|
189
|
-
return `${valueInteger}${valueDecimal}`;
|
190
|
-
},
|
191
|
-
|
192
|
-
|
193
|
-
/** Wait the time indicated */
|
194
|
-
Sleep: (milliseconds: number = 0, reference: string | null = null) => {
|
195
|
-
if (Tools.IsNull(reference)) {
|
196
|
-
return new Promise(Resolve => setTimeout(Resolve, milliseconds));
|
197
|
-
}
|
198
|
-
|
199
|
-
else return new Promise<void>(Resolve => {
|
200
|
-
reference = reference!.replaceAll(' ', '_').toLowerCase();
|
201
|
-
|
202
|
-
if (reference_signal().hasOwnProperty(reference)) {
|
203
|
-
clearInterval(reference_signal()[reference!]);
|
204
|
-
}
|
205
|
-
|
206
|
-
reference_signal.set(Object.assign(reference_signal(), {
|
207
|
-
[reference!]: setTimeout(() => {
|
208
|
-
Resolve();
|
209
|
-
clearInterval(reference_signal()[reference!]);
|
210
|
-
const _reference = { ...reference_signal() };
|
211
|
-
delete _reference[reference!];
|
212
|
-
reference_signal.set({ ..._reference });
|
213
|
-
}, milliseconds)
|
214
|
-
}));
|
215
|
-
});
|
216
|
-
}
|
217
|
-
};
|