coer-elements 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ import { signal } from "@angular/core";
2
+ import { Screen } from './../Tools/Screen.class';
3
+
4
+ export const breakpoint_signal = signal<'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl'>(Screen?.BREAKPOINT || 'xs');
5
+ export const isReady_signal = signal<boolean>(false);
6
+ export const isLoading_signal = signal<boolean>(false);
7
+ export const isModalOpen_signal = signal<boolean>(false);
@@ -2,7 +2,7 @@ import { Tools } from ".";
2
2
  import * as XLSX from 'xlsx';
3
3
 
4
4
  export class Files {
5
- private static readonly EXCEL_EXTENSIONS: string[] = ['xls', 'xlsx', 'csv'];
5
+ public static readonly EXCEL_EXTENSIONS: string[] = ['xls', 'xlsx', 'csv'];
6
6
 
7
7
  /** Get Extension File */
8
8
  public static GetExtension(file: File): string | null {
@@ -99,4 +99,21 @@ export class Files {
99
99
  XLSX.utils.book_append_sheet(WORK_BOOK, WORK_SHEET, 'Sheet1');
100
100
  XLSX.writeFile(WORK_BOOK, fileName);
101
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
+ }
102
119
  }
@@ -0,0 +1,55 @@
1
+ import { Observable } from "rxjs";
2
+
3
+ export interface IScreenSize {
4
+ width: number;
5
+ height: number;
6
+ breakpoin: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
7
+ }
8
+
9
+ export class Screen {
10
+
11
+ public static get WINDOW_WIDTH(): number {
12
+ return window.innerWidth;
13
+ }
14
+
15
+
16
+ public static get WINDOW_HEIGHT(): number {
17
+ return window.innerHeight;
18
+ }
19
+
20
+
21
+ public static get DEVICE_WIDTH(): number {
22
+ return window.screen.width;
23
+ }
24
+
25
+
26
+ public static get DEVICE_HEIGHT(): number {
27
+ return window.screen.height;
28
+ }
29
+
30
+
31
+ public static get BREAKPOINT(): 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl' {
32
+ if (window.innerWidth < 576) return 'xs';
33
+ else if (window.innerWidth >= 576 && window.innerWidth < 768) return 'sm';
34
+ else if (window.innerWidth >= 768 && window.innerWidth < 992) return 'md';
35
+ else if (window.innerWidth >= 992 && window.innerWidth < 1200) return 'lg';
36
+ else if (window.innerWidth >= 1200 && window.innerWidth < 1400) return 'xl';
37
+ else return 'xxl';
38
+ }
39
+
40
+
41
+ /** */
42
+ public static Resize = new Observable<IScreenSize>(subscriber => {
43
+ window.addEventListener("load", () => {
44
+ window.dispatchEvent(new Event('resize'));
45
+ });
46
+
47
+ window.onresize = () => {
48
+ subscriber.next({
49
+ width: window.innerWidth,
50
+ height: window.innerHeight,
51
+ breakpoin: this.BREAKPOINT
52
+ });
53
+ }
54
+ });
55
+ }
package/Tools/index.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { Guid } from "guid-typescript";
2
+ import { signal } from "@angular/core";
3
+ const reference_signal = signal<any>({});
2
4
 
