misskey/packages/frontend/.storybook/fake-utils.ts

96 lines
3.1 KiB
TypeScript
Raw Normal View History

2024-02-22 10:24:47 +00:00
/**
* AIで生成した無作為なファーストネーム
*/
export const firstNameDict: string = [
'Ethan', 'Olivia', 'Jackson', 'Emma', 'Liam', 'Ava', 'Aiden', 'Sophia', 'Mason', 'Isabella',
'Noah', 'Mia', 'Lucas', 'Harper', 'Caleb', 'Abigail', 'Samuel', 'Emily', 'Logan',
'Madison', 'Benjamin', 'Chloe', 'Elijah', 'Grace', 'Alexander', 'Scarlett', 'William', 'Zoey', 'James', 'Lily',
]
/**
* AIで生成した無作為なラストネーム
*/
export const lastNameDict: string = [
'Anderson', 'Johnson', 'Thompson', 'Davis', 'Rodriguez', 'Smith', 'Patel', 'Williams', 'Lee', 'Brown',
'Garcia', 'Jackson', 'Martinez', 'Taylor', 'Harris', 'Nguyen', 'Miller', 'Jones', 'Wilson',
'White', 'Thomas', 'Garcia', 'Martinez', 'Robinson', 'Turner', 'Lewis', 'Hall', 'King', 'Baker', 'Cooper',
]
/**
* AIで生成した無作為な国名
*/
export const countryDict: string = [
'Japan', 'Canada', 'Brazil', 'Australia', 'Italy', 'SouthAfrica', 'Mexico', 'Sweden', 'Russia', 'India',
'Germany', 'Argentina', 'South Korea', 'France', 'Nigeria', 'Turkey', 'Spain', 'Egypt', 'Thailand',
'Vietnam', 'Kenya', 'Saudi Arabia', 'Netherlands', 'Colombia', 'Poland', 'Chile', 'Malaysia', 'Ukraine', 'New Zealand', 'Peru',
]
export function text(length: number = 10): string {
let result = "";
while (result.length < length) {
result += Math.random().toString(36).substring(2);
}
return result.substring(0, length);
}
export function integer(min: number = 0, max: number = 9999): number {
return Math.floor(Math.random() * (max - min)) + min;
}
export function date(params?: {
yearMin?: number,
yearMax?: number,
monthMin?: number,
monthMax?: number,
dayMin?: number,
dayMax?: number,
hourMin?: number,
hourMax?: number,
minuteMin?: number,
minuteMax?: number,
secondMin?: number,
secondMax?: number,
millisecondMin?: number,
millisecondMax?: number,
}) {
const year = integer(params?.yearMin ?? 1970, params?.yearMax ?? (new Date()).getFullYear());
const month = integer(params?.monthMin ?? 1, params?.monthMax ?? 12);
let day = integer(params?.dayMin ?? 1, params?.dayMax ?? 31);
if (month === 2) {
day = Math.min(day, 28);
} else if ([4, 6, 9, 11].includes(month)) {
day = Math.min(day, 30);
} else {
day = Math.min(day, 31);
}
const hour = integer(params?.hourMin ?? 0, params?.hourMax ?? 23);
const minute = integer(params?.minuteMin ?? 0, params?.minuteMax ?? 59);
const second = integer(params?.secondMin ?? 0, params?.secondMax ?? 59);
const millisecond = integer(params?.millisecondMin ?? 0, params?.millisecondMax ?? 999);
return new Date(year, month - 1, day, hour, minute, second, millisecond);
}
export function boolean(): boolean {
return Math.random() < 0.5;
}
export function choose<T>(array: T[]): T {
return array[Math.floor(Math.random() * array.length)];
}
export function firstName(): string {
return firstNameDict[Math.floor(Math.random() * firstNameDict.length)];
}
export function lastName(): string {
return lastNameDict[Math.floor(Math.random() * lastNameDict.length)];
}
export function country(): string {
return countryDict[Math.floor(Math.random() * countryDict.length)];
}