Fork of atp.tools as a universal profile for people on the ATmosphere
1// utils/textGenerator.ts
2import { WORD_LIST } from "@/lib/wordList";
3import engQuotes from "@/lib/quotes/english.json";
4
5export function generateWords(count: number): string {
6 return (
7 Array(count)
8 .fill(0)
9 .map(() => WORD_LIST.en[Math.floor(Math.random() * WORD_LIST.en.length)])
10 .join(" ") + " "
11 );
12}
13
14export function getRandomText(length: "short" | "med" | "long" | "xl"): string {
15 let minLen = 0;
16 let maxLen = 0;
17
18 switch (length) {
19 case "short":
20 minLen = 0;
21 maxLen = 75;
22 break;
23 case "med":
24 minLen = 75;
25 maxLen = 200;
26 break;
27 case "long":
28 minLen = 200;
29 maxLen = 400;
30 break;
31 case "xl":
32 minLen = 400;
33 maxLen = 999;
34 break;
35 }
36
37 let quoteSelection = engQuotes.quotes.filter(
38 (q) => q.length >= minLen && q.length <= maxLen,
39 );
40
41 if (quoteSelection.length === 0) {
42 quoteSelection = engQuotes.quotes.filter(
43 (q) => q.length >= 100 && q.length <= 200,
44 );
45 }
46
47 return quoteSelection[Math.floor(Math.random() * quoteSelection.length)];
48}