pangea-lib 1.8.3 → 1.8.5

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,10 +1,11 @@
1
1
  {
2
2
  "name": "pangea-lib",
3
- "version": "1.8.3",
3
+ "version": "1.8.5",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
8
+ "src/helpers",
8
9
  "src/styles"
9
10
  ],
10
11
  "main": "./dist/pangea.umd.cjs",
@@ -0,0 +1,15 @@
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
+ }
@@ -0,0 +1,18 @@
1
+ import axios from 'axios';
2
+
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 = this.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
+ }
@@ -0,0 +1,31 @@
1
+ type DisplayDatetimeConfig = {
2
+ format?: 'numbers' | 'short' | 'long';
3
+ withTime?: boolean;
4
+ };
5
+
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
+ }
@@ -0,0 +1,40 @@
1
+ import moment from 'moment';
2
+
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]));
19
+ }
20
+ } else {
21
+ objTo[key] = new relations[key](objFrom[key]);
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
+ this.copyAvailableFields(destinationObj[key], originObj[key]);
35
+ } else {
36
+ destinationObj[key] = originObj[key];
37
+ }
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,15 @@
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;
10
+ }
11
+ }
12
+ // remove port number
13
+ finalUrl = finalUrl.replace(/:(\d*)$/, '');
14
+ return window.location.href.includes(finalUrl);
15
+ }