npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

quote-guru

v1.0.1

Published

quote-guru is a lightweight, easy-to-use library that provides random inspirational quotes. It provides each quote with its author and a neatly formatted HTML blockquote. Perfect for adding a touch of wisdom or motivation to your apps, websites, or projec

Downloads

31

Readme

Quote Guru

NPM Version License

Quote Guru is a lightweight, easy-to-use library that provides random inspirational quotes. It provides each quote with its author and a neatly formatted HTML blockquote. Perfect for adding a touch of wisdom or motivation to your apps, websites, or projects!

Features

  • Retrieve random quotes from a predefined JSON file.
  • Each quote includes the text, author, and a formatted blockquote.
  • Lightweight and easy to integrate.

Installation

You can install quote-guru via npm:

npm install quote-guru

Usage

First, import the RandomQuoteGenerator class into your project:

import { RandomQuoteGenerator } from 'quote-guru';

Then, create an instance of the RandomQuoteGenerator:

const quoteGenerator = new RandomQuoteGenerator();

Methods

getRandomQuote()

Returns a random quote with the quote text, author, and a preformatted block quote. If there are no quotes available, null will be returned.

const randomQuote = await quoteGenerator.getRandomQuote();
console.log(randomQuote);
/*
{
    quote: "Genius is one percent inspiration and ninety-nine percent perspiration.",
    author: "Thomas Edison",
    blockQuote: "<blockquote>&ldquo;Genius is one percent inspiration and ninety-nine percent perspiration.&rdquo; &mdash; <footer>Thomas Edison</footer></blockquote>"
}
*/

getRandomQuoteByAuthor(author)

Retrieves one random quote by the specified author. If the input is invalid, an error message will be returned. If there are no quotes available for the author, null will be returned.

const quotesByAuthor = await quoteGenerator.getRandomQuoteByAuthor('Thomas Edison');
console.log(quotesByAuthor);
/*
[
    {
        quote: "Genius is one percent inspiration and ninety-nine percent perspiration.",
        author: "Thomas Edison",
        blockQuote: "<blockquote>&ldquo;Genius is one percent inspiration and ninety-nine percent perspiration.&rdquo; &mdash; <footer>Thomas Edison</footer></blockquote>"
    }
]
*/

getRandomQuoteAndAuthor()

Returns a random quote with just the text and author. Useful for displaying a simple quote without the blockquote formatting. If there are no quotes available, null will be returned.

const quoteAndAuthor = await quoteGenerator.getRandomQuoteAndAuthor();
console.log(quoteAndAuthor);
/*
{
    quote: "You can observe a lot just by watching.",
    author: "Yogi Berra"
}
*/

Sample Usage

Here's an example of how you can use the quote-guru library in your project:

import { RandomQuoteGenerator } from 'quote-guru';

async function displayRandomQuotes() {
    const quoteGenerator = new RandomQuoteGenerator();

    try {
        const randomQuote = await quoteGenerator.getRandomQuote();
        const randomQuoteAuthor = await quoteGenerator.getRandomQuoteAndAuthor();
        const randomQuoteByAuthor = await quoteGenerator.getRandomQuoteByAuthor('Thomas Edison');

        console.log(randomQuote);
        console.log(randomQuoteAuthor);
        console.log(randomQuoteByAuthor);
    } catch (error) {
        console.error('Error retrieving quotes:', error);
    }
}

displayRandomQuotes();

Edge Cases and Validations

  • Make sure to use await when calling the methods to handle the asynchronous nature of the library.
  • The getRandomQuoteByAuthor method requires the author parameter to be a non-empty string. It will throw a validation error if the input is invalid.
  • If there are no quotes available (i.e., an empty quotes array), methods will return null.

Feel free to experiment with these methods to get different quotes or filter by specific authors!

JSON File Structure

The quotes are retrieved from a JSON file located in the assets directory. The file should have the following format:

[
    {
        "quoteText": "Your quote here.",
        "quoteAuthor": "Author Name"
    },
    {
        "quoteText": "Another quote.",
        "quoteAuthor": "Another Author"
    }
]

Setup on Your Local Machine

To set up the project on your local machine, follow these steps:

Clone the repository:

git clone [email protected]:evrentan/quote-guru.git

Navigate to the project directory:

cd quote-guru

Install the dependencies:

npm install

Build the project:

npm run build

Test the project:

npm test

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/yourFeature).
  3. Commit your changes (git commit -m 'feat(Feature): Add some Feature').
  4. Push to the branch (git push origin feature/yourFeature).
  5. Open a pull request.

License

This project is licensed under the ISC License.

About

This library was created to help developers easily integrate random quotes into their applications. If you have any questions or suggestions, feel free to reach out!

Acknowledgements

ZenQuotes API is an inspiration for this project. It provides a simple and easy-to-use API for retrieving random quotes.

Credits

This project uses a JSON quotes database provided by JamesFT. You can find the original quotes database here. Special thanks to JamesFT for making this valuable resource available!

Sponsoring

If you enjoy this project and would like to support its development, please consider sponsoring. Your support helps me continue improving and maintaining the project.

You can sponsor me via:

GitHub Sponsors

Buy Me a Coffee

Thank you for your support!