pangea-helpers 1.1.0 → 1.1.1

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.
@@ -0,0 +1 @@
1
+ export declare function animateCSS(element: string, animation: string, prefix?: string): Promise<unknown>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.animateCSS = void 0;
4
+ function animateCSS(element, animation, prefix = 'animate__') {
5
+ return new Promise((resolve) => {
6
+ const animationName = `${prefix}${animation}`;
7
+ const node = document.querySelector(element);
8
+ if (node) {
9
+ node.classList.add(`${prefix}animated`, animationName);
10
+ const handleAnimationEnd = (event) => {
11
+ event.stopPropagation();
12
+ node === null || node === void 0 ? void 0 : node.classList.remove(`${prefix}animated`, animationName);
13
+ resolve('Animation ended');
14
+ };
15
+ node.addEventListener('animationend', handleAnimationEnd, { once: true });
16
+ }
17
+ });
18
+ }
19
+ exports.animateCSS = animateCSS;
@@ -0,0 +1,2 @@
1
+ export declare function getAmountInString(amount: number, significantDigits: number, coinName: string, withCoinName?: boolean): string;
2
+ export declare function getDollarValue(): Promise<number>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getDollarValue = exports.getAmountInString = void 0;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ const number_1 = require("./number");
18
+ function getAmountInString(amount, significantDigits, coinName, withCoinName = true) {
19
+ let amountToDisplay = (0, number_1.getValueInString)(amount, significantDigits);
20
+ if (withCoinName)
21
+ amountToDisplay = amountToDisplay += ` ${coinName}`;
22
+ return amountToDisplay;
23
+ }
24
+ exports.getAmountInString = getAmountInString;
25
+ function getDollarValue() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const res = yield axios_1.default.get('https://dolarapi.com/v1/dolares/blue');
28
+ return res.data.venta;
29
+ });
30
+ }
31
+ exports.getDollarValue = getDollarValue;
@@ -0,0 +1,6 @@
1
+ type GetDatetimeInStringConfig = {
2
+ format?: 'numbers' | 'short' | 'long';
3
+ withTime?: boolean;
4
+ };
5
+ export declare function getDatetimeInString(datetime: Date, config?: GetDatetimeInStringConfig): string;
6
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDatetimeInString = void 0;
4
+ function getDatetimeInString(datetime, config) {
5
+ // config
6
+ const defaultConfig = {
7
+ format: 'short',
8
+ withTime: true,
9
+ };
10
+ const finalConfig = Object.assign(Object.assign({}, defaultConfig), config);
11
+ // null
12
+ if (!datetime)
13
+ return '-';
14
+ // options
15
+ const options = {
16
+ weekday: finalConfig.format === 'numbers' ? undefined : finalConfig.format,
17
+ year: 'numeric',
18
+ month: finalConfig.format === 'numbers' ? '2-digit' : finalConfig.format,
19
+ day: '2-digit',
20
+ hour: finalConfig.withTime ? '2-digit' : undefined,
21
+ minute: finalConfig.withTime ? '2-digit' : undefined,
22
+ hour12: false,
23
+ };
24
+ // return
25
+ const stringDatetime = datetime.toLocaleString('es-ES', options);
26
+ return stringDatetime.charAt(0).toUpperCase() + stringDatetime.slice(1);
27
+ }
28
+ exports.getDatetimeInString = getDatetimeInString;
@@ -0,0 +1 @@
1
+ export declare function getValueInString(value: number, maximumFractionDigits: number): string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getValueInString = void 0;
4
+ function getValueInString(value, maximumFractionDigits) {
5
+ const valueToReturn = value.toLocaleString(undefined, {
6
+ maximumFractionDigits,
7
+ });
8
+ if (valueToReturn === "-0")
9
+ return "0";
10
+ return valueToReturn;
11
+ }
12
+ exports.getValueInString = getValueInString;
@@ -0,0 +1,2 @@
1
+ export declare function copyModelFields(objTo: any, objFrom: any, relations?: any): void;
2
+ export declare function copyAvailableFields(destinationObj?: any, originObj?: any): void;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.copyAvailableFields = exports.copyModelFields = void 0;
7
+ const moment_1 = __importDefault(require("moment"));
8
+ function copyModelFields(objTo, objFrom, relations) {
9
+ if (objFrom)
10
+ Object.keys(objFrom).forEach((key) => {
11
+ if (!objTo.hasOwnProperty(key))
12
+ return;
13
+ if (!objFrom[key])
14
+ return (objTo[key] = objFrom[key]);
15
+ if (objFrom[key] instanceof File)
16
+ return (objTo[key] = objFrom[key]);
17
+ if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test(objFrom[key]) &&
18
+ (0, moment_1.default)(objFrom[key], moment_1.default.ISO_8601, true).isValid())
19
+ return (objTo[key] = new Date(objFrom[key]));
20
+ if (typeof objFrom[key] === 'object' && (relations === null || relations === void 0 ? void 0 : relations[key])) {
21
+ if (Array.isArray(objFrom[key])) {
22
+ objTo[key] = [];
23
+ for (let index = 0; index < objFrom[key].length; index++) {
24
+ objTo[key].push(new relations[key](objFrom[key][index]));
25
+ }
26
+ }
27
+ else {
28
+ objTo[key] = new relations[key](objFrom[key]);
29
+ }
30
+ }
31
+ else {
32
+ objTo[key] = objFrom[key];
33
+ }
34
+ });
35
+ }
36
+ exports.copyModelFields = copyModelFields;
37
+ function copyAvailableFields(destinationObj, originObj) {
38
+ if (!destinationObj || !originObj)
39
+ return;
40
+ for (const key in originObj) {
41
+ if (originObj.hasOwnProperty(key) && destinationObj.hasOwnProperty(key)) {
42
+ if (typeof originObj[key] === 'object' && originObj[key] !== null) {
43
+ copyAvailableFields(destinationObj[key], originObj[key]);
44
+ }
45
+ else {
46
+ destinationObj[key] = originObj[key];
47
+ }
48
+ }
49
+ }
50
+ }
51
+ exports.copyAvailableFields = copyAvailableFields;
@@ -0,0 +1,7 @@
1
+ export declare class Token {
2
+ secretPrivateKey: string;
3
+ daysToExpire: number;
4
+ constructor(secretPrivateKey: string, daysToExpire?: number);
5
+ createAccessToken(key: string, value: string): any;
6
+ verifyAccessToken(token: string): any;
7
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Token = void 0;
7
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ class Token {
9
+ constructor(secretPrivateKey, daysToExpire) {
10
+ this.secretPrivateKey = 'secretPrivateKey';
11
+ this.daysToExpire = 30;
12
+ this.secretPrivateKey = secretPrivateKey;
13
+ this.daysToExpire = daysToExpire;
14
+ }
15
+ createAccessToken(key, value) {
16
+ return jsonwebtoken_1.default.sign({ [key]: value }, this.secretPrivateKey, {
17
+ expiresIn: 60 * 60 * 24 * this.daysToExpire,
18
+ });
19
+ }
20
+ verifyAccessToken(token) {
21
+ return jsonwebtoken_1.default.verify(token, this.secretPrivateKey);
22
+ }
23
+ }
24
+ exports.Token = Token;
@@ -0,0 +1 @@
1
+ export declare function isCurrentUrl(url: string): boolean;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCurrentUrl = void 0;
4
+ function isCurrentUrl(url) {
5
+ if (!url)
6
+ return false;
7
+ let finalUrl = url;
8
+ // remove protocol
9
+ const protocols = ['http://', 'https://'];
10
+ for (const protocol of protocols) {
11
+ if (url.startsWith(protocol)) {
12
+ finalUrl = url.replace(protocol, '');
13
+ break;
14
+ }
15
+ }
16
+ // remove port number
17
+ finalUrl = finalUrl.replace(/:(\d*)$/, '');
18
+ return window.location.href.includes(finalUrl);
19
+ }
20
+ exports.isCurrentUrl = isCurrentUrl;
package/dist/main.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import * as animationHelpers from './helpers/animation';
2
+ import * as coinHelpers from './helpers/coin';
3
+ import * as datetimeHelpers from './helpers/datetime';
4
+ import * as numberHelpers from './helpers/number';
5
+ import * as objectHelpers from './helpers/object';
6
+ import * as tokenHelpers from './helpers/token';
7
+ import * as urlHelpers from './helpers/url';
8
+ export { animationHelpers, coinHelpers, datetimeHelpers, numberHelpers, objectHelpers, tokenHelpers, urlHelpers };