2.0.3 • Published 6 months ago

random-wiki-image v2.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

random-wiki-image

I bet u $1,000,000,000 :: pinky rises to corner of mouth :: u can't guess what this package does, nor how its usage.

Usage

Here's (a contrived version of) how I use it in my Next.js blog

"use client";

import Image from "next/image";
import { useEffect, useState } from "react";
import RandomWikiImage from "random-wiki-image";

const RandomImage = () => {
  const [imageUrl, setImageUrl] = useState < string > "";

  useEffect(() => {
    const fetchImage = async () => {
      const randomWikiImage = new RandomWikiImage();
      try {
        const url = await randomWikiImage.getRandomImageUrl();
        setImageUrl(url);
      } catch (error) {
        console.error("Failed to fetch random Wikipedia image:", error);
      }
    };

    fetchImage();
  }, []);

  return (
    <section>
      <Image
        src={imageUrl}
        alt="Random Wikipedia Image"
        width={430}
        height={100}
      />
    </section>
  );
};

export default RandomImage;

Which yields this very fun sidebar content:

alt text

With a diff one each time ; ) - and thusly, the fun:

alt text

API

new RandomWikiImage([language])

language (optional): The language code for Wikipedia (e.g., "en" for English, "es" for Spanish). Default: "en".

randomWikiImage.image()

Returns a Promise that resolves to the URL of a random Wikipedia image. If no images are found, the Promise will reject with an error.

2.0.3

6 months ago

2.0.2

6 months ago

2.0.1

6 months ago

2.0.0

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago