Nghia Vu

Nghia Vu

// Name: Dummy Data
// Description: Generate fake data for real use-case (that #version just generate fields about person and color)
// Author: Nghia Vu (Ngh14)
import '@johnlindquist/kit';
import falso from '@ngneat/falso';
let counts = 1;
const randZodiacSign = () => {
const zodiacSigns = [
'Aries',
'Taurus',
'Gemini',
'Cancer',
'Leo',
'Virgo',
'Libra',
'Scorpio',
'Sagittarius',
'Capricorn',
'Aquarius',
'Pisces',
];
return falso.rand(zodiacSigns);
};
const person = [
{
name: 'Full Name',
value: () => falso.randFullName(),
description: 'The complete name of the randomly generated user.',
},
{
name: 'Title',
value: () => falso.randPersonTitle(),
description: 'The professional title of the randomly generated user.',
},
{
name: 'Email',
value: () => falso.randEmail(),
description: 'The email address of the randomly generated user.',
},
{
name: 'Phone',
value: () => falso.randPhoneNumber(),
description: 'The phone number of the randomly generated user.',
},
{
name: 'Address',
value: () => falso.randAddress(),
description: 'The physical address of the randomly generated user.',
},
{
name: 'Username',
value: () => falso.randUserName(),
description: 'The username chosen for the randomly generated user.',
},
{
name: 'Last Name',
value: () => falso.randLastName(),
description: 'The last name of the randomly generated user.',
},
{
name: 'First_Name',
value: () => falso.randFirstName(),
description: 'The first name of the randomly generated user.',
},
{
name: 'Gender',
value: () => falso.randGender(),
description: 'The gender of the randomly generated user.',
},
{
name: 'Avatar',
value: () => falso.randAvatar(),
description: 'The profile picture (avatar) of the randomly generated user.',
},
{
name: 'Pronoun',
value: () => falso.randPronoun(),
description: 'The preferred pronoun of the randomly generated user.',
},
{
name: 'Skill',
value: () => falso.randSkill(),
description: 'A skill associated with the randomly generated user.',
},
{
name: 'Password',
value: () => falso.randPassword(),
description: 'The password for the randomly generated user.',
},
{
name: 'Country',
value: () => falso.randCountry(),
description: 'The country of residence of the randomly generated user.',
},
{
name: 'City',
value: () => falso.randCity(),
description: 'The city of residence of the randomly generated user.',
},
{
name: 'Role',
value: () => falso.randRole(),
description: 'The role or position held by the randomly generated user.',
},
{
name: 'Company',
value: () => falso.randCompanyName(),
description:
'The name of the company associated with the randomly generated user.',
},
{
name: 'Subscription Plan',
value: () => falso.randSubscriptionPlan(),
description: 'The subscription plan chosen by the randomly generated user.',
},
{
name: 'Date of Birth',
value: () => falso.randPastDate(),
description: 'The date of birth of the randomly generated user.',
},
{
name: 'Credit Card',
value: () => falso.randCreditCard(),
description: 'The randomly generated credit card information of the user.',
},
{
name: 'User Agent',
value: () => falso.randUserAgent(),
description:
'The user agent of the device used by the randomly generated user.',
},
{
name: 'IP',
value: () => falso.randIP(),
description: 'The randomly generated IP address of the user.',
},
{
name: 'IP6',
value: () => falso.randIP6(),
description: 'The randomly generated IPv6 address of the user.',
},
{
name: 'Zodiac Sign',
value: () => randZodiacSign(),
description: 'The randomly generated zodiac sign of the user.',
},
];
const color = [
{
name: 'Name',
value: () => falso.randColor(),
description: 'Generates a random color name.',
},
{
name: 'HEX',
value: () => falso.randHex(),
description: 'Generates a random hexadecimal color code.',
},
{
name: 'HSL',
value: () => falso.randHsl(),
description:
'Generates a random HSL (Hue, Saturation, Lightness) color code.',
},
{
name: 'RGB',
value: () => falso.randRgb(),
description: 'Generates a random RGB (Red, Green, Blue) color code.',
},
{
name: 'RGBa',
value: () => falso.randRgb({ alpha: true }),
description:
'Generates a random RGBA (Red, Green, Blue, Alpha) color code.',
},
];
function filterDataField(arr, field) {
const filtered = {};
arr.map(({ name, value }) => {
if (field.includes(name)) {
filtered[name] = value();
}
});
return filtered;
}
function generateData({ types, fields, ...rest }) {
const arr = [];
for (let index = 0; index < counts; index++) {
arr.push(filterDataField(types, fields));
}
setSelectedText(JSON.stringify(arr));
}
let types = await arg('Generate Random Data...', ['people', 'color']);
if (types == 'people') {
let peopleField = await select(
'Select a fields....',
person
.sort((a, b) => a.name.localeCompare(b.name))
.map(({ name, value, description }) => ({
name,
description,
value: name,
height: PROMPT.HEIGHT.XS,
preview: () => JSON.stringify(value()),
})),
);
counts = await arg({
description: 'How many person records you want?',
placeholder: '1',
});
generateData({ types: person, fields: peopleField });
} else if (types == 'color') {
let result = await arg(
'Generate random color...',
color.map(({ name, value, description }) => ({
name,
description,
value: value(),
height: PROMPT.HEIGHT.XS,
preview: () => value(),
})),
);
setSelectedText(result);
}