pangea-lib 1.8.3 → 1.8.4
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
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
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
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
type DisplayDatetimeConfig = {
|
|
2
|
+
format?: 'numbers' | 'short' | 'long';
|
|
3
|
+
withTime?: boolean;
|
|
4
|
+
};
|
|
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
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import moment from 'moment';
|
|
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]);
|
|
23
|
+
}
|
|
24
|
+
} 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];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
}
|
|
12
|
+
}
|
|
13
|
+
// remove port number
|
|
14
|
+
finalUrl = finalUrl.replace(/:(\d*)$/, '');
|
|
15
|
+
return window.location.href.includes(finalUrl);
|
|
16
|
+
},
|
|
17
|
+
};
|