rez-table-listing-mui
Version:
A rez table listing component built on TanStack Table
87 lines (79 loc) • 2.61 kB
text/typescript
export const generateRickAndMortyData = (count: number) => {
const names = [
"Rick Sanchez",
"Morty Smith",
"Summer Smith",
"Beth Smith",
"Jerry Smith",
"Birdperson",
"Squanchy",
"Tammy Guetermann",
"Evil Morty",
"Pickle Rick",
"Snowball",
"Abradolf Lincler",
];
const statuses = ["Alive", "Dead", "Unknown"];
const speciesList = ["Human", "Alien", "Humanoid", "Robot", "Cronenberg"];
const genders = ["Male", "Female", "unknown"];
const locations = [
"Earth (C-137)",
"Citadel of Ricks",
"Anatomy Park",
"Interdimensional Cable",
"Planet Squanch",
"Venzenulon 7",
"Nuptia 4",
"Immortality Field Resort",
];
const types = ["Genetic experiment", "Superhuman", "Parasite", "Ghost"];
const origins = [...locations, "unknown"];
const formatDate = (date: Date) => {
const day = String(date.getDate()).padStart(2, "0");
const month = String(date.getMonth() + 1).padStart(2);
const year = String(date.getFullYear());
return `${day}/${month}/${year}`;
};
const records = [];
for (let i = 1; i <= count; i++) {
const name = names[Math.floor(Math.random() * names.length)];
const status = statuses[Math.floor(Math.random() * statuses.length)];
const species = speciesList[Math.floor(Math.random() * speciesList.length)];
const gender = genders[Math.floor(Math.random() * genders.length)];
const originName = origins[Math.floor(Math.random() * origins.length)];
const locationName =
locations[Math.floor(Math.random() * locations.length)];
const type = types[Math.floor(Math.random() * types.length)];
const randomDate = new Date(
Date.now() - Math.random() * 365 * 24 * 60 * 60 * 1000
);
const joiningDate = formatDate(randomDate);
const salary = Math.floor(Math.random() * 1000000);
records.push({
id: i,
name,
status,
species,
type,
gender,
joiningDate,
salary,
origin: {
name: originName,
url: `https://rickandmortyapi.com/api/location/${
Math.floor(Math.random() * 30) + 1
}`,
},
location: {
name: locationName,
url: `https://rickandmortyapi.com/api/location/${
Math.floor(Math.random() * 30) + 1
}`,
},
image: `https://rickandmortyapi.com/api/character/avatar/${i}.jpeg`,
url: `https://rickandmortyapi.com/api/character/${i}`,
created: joiningDate,
});
}
return records;
};