3
5
  export const Tools = {
4
6
  /** Generate a Guid */
@@ -6,6 +8,7 @@ export const Tools = {
6
8
  return `${seed}-${Guid.create().toString()}`;
7
9
  },
8
10
 
11
+
9
12
  /** Returns true if the value is null or undefined, false otherwise */
10
13
  IsNull: (value: any): boolean => {
11
14
  if (value === undefined) return true;
@@ -22,6 +25,15 @@ export const Tools = {
22
25
  },
23
26
 
24
27
 
28
+ /** Returns true if the value is null or undefined or contains only whitespace, false otherwise */
29
+ IsOnlyWhiteSpace: (value: any): boolean => {
30
+ if (value === undefined) return true;
31
+ if (value === null) return true;
32
+ if((value as string).toString().trim() === '') return true;
33
+ return false;
34
+ },
35
+
36
+
25
37
  /** Break reference of a object or array */
26
38
  BreakReference: <T>(object: T): T => {
27
39
  if (object === undefined) return undefined as T;
@@ -91,14 +103,11 @@ export const Tools = {
91
103
  },
92
104
 
93
105
 
94
- /**
95
- * Sort an array in ascending order by property
96
- * @returns A new array
97
- * */
106
+ /** Sort an array in ascending order by property */
98
107
  SortBy: <T>(array: T[], property: string, propertyType: 'string' | 'number' = 'string'): T[] => {
99
108
  switch (propertyType) {
100
109
  case 'string': {
101
- return [...array].sort((x: any, y: any) => {
110
+ return array.sort((x: any, y: any) => {
102
111
  if (String(x[property]).toUpperCase().trim() < String(y[property]).toUpperCase().trim()) return -1;
103
112
  else if (String(x[property]).toUpperCase().trim() > String(y[property]).toUpperCase().trim()) return 1;
104
113
  else return 0;
@@ -112,10 +121,7 @@ export const Tools = {
112
121
  },
113
122
 
114
123
 
115
- /**
116
- * Sort an array in descending order by property
117
- * @returns A new array
118
- * */
124
+ /** Sort an array in descending order by property */
119
125
  SortByDesc: <T>(array: T[], property: string, propertyType: 'string' | 'number' = 'string'): T[] => {
120
126
  switch (propertyType) {
121
127
  case 'string': {
@@ -130,5 +136,77 @@ export const Tools = {
130
136
  return array.sort((x: any, y: any) => Number(Number(y[property])) - x[property]);
131
137
  }
132
138
  }
139
+ },
140
+
141
+
142
+ /** Return a string with forman numeric */
143
+ GetNumericFormat: (value: string | number | null | undefined, decimals: number = 0): string => {
144
+ if (value == undefined
145
+ || value == null
146
+ || value.toString().trim() == ''
147
+ || isNaN(Number(value))) {
148
+ return '0';
149
+ }
150
+
151
+ let valueInteger = '';
152
+ let valueDecimal = '';
153
+ value = value.toString().replaceAll(' ', '');
154
+
155
+ if (value.includes('.') || (decimals > 0)) {
156
+ valueInteger = value.includes('.') ? value.split('.')[0] : value;
157
+
158
+ if (decimals > 0) {
159
+ const PADDING = decimals - valueDecimal.length;
160
+ valueDecimal = value.includes('.') ? value.split('.')[1] : '';
161
+ for(let i = 0; i < PADDING; i++) valueDecimal += '0';
162
+ valueDecimal = valueDecimal.substring(0, decimals);
163
+ valueDecimal = `.${valueDecimal}`;
164
+ }
165
+ }
166
+
167
+ else {
168
+ valueInteger = value;
169
+ }
170
+
171
+ let counter = 0;
172
+ const VALUE_INTEGER_ARRAY: string[] = [];
173
+ for(const char of valueInteger.split('').reverse()) {
174
+ if (counter == 3) {
175
+ VALUE_INTEGER_ARRAY.push(',');
176
+ counter = 0;
177
+ }
178
+
179
+ VALUE_INTEGER_ARRAY.push(char);
180
+ ++counter;
181
+ }
182
+
183
+ valueInteger = VALUE_INTEGER_ARRAY.reverse().join('');
184
+ return `${valueInteger}${valueDecimal}`;
185
+ },
186
+
187
+
188
+ /** Wait the time indicated */
189
+ Sleep: (milliseconds: number = 0, reference: string | null = null) => {
190
+ if (Tools.IsNull(reference)) {
191
+ return new Promise(Resolve => setTimeout(Resolve, milliseconds));
192
+ }
193
+
194
+ else return new Promise<void>(Resolve => {
195
+ reference = reference!.replaceAll(' ', '_').toLowerCase();
196
+
197
+ if (reference_signal().hasOwnProperty(reference)) {
198
+ clearInterval(reference_signal()[reference!]);
199
+ }
200
+
201
+ reference_signal.set(Object.assign(reference_signal(), {
202
+ [reference!]: setTimeout(() => {
203
+ Resolve();
204
+ clearInterval(reference_signal()[reference!]);
205
+ const _reference = { ...reference_signal() };
206
+ delete _reference[reference!];
207
+ reference_signal.set({ ..._reference });
208
+ }, milliseconds)
209
+ }));
210
+ });
133
211
  }
134
212
  };
package/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './Tools'
2
+ export * from './Tools/DateTime.class';
2
3
  export * from './Tools/Files.class';
3
- export * from './Tools/DateTime.class';
4
+ export * from './Tools/Screen.class';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coer-elements",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "author": "Christian Omar Escamilla Rodríguez",
5
5
  "keywords": [
6
6
  "coer",
@@ -19,11 +19,13 @@
19
19
  "build-browser": "tsc index.ts --outDir dist_browser --module ES6",
20
20
  "build-node": "tsc index.ts --outDir dist_node",
21
21
  "build": "npm run build-browser & npm run build-node",
22
- "publish": "npm publish --access public"
22
+ "push": "npm publish --access public"
23
23
  },
24
24
  "dependencies": {
25
+ "@angular/core": "^18.2.3",
25
26
  "guid-typescript": "^1.0.9",
26
27
  "moment": "^2.30.1",
28
+ "rxjs": "^7.8.1",
27
29
  "xlsx": "^0.18.5"
28
30
  },
29
31
  "devDependencies": {