Files
pruebas-automatizacion-desa…/src/data/data-pools/shared.ts

74 lines
2.6 KiB
TypeScript

export function generatePrice(enteros: number, decimales: number) {
return (Math.floor(Math.random() * (10 ^ enteros)) / (10 ^ decimales)).toString()
}
export const CURRENCIES = ["USD", "EUR", "JPY"]
export function pickCurrencies(currencies: string[]) {
if (currencies.length == 1) return currencies[0]
const max = currencies.length
const min = 0
const select = Math.floor(Math.random() * (max - min)) + min
return currencies[select]
}
export function randomDecimal(enteros: number, decimales: number) {
return (Math.floor(
Math.random() * (10 ** (enteros + decimales + 1)))
/
(10 ** (decimales))
).toString()
}
export function randomDecimalGenerator(enteros: number, decimales: number) {
return () => randomDecimal(enteros, decimales)
}
export function randomEmail() {
const domains = ["gmail.com", "outlook.com"]
const seleccionDominio = Math.floor(Math.random() * domains.length)
const randName = Math.random().toString(36).substring(3)
return randName + "@" + domains[seleccionDominio]
}
export function randomIntegerGenerator(max: number, min: number) {
return () => randomInteger(max, min)
}
export function randomInteger(max: number, min: number) {
return Math.floor(Math.random() * (max + min + 1) - min)
}
export function randomISODate() {
// 1. Generate a random date (between year 2000 and now)
const start = new Date(2000, 0, 1).getTime();
const end = new Date().getTime();
const date = new Date(Math.floor(Math.random() * (end - start + 1) + start));
// 2. Generate a random offset
// Standard offsets range from -12 to +14 hours.
// We'll pick a random hour and either 00, 30, or 45 minutes.
const offsetHours = Math.floor(Math.random() * (14 - (-12) + 1)) + (-12);
const offsetMinutes = [0, 30, 45][Math.floor(Math.random() * 3)];
// 3. Format the offset string (e.g., +05:30 or -08:00)
const sign = offsetHours >= 0 ? "+" : "-";
const absHours = Math.abs(offsetHours).toString().padStart(2, '0');
const absMinutes = offsetMinutes.toString().padStart(2, '0');
const offsetStr = `${sign}${absHours}:${absMinutes}`;
// 4. Manually construct the ISO string
const pad = (n: number) => n.toString().padStart(2, '0');
const year = date.getFullYear();
const month = pad(date.getMonth() + 1);
const day = pad(date.getDate());
const hours = pad(date.getHours());
const minutes = pad(date.getMinutes());
const seconds = pad(date.getSeconds());
const ms = date.getMilliseconds().toString().padStart(3, '0');
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${ms}${offsetStr}`;
}