coer-elements 1.0.2 → 1.0.4

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,50 @@
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
+ }
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';
@@ -2,4 +2,10 @@ export interface IPatch {
2
2
  op: 'remove' | 'add' | 'replace';
3
3
  path: string;
4
4
  value: any;
5
+ }
6
+
7
+ export interface IScreenSize {
8
+ width: number;
9
+ height: number;
10
+ breakpoin: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
5
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coer-elements",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "author": "Christian Omar Escamilla Rodríguez",
5
5
  "keywords": [
6
6
  "coer",
@@ -19,14 +19,26 @@
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/animations": "^17.3.0",
26
+ "@angular/cdk": "^17.3.3",
27
+ "@angular/common": "^17.3.0",
28
+ "@angular/compiler": "^17.3.0",
29
+ "@angular/core": "^17.3.0",
30
+ "@angular/forms": "^17.3.0",
31
+ "@angular/material": "^17.3.3",
32
+ "@angular/platform-browser": "^17.3.0",
33
+ "@angular/platform-browser-dynamic": "^17.3.0",
34
+ "@angular/router": "^17.3.0",
25
35
  "guid-typescript": "^1.0.9",
26
36
  "moment": "^2.30.1",
37
+ "rxjs": "^7.8.1",
27
38
  "xlsx": "^0.18.5"
28
39
  },
29
40
  "devDependencies": {
41
+ "@types/xlsx": "^0.0.36",
30
42
  "typescript": "^5.5.4"
31
43
  }
32
44
  }