mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-09 21:14:22 +00:00
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { MetaDataProps } from "@/types";
|
|
|
|
export const wait = (ms: number) =>
|
|
new Promise((resolve) => setTimeout(resolve, ms));
|
|
// Helper function to create dictionaries by type
|
|
export const createDict = (
|
|
type: string,
|
|
data: any,
|
|
includedField: string = "included",
|
|
) =>
|
|
Object.fromEntries(
|
|
data[includedField]
|
|
.filter((item: { type: string }) => item.type === type)
|
|
.map((item: { id: string }) => [item.id, item]),
|
|
);
|
|
|
|
export const parseStringify = (value: any) => JSON.parse(JSON.stringify(value));
|
|
|
|
export const convertFileToUrl = (file: File) => URL.createObjectURL(file);
|
|
|
|
export const getPaginationInfo = (metadata: MetaDataProps) => {
|
|
const currentPage = metadata?.pagination.page ?? "1";
|
|
const totalPages = metadata?.pagination.pages;
|
|
const totalEntries = metadata?.pagination.count;
|
|
|
|
return { currentPage, totalPages, totalEntries };
|
|
};
|
|
|
|
export function encryptKey(passkey: string) {
|
|
return btoa(passkey);
|
|
}
|
|
|
|
export function decryptKey(passkey: string) {
|
|
return atob(passkey);
|
|
}
|
|
|
|
export const getErrorMessage = async (error: unknown): Promise<string> => {
|
|
let message: string;
|
|
|
|
if (error instanceof Error) {
|
|
message = error.message;
|
|
} else if (error && typeof error === "object" && "message" in error) {
|
|
message = String(error.message);
|
|
} else if (typeof error === "string") {
|
|
message = error;
|
|
} else {
|
|
message = "Oops! Something went wrong.";
|
|
}
|
|
return message;
|
|
};
|