INNER CODE UNIT · TypeScript

randQuote

PiyushSuthar/github-readme-quotes · src/fetcher/fetch-quotes.ts:31

  let randQuote = validQuotes[Math.floor(Math.random() * validQuotes.length)];

  // Check length and recurse if necessary.
  return randQuote.text.length < 220 ? randQuote : randomQuote(validQuotes);
};

export async function fetchQuotes(): Promise<ParseDataReturn> {
  const response = await axios.get(
    'https://github.com/mudroljub/programming-quotes-api/raw/master/data/quotes.json'
  );

  const data: ParseDataParams[] = response.data;

  // Validate the fetched data.
  if (!Array.isArray(data)) {
    throw new Error('Fetched data is not an array.');
  }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…