word-jokes
v1.0.0
Published
A fun npm package that generates random jokes starting with a given word. Perfect for adding humor to your applications!
Maintainers
Readme
Word Jokes Package
A fun and simple npm package that generates random jokes starting with a given word. Perfect for adding humor to your applications!
Installation
npm install word-jokesUsage
Basic Usage
const { getJoke, getRandomJoke, getCategories } = require("word-jokes");
// Get a joke starting with a specific word
console.log(getJoke("what"));
// Output: "What do you call a bear with no teeth? A gummy bear!"
// Get a random joke from any category
console.log(getRandomJoke());
// Output: Random joke from any category
// Get all available categories
console.log(getCategories());
// Output: ["what", "why", "how", "when", "where", "who", "which", "can", "do", "are", "is", "the", "a", "an"]Advanced Usage
const { getJokesByCategory, jokes } = require("word-jokes");
// Get all jokes from a specific category
const whyJokes = getJokesByCategory("why");
console.log(whyJokes);
// Output: Array of all "why" jokes
// Access the jokes object directly
console.log(jokes.what);
// Output: Array of all "what" jokesAvailable Categories
The package includes jokes starting with these words:
- what - What do you call... jokes
- why - Why don't... jokes
- how - How do you... jokes
- when - When is... jokes
- where - Where do you... jokes
- who - Who is... jokes
- which - Which... jokes
- can - Can... jokes
- do - Do you know... jokes
- are - Are you... pickup lines
- is - Is your name... pickup lines
- the - The best time... jokes
- a - A... walks into a bar jokes
- an - An... jokes
API Reference
getJoke(word)
Generates a random joke starting with the given word.
Parameters:
word(string): The word to start the joke with
Returns:
string: A random joke starting with the word, or a default joke if no match found
Example:
getJoke("what"); // Returns a random "what" joke
getJoke("why"); // Returns a random "why" jokegetRandomJoke()
Gets a random joke from any category.
Returns:
string: A random joke from any available category
getCategories()
Gets all available joke categories.
Returns:
string[]: Array of available joke categories
getJokesByCategory(category)
Gets all jokes from a specific category.
Parameters:
category(string): The category to get jokes from
Returns:
string[]: Array of jokes from the category, or empty array if category doesn't exist
jokes
The raw jokes object containing all jokes organized by category.
Examples
Node.js Application
const { getJoke } = require("word-jokes");
// Simple joke generator
function tellJoke(word) {
const joke = getJoke(word);
console.log(`Here's a joke starting with "${word}":`);
console.log(joke);
}
tellJoke("how");
tellJoke("why");Web Application
const { getJoke, getCategories } = require("word-jokes");
// Express.js example
app.get("/joke/:word", (req, res) => {
const word = req.params.word;
const joke = getJoke(word);
res.json({ word, joke });
});
app.get("/categories", (req, res) => {
const categories = getCategories();
res.json({ categories });
});Discord Bot
const { getJoke } = require("word-jokes");
client.on("message", (message) => {
if (message.content.startsWith("!joke")) {
const word = message.content.split(" ")[1] || "random";
const joke = word === "random" ? getRandomJoke() : getJoke(word);
message.channel.send(joke);
}
});Contributing
Feel free to contribute by adding more jokes or improving the existing ones! Just make sure they're family-friendly and appropriate for all audiences.
License
ISC
Author
Vaibhav Sharma
Note: This package is designed to be fun and family-friendly. All jokes are clean and suitable for all audiences.
