pangea-lib 1.8.4 → 1.8.6

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pangea-lib",
3
- "version": "1.8.4",
3
+ "version": "1.8.6",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "files": [
@@ -1,17 +1,15 @@
1
- export default {
2
- animateCSS(element: string, animation: string, prefix = 'animate__') {
3
- return new Promise((resolve) => {
4
- const animationName = `${prefix}${animation}`;
5
- const node = document.querySelector(element);
6
- if (node) {
7
- node.classList.add(`${prefix}animated`, animationName);
8
- const handleAnimationEnd = (event: { stopPropagation: () => void }) => {
9
- event.stopPropagation();
10
- node?.classList.remove(`${prefix}animated`, animationName);
11
- resolve('Animation ended');
12
- };
13
- node.addEventListener('animationend', handleAnimationEnd, { once: true });
14
- }
15
- });
16
- },
17
- };
1
+ export function animateCSS(element: string, animation: string, prefix = 'animate__') {
2
+ return new Promise((resolve) => {
3
+ const animationName = `${prefix}${animation}`;
4
+ const node = document.querySelector(element);
5
+ if (node) {
6
+ node.classList.add(`${prefix}animated`, animationName);
7
+ const handleAnimationEnd = (event: { stopPropagation: () => void }) => {
8
+ event.stopPropagation();
9
+ node?.classList.remove(`${prefix}animated`, animationName);
10
+ resolve('Animation ended');
11
+ };
12
+ node.addEventListener('animationend', handleAnimationEnd, { once: true });
13
+ }
14
+ });
15
+ }
@@ -1,18 +1,18 @@
1
1
  import axios from 'axios';
2
2
 
3
- export default {
4
- displayValue(value: number, maximumFractionDigits: number) {
5
- const valueToReturn = value.toLocaleString(undefined, { maximumFractionDigits });
6
- if (valueToReturn === '-0') return '0';
7
- return valueToReturn;
8
- },
9
- getAmountToDisplay(amount: number, significantDigits: number, coinName: string, withCoinName = true) {
10
- let amountToDisplay = this.displayValue(amount, significantDigits);
11
- if (withCoinName) amountToDisplay = amountToDisplay += ` ${coinName}`;
12
- return amountToDisplay;
13
- },
14
- async getDollarValue(): Promise<number> {
15
- const res = await axios.get('https://dolarapi.com/v1/dolares/blue');
16
- return res.data.venta;
17
- },
18
- };
3
+ export function displayValue(value: number, maximumFractionDigits: number) {
4
+ const valueToReturn = value.toLocaleString(undefined, { maximumFractionDigits });
5
+ if (valueToReturn === '-0') return '0';
6
+ return valueToReturn;
7
+ }
8
+
9
+ export function getAmountToDisplay(amount: number, significantDigits: number, coinName: string, withCoinName = true) {
10
+ let amountToDisplay = displayValue(amount, significantDigits);
11
+ if (withCoinName) amountToDisplay = amountToDisplay += ` ${coinName}`;
12
+ return amountToDisplay;
13
+ }
14
+
15
+ export async function getDollarValue(): Promise<number> {
16
+ const res = await axios.get('https://dolarapi.com/v1/dolares/blue');
17
+ return res.data.venta;
18
+ }
@@ -3,31 +3,29 @@ type DisplayDatetimeConfig = {
3
3
  withTime?: boolean;
4
4
  };
5
5
 
6
- export default {
7
- displayDatetime(datetime: Date, config?: DisplayDatetimeConfig) {
8
- // config
9
- const defaultConfig: DisplayDatetimeConfig = {
10
- format: 'short',
11
- withTime: true,
12
- };
13
- const finalConfig = {
14
- ...defaultConfig,
15
- ...config,
16
- };
17
- // null
18
- if (!datetime) return '-';
19
- // options
20
- const options: Intl.DateTimeFormatOptions = {
21
- weekday: finalConfig.format === 'numbers' ? undefined : finalConfig.format,
22
- year: 'numeric',
23
- month: finalConfig.format === 'numbers' ? '2-digit' : finalConfig.format,
24
- day: '2-digit',
25
- hour: finalConfig.withTime ? '2-digit' : undefined,
26
- minute: finalConfig.withTime ? '2-digit' : undefined,
27
- hour12: false,
28
- };
29
- // return
30
- const stringDatetime = datetime.toLocaleString('es-ES', options);
31
- return stringDatetime.charAt(0).toUpperCase() + stringDatetime.slice(1);
32
- },
33
- };
6
+ export function displayDatetime(datetime: Date, config?: DisplayDatetimeConfig) {
7
+ // config
8
+ const defaultConfig: DisplayDatetimeConfig = {
9
+ format: 'short',
10
+ withTime: true,
11
+ };
12
+ const finalConfig = {
13
+ ...defaultConfig,
14
+ ...config,
15
+ };
16
+ // null
17
+ if (!datetime) return '-';
18
+ // options
19
+ const options: Intl.DateTimeFormatOptions = {
20
+ weekday: finalConfig.format === 'numbers' ? undefined : finalConfig.format,
21
+ year: 'numeric',
22
+ month: finalConfig.format === 'numbers' ? '2-digit' : finalConfig.format,
23
+ day: '2-digit',
24
+ hour: finalConfig.withTime ? '2-digit' : undefined,
25
+ minute: finalConfig.withTime ? '2-digit' : undefined,
26
+ hour12: false,
27
+ };
28
+ // return
29
+ const stringDatetime = datetime.toLocaleString('es-ES', options);
30
+ return stringDatetime.charAt(0).toUpperCase() + stringDatetime.slice(1);
31
+ }
@@ -1,41 +1,40 @@
1
1
  import moment from 'moment';
2
2
 
3
- export default {
4
- copyModelFields(objTo: any, objFrom: any, relations?: any) {
5
- if (objFrom)
6
- Object.keys(objFrom).forEach((key) => {
7
- if (!objTo.hasOwnProperty(key)) return;
8
- if (!objFrom[key]) return (objTo[key] = objFrom[key]);
9
- if (objFrom[key] instanceof File) return (objTo[key] = objFrom[key]);
10
- if (
11
- /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test(objFrom[key]) &&
12
- moment(objFrom[key], moment.ISO_8601, true).isValid()
13
- )
14
- return (objTo[key] = new Date(objFrom[key]));
15
- if (typeof objFrom[key] === 'object' && relations?.[key]) {
16
- if (Array.isArray(objFrom[key])) {
17
- objTo[key] = [];
18
- for (let index = 0; index < objFrom[key].length; index++) {
19
- objTo[key].push(new relations[key](objFrom[key][index]));
20
- }
21
- } else {
22
- objTo[key] = new relations[key](objFrom[key]);
3
+ export function copyModelFields(objTo: any, objFrom: any, relations?: any) {
4
+ if (objFrom)
5
+ Object.keys(objFrom).forEach((key) => {
6
+ if (!objTo.hasOwnProperty(key)) return;
7
+ if (!objFrom[key]) return (objTo[key] = objFrom[key]);
8
+ if (objFrom[key] instanceof File) return (objTo[key] = objFrom[key]);
9
+ if (
10
+ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test(objFrom[key]) &&
11
+ moment(objFrom[key], moment.ISO_8601, true).isValid()
12
+ )
13
+ return (objTo[key] = new Date(objFrom[key]));
14
+ if (typeof objFrom[key] === 'object' && relations?.[key]) {
15
+ if (Array.isArray(objFrom[key])) {
16
+ objTo[key] = [];
17
+ for (let index = 0; index < objFrom[key].length; index++) {
18
+ objTo[key].push(new relations[key](objFrom[key][index]));
23
19
  }
24
20
  } else {
25
- objTo[key] = objFrom[key];
26
- }
27
- });
28
- },
29
- copyAvailableFields(destinationObj?: any, originObj?: any) {
30
- if (!destinationObj || !originObj) return;
31
- for (const key in originObj) {
32
- if (originObj.hasOwnProperty(key) && destinationObj.hasOwnProperty(key)) {
33
- if (typeof originObj[key] === 'object' && originObj[key] !== null) {
34
- this.copyAvailableFields(destinationObj[key], originObj[key]);
35
- } else {
36
- destinationObj[key] = originObj[key];
21
+ objTo[key] = new relations[key](objFrom[key]);
37
22
  }
23
+ } else {
24
+ objTo[key] = objFrom[key];
25
+ }
26
+ });
27
+ }
28
+
29
+ export function copyAvailableFields(destinationObj?: any, originObj?: any) {
30
+ if (!destinationObj || !originObj) return;
31
+ for (const key in originObj) {
32
+ if (originObj.hasOwnProperty(key) && destinationObj.hasOwnProperty(key)) {
33
+ if (typeof originObj[key] === 'object' && originObj[key] !== null) {
34
+ copyAvailableFields(destinationObj[key], originObj[key]);
35
+ } else {
36
+ destinationObj[key] = originObj[key];
38
37
  }
39
38
  }
40
- },
41
- };
39
+ }
40
+ }
@@ -1,17 +1,15 @@
1
- export default {
2
- isCurrentUrl(url: string) {
3
- if (!url) return false;
4
- let finalUrl = url;
5
- // remove protocol
6
- const protocols = ['http://', 'https://'];
7
- for (const protocol of protocols) {
8
- if (url.startsWith(protocol)) {
9
- finalUrl = url.replace(protocol, '');
10
- break;
11
- }
1
+ export function isCurrentUrl(url: string) {
2
+ if (!url) return false;
3
+ let finalUrl = url;
4
+ // remove protocol
5
+ const protocols = ['http://', 'https://'];
6
+ for (const protocol of protocols) {
7
+ if (url.startsWith(protocol)) {
8
+ finalUrl = url.replace(protocol, '');
9
+ break;
12
10
  }
13
- // remove port number
14
- finalUrl = finalUrl.replace(/:(\d*)$/, '');
15
- return window.location.href.includes(finalUrl);
16
- },
17
- };
11
+ }
12
+ // remove port number
13
+ finalUrl = finalUrl.replace(/:(\d*)$/, '');
14
+ return window.location.href.includes(finalUrl);
15
+ }