Skip to content

Instantly share code, notes, and snippets.

@Klerith
Created May 13, 2024 12:29
Show Gist options
  • Save Klerith/833e30a7c42ec126495656fe80ddd745 to your computer and use it in GitHub Desktop.
Save Klerith/833e30a7c42ec126495656fe80ddd745 to your computer and use it in GitHub Desktop.
Generador de data para pruebas
import { v4 as uuidV4 } from "uuid";
import { uniqueNamesGenerator, Config, names } from "unique-names-generator";
const config: Config = {
dictionaries: [names],
};
export type Payment = {
id: string;
amount: number;
status: "pending" | "processing" | "success" | "failed";
email: string;
clientName: string;
};
const randomStatus = () => {
const statuses = ["pending", "processing", "success", "failed"] as const;
return statuses[Math.floor(Math.random() * statuses.length)];
};
const randomEmail = (clientName: string) => {
const domains = ["gmail.com", "yahoo.com", "outlook.com", "hotmail.com"];
const randomDomain = domains[Math.floor(Math.random() * domains.length)];
return `${clientName}@${randomDomain}`;
};
export const payments: Payment[] = Array.from({ length: 500 }, (_) => {
const randomName = uniqueNamesGenerator(config);
return {
id: uuidV4(),
amount: Math.floor(Math.random() * 10000) / 100,
status: randomStatus(),
clientName: randomName,
email: randomEmail(randomName.toLowerCase()),
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment