bee-jokes
Version:
bee-jokes is a lightweight TypeScript/JavaScript package that delivers clean, categorized, and multilingual jokes — fast and ready to sting your apps with humor!
827 lines (821 loc) • 27.1 kB
JavaScript
// src/data/jokes.json
var jokes_default = [
{
id: "programming-001",
joke: "Why do programmers prefer dark mode? Because light attracts bugs.",
category: "programming",
langCode: "en",
tags: ["bugs", "dark-mode", "developer"]
},
{
id: "programming-002",
joke: "Why do programmers always mix up Halloween and Christmas? Because Oct 31 == Dec 25!",
category: "programming",
langCode: "en",
tags: ["dates", "binary", "developer"]
},
{
id: "programming-003",
joke: "There are 10 types of people in this world. Those who understand binary, and those who don't.",
category: "programming",
langCode: "en",
tags: ["binary", "logic", "developer"]
},
{
id: "programming-004",
joke: "Pourquoi les programmeurs aiment-ils le noir ? Parce que le noir, c'est comme le code, on ne voit rien !",
category: "programming",
langCode: "fr",
tags: ["code", "dark-mode", "developer"]
},
{
id: "general-001",
joke: "Why don't scientists trust atoms? Because they make up everything!",
category: "general",
langCode: "en",
tags: ["science", "pun", "chemistry"]
},
{
id: "general-002",
joke: "\xBFQu\xE9 le dice un sem\xE1foro a otro sem\xE1foro? No me mires que te pongo verde.",
category: "general",
langCode: "es",
tags: ["traffic", "pun"]
},
{
id: "general-003",
joke: "\u091F\u0940\u091A\u0930: \u0939\u094B\u092E\u0935\u0930\u094D\u0915 \u0915\u094D\u092F\u094B\u0902 \u0928\u0939\u0940\u0902 \u0915\u093F\u092F\u093E? \u091B\u093E\u0924\u094D\u0930: \u092E\u0948\u092E, \u0932\u093E\u0907\u091F \u0928\u0939\u0940\u0902 \u0925\u0940\u0964 \u091F\u0940\u091A\u0930: \u0924\u094B \u092E\u094B\u092E\u092C\u0924\u094D\u0924\u0940 \u091C\u0932\u093E \u0932\u0947\u0924\u0947\u0964 \u091B\u093E\u0924\u094D\u0930: \u092E\u0948\u092E, \u092E\u093E\u091A\u093F\u0938 \u0928\u0939\u0940\u0902 \u0925\u0940\u0964 \u091F\u0940\u091A\u0930: \u0924\u094B \u092E\u093E\u091A\u093F\u0938 \u0916\u0930\u0940\u0926 \u0932\u0947\u0924\u0947\u0964 \u091B\u093E\u0924\u094D\u0930: \u092E\u0948\u092E, \u092A\u0948\u0938\u0947 \u0928\u0939\u0940\u0902 \u0925\u0947\u0964 \u091F\u0940\u091A\u0930: \u0924\u094B \u092A\u0948\u0938\u0947 \u0915\u092E\u093E \u0932\u0947\u0924\u0947\u0964 \u091B\u093E\u0924\u094D\u0930: \u092E\u0948\u092E, \u092F\u0939\u0940 \u0924\u094B \u0939\u094B\u092E\u0935\u0930\u094D\u0915 \u092E\u0947\u0902 \u0925\u093E!",
category: "general",
langCode: "hi",
tags: ["school", "homework", "student"]
},
{
id: "dadjokes-001",
joke: "I'm reading a book on anti-gravity. It's impossible to put down!",
category: "dadjokes",
langCode: "en",
tags: ["physics", "pun", "book"]
},
{
id: "dadjokes-002",
joke: "\xBFQu\xE9 hace una abeja en el gimnasio? \xA1Zumba!",
category: "dadjokes",
langCode: "es",
tags: ["animals", "pun", "gym"]
},
{
id: "puns-001",
joke: "I told my wife she was drawing her eyebrows too high. She looked surprised.",
category: "puns",
langCode: "en",
tags: ["looks", "surprise"]
},
{
id: "puns-002",
joke: "Qu'est-ce qu'un chat qui tombe dans un pot de peinture le jour de No\xEBl ? Un chat-peint de No\xEBl !",
category: "puns",
langCode: "fr",
tags: ["animals", "christmas", "pun"]
},
{
id: "science-001",
joke: "What did the atom say to the electron? Don't be negative!",
category: "science",
langCode: "en",
tags: ["physics", "chemistry", "pun"]
},
{
id: "science-002",
joke: "\xBFQu\xE9 le dijo un prot\xF3n a otro prot\xF3n? \xA1Hoy estoy positivo!",
category: "science",
langCode: "es",
tags: ["physics", "chemistry", "positive"]
},
{
id: "officelife-001",
joke: "My boss told me to have a good day. So I went home.",
category: "officelife",
langCode: "en",
tags: ["boss", "work", "day-off"]
},
{
id: "animals-001",
joke: "Why did the scarecrow win an award? Because he was outstanding in his field!",
category: "animals",
langCode: "en",
tags: ["farm", "pun", "award"]
},
{
id: "animals-002",
joke: "Que dit un escargot quand il croise une limace ? \xAB Tiens, t'as oubli\xE9 ta maison ! \xBB",
category: "animals",
langCode: "fr",
tags: ["snail", "slug", "pun"]
},
{
id: "relationships-001",
joke: "I asked my girlfriend to tell me something that would get my heart racing. She said, 'I forgot my wallet.'",
category: "relationships",
langCode: "en",
tags: ["girlfriend", "money", "wallet"]
},
{
id: "school-001",
joke: "Why did the math book look sad? Because it had too many problems.",
category: "school",
langCode: "en",
tags: ["math", "book", "problems"]
},
{
id: "school-002",
joke: "\u091F\u0940\u091A\u0930: 15 \u092B\u0932\u094B\u0902 \u0915\u0947 \u0928\u093E\u092E \u092C\u0924\u093E\u0913\u0964 \u091B\u093E\u0924\u094D\u0930: \u090F\u0915 \u0926\u0930\u094D\u091C\u0928 \u0915\u0947\u0932\u0947 \u0914\u0930 \u0924\u0940\u0928 \u0938\u0947\u092C\u0964",
category: "school",
langCode: "hi",
tags: ["fruits", "math", "student"]
},
{
id: "food-001",
joke: "Why did the tomato turn red? Because it saw the salad dressing!",
category: "food",
langCode: "en",
tags: ["vegetables", "salad", "pun"]
},
{
id: "food-002",
joke: "\xBFQu\xE9 hace un mudo en un gallinero? \xA1Huevos de chocolate!",
category: "food",
langCode: "es",
tags: ["chocolate", "chicken", "pun"]
},
{
id: "sports-001",
joke: "Why did the football coach go to the bank? To get his quarter back.",
category: "sports",
langCode: "en",
tags: ["football", "bank", "pun"]
},
{
id: "history-001",
joke: "Why did the Roman Empire fall? Because it couldn't stand being conquered by the barbarians!",
category: "history",
langCode: "en",
tags: ["rome", "empire", "fall"]
},
{
id: "travel-001",
joke: "I used to be a travel agent, but I gave it up. It was just too much baggage.",
category: "travel",
langCode: "en",
tags: ["agent", "luggage", "pun"]
},
{
id: "medical-001",
joke: "What's a doctor's favorite kind of music? Anything with a good beat.",
category: "medical",
langCode: "en",
tags: ["doctor", "music", "pun"]
},
{
id: "tech-001",
joke: "Why was the mobile phone wearing glasses? Because it lost its contacts.",
category: "tech",
langCode: "en",
tags: ["phone", "glasses", "contacts"]
},
{
id: "music-001",
joke: "Why did the music teacher need a ladder? To reach the high notes.",
category: "music",
langCode: "en",
tags: ["teacher", "notes", "instrument"]
},
{
id: "financial-001",
joke: "Why did the accountant break up with the calculator? Because he just couldn't count on her.",
category: "financial",
langCode: "en",
tags: ["accountant", "calculator", "breakup"]
},
{
id: "popculture-001",
joke: "Why did the superhero get invited to all the parties? Because he was a Marvel!",
category: "popculture",
langCode: "en",
tags: ["superhero", "marvel", "party"]
},
{
id: "holiday-001",
joke: "Why did Santa get a parking ticket on Christmas Eve? He left his sleigh in a snow parking zone!",
category: "holiday",
langCode: "en",
tags: ["christmas", "santa", "parking"]
},
{
id: "family-001",
joke: "My family is so annoying. We're like a tangled ball of yarn, always getting on each other's nerves.",
category: "family",
langCode: "en",
tags: ["parents", "siblings", "relationships"]
},
{
id: "sarcasm-001",
joke: "I'm so good at sleeping, I can do it with my eyes closed.",
category: "sarcasm",
langCode: "en",
tags: ["sleep", "obvious", "humor"]
},
{
id: "programming-007",
joke: "Why did the developer go broke? Because he used up all his cache.",
category: "programming",
langCode: "en",
tags: ["money", "cache", "developer"]
},
{
id: "programming-008",
joke: "What's a programmer's favorite bug? A feature.",
category: "programming",
langCode: "en",
tags: ["bugs", "feature", "humor"]
},
{
id: "programming-009",
joke: "Pourquoi les d\xE9veloppeurs n'aiment-ils pas la nature ? Trop de feuilles sans documentation.",
category: "programming",
langCode: "fr",
tags: ["documentation", "nature", "developer"]
},
{
id: "programming-010",
joke: "What's the best thing about booleans? Even if you're wrong, you're only off by a bit.",
category: "programming",
langCode: "en",
tags: ["boolean", "bit", "logic"]
},
{
id: "general-006",
joke: "Why did the bicycle fall over? Because it was two-tired.",
category: "general",
langCode: "en",
tags: ["bicycle", "pun", "tired"]
},
{
id: "general-007",
joke: "\xBFCu\xE1l es el colmo de un jardinero? Que deje a su mujer plantada.",
category: "general",
langCode: "es",
tags: ["gardener", "pun", "relationships"]
},
{
id: "general-008",
joke: "\u092E\u0947\u0930\u0947 \u0926\u094B\u0938\u094D\u0924 \u0928\u0947 \u092E\u0941\u091D\u0938\u0947 \u0915\u0939\u093E \u0915\u093F \u0935\u0939 \u090F\u0915 \u0926\u093F\u0928 \u092E\u0947\u0902 1000 \u092A\u0941\u0936-\u0905\u092A\u094D\u0938 \u0915\u0930 \u0938\u0915\u0924\u093E \u0939\u0948\u0964 \u092E\u0948\u0902\u0928\u0947 \u092A\u0942\u091B\u093E, '\u0915\u0948\u0938\u0947?' \u0909\u0938\u0928\u0947 \u0915\u0939\u093E, '\u0927\u0940\u0930\u0947-\u0927\u0940\u0930\u0947\u0964'",
category: "general",
langCode: "hi",
tags: ["friend", "exercise", "humor"]
},
{
id: "dadjokes-005",
joke: "I invented a new word: plagiarism.",
category: "dadjokes",
langCode: "en",
tags: ["wordplay", "irony"]
},
{
id: "dadjokes-006",
joke: "\xBFQu\xE9 le dice un guepardo a otro guepardo? 'Est\xE1s hecho una bala.'",
category: "dadjokes",
langCode: "es",
tags: ["animals", "speed", "pun"]
},
{
id: "puns-005",
joke: "I used to be a baker, but I kneaded dough so much I got tired.",
category: "puns",
langCode: "en",
tags: ["baker", "food", "tired"]
},
{
id: "puns-006",
joke: "Pourquoi les poissons vivent-ils dans l'eau sal\xE9e ? Parce que l'eau poivr\xE9e les ferait \xE9ternuer !",
category: "puns",
langCode: "fr",
tags: ["fish", "food", "water"]
},
{
id: "science-003",
joke: "What did the biologist wear to his first date? Designer genes.",
category: "science",
langCode: "en",
tags: ["biology", "genes", "date"]
},
{
id: "science-004",
joke: "\xBFPor qu\xE9 el 6 ten\xEDa miedo del 7? Porque el 7, 8, 9.",
category: "science",
langCode: "es",
tags: ["numbers", "pun", "math"]
},
{
id: "officelife-002",
joke: "My job is secure. No one else wants it.",
category: "officelife",
langCode: "en",
tags: ["work", "job", "sarcasm"]
},
{
id: "officelife-003",
joke: "I told my boss I needed a raise. He said, 'Why don't you stand on a chair?'",
category: "officelife",
langCode: "en",
tags: ["boss", "raise", "humor"]
},
{
id: "animals-003",
joke: "What do you call a sleeping bull? A bulldozer.",
category: "animals",
langCode: "en",
tags: ["farm", "animals", "pun"]
},
{
id: "animals-004",
joke: "Pourquoi les canards n'ont-ils jamais faim ? Parce qu'ils ont toujours la patate !",
category: "animals",
langCode: "fr",
tags: ["duck", "food", "pun"]
},
{
id: "relationships-002",
joke: "My wife and I have a great relationship. We never go to bed angry. We just stay up and fight.",
category: "relationships",
langCode: "en",
tags: ["marriage", "wife", "fighting"]
},
{
id: "relationships-003",
joke: "Dating is like a job interview, except you're both lying and you both know it.",
category: "relationships",
langCode: "en",
tags: ["dating", "interview", "truth"]
},
{
id: "school-003",
joke: "Why did the student eat his homework? Because the teacher told him it was a piece of cake.",
category: "school",
langCode: "en",
tags: ["homework", "student", "teacher"]
},
{
id: "school-004",
joke: "\u0917\u0923\u093F\u0924 \u0915\u0947 \u0905\u0927\u094D\u092F\u093E\u092A\u0915 \u0928\u0947 \u091B\u093E\u0924\u094D\u0930 \u0938\u0947 \u092A\u0942\u091B\u093E, '\u0905\u0917\u0930 \u0924\u0941\u092E\u094D\u0939\u093E\u0930\u0947 \u092A\u093E\u0938 5 \u0938\u0947\u092C \u0939\u0948\u0902 \u0914\u0930 \u092E\u0948\u0902 \u0924\u0941\u092E\u094D\u0939\u0947\u0902 5 \u0914\u0930 \u0926\u0947\u0924\u093E \u0939\u0942\u0901, \u0924\u094B \u0924\u0941\u092E\u094D\u0939\u093E\u0930\u0947 \u092A\u093E\u0938 \u0915\u093F\u0924\u0928\u0947 \u0939\u094B\u0902\u0917\u0947?' \u091B\u093E\u0924\u094D\u0930: '10\u0964' \u0905\u0927\u094D\u092F\u093E\u092A\u0915: '\u092C\u0939\u0941\u0924 \u0905\u091A\u094D\u091B\u0947! \u0905\u092C \u092C\u0924\u093E\u0913, \u0905\u0917\u0930 \u0924\u0941\u092E\u094D\u0939\u093E\u0930\u0947 \u092A\u093E\u0938 5 \u0915\u0947\u0932\u0947 \u0939\u0948\u0902 \u0914\u0930 \u092E\u0948\u0902 \u0924\u0941\u092E\u094D\u0939\u0947\u0902 5 \u0914\u0930 \u0926\u0947\u0924\u093E \u0939\u0942\u0901, \u0924\u094B \u0924\u0941\u092E\u094D\u0939\u093E\u0930\u0947 \u092A\u093E\u0938 \u0915\u093F\u0924\u0928\u0947 \u0939\u094B\u0902\u0917\u0947?' \u091B\u093E\u0924\u094D\u0930: '\u0915\u0941\u091B \u0928\u0939\u0940\u0902, \u0915\u094D\u092F\u094B\u0902\u0915\u093F \u0915\u0947\u0932\u0947 \u0924\u094B \u092E\u0947\u0930\u0947 \u092A\u093E\u0938 \u0925\u0947 \u0939\u0940 \u0928\u0939\u0940\u0902\u0964'",
category: "school",
langCode: "hi",
tags: ["math", "student", "logic"]
},
{
id: "food-003",
joke: "What do you call a sad strawberry? A blueberry.",
category: "food",
langCode: "en",
tags: ["fruit", "pun", "sad"]
},
{
id: "food-004",
joke: "\xBFQu\xE9 le dijo una taza a otra taza? '\xBFQu\xE9 taza haciendo?'",
category: "food",
langCode: "es",
tags: ["utensil", "pun", "tea"]
},
{
id: "sports-002",
joke: "Why was the tennis match so loud? Because both players had a racket!",
category: "sports",
langCode: "en",
tags: ["tennis", "racket", "loud"]
},
{
id: "sports-003",
joke: "What do you call a boomerang that won't come back? A stick.",
category: "sports",
langCode: "en",
tags: ["boomerang", "stick", "funny"]
},
{
id: "history-002",
joke: "Why did the historian break up with the archaeologist? They had too many old issues.",
category: "history",
langCode: "en",
tags: ["history", "archaeology", "relationships"]
},
{
id: "history-003",
joke: "What do you call a sleeping dinosaur? Dino-snore!",
category: "history",
langCode: "en",
tags: ["dinosaur", "pun", "sleep"]
},
{
id: "travel-002",
joke: "I'm on a seafood diet. I see food, and I eat it. Especially when I travel!",
category: "travel",
langCode: "en",
tags: ["diet", "food", "vacation"]
},
{
id: "travel-003",
joke: "What do you call a grumpy traveler? A grum-pillion.",
category: "travel",
langCode: "en",
tags: ["traveler", "grumpy", "pun"]
},
{
id: "medical-002",
joke: "Why did the patient bring a ladder to the doctor's office? Because he heard he had high blood pressure.",
category: "medical",
langCode: "en",
tags: ["doctor", "patient", "blood-pressure"]
},
{
id: "medical-003",
joke: "What do you call a fake doctor? A 'phoney' physician.",
category: "medical",
langCode: "en",
tags: ["doctor", "fake", "pun"]
},
{
id: "tech-002",
joke: "Why did the computer go to the doctor? It had a virus!",
category: "tech",
langCode: "en",
tags: ["computer", "virus", "sick"]
},
{
id: "tech-003",
joke: "I told my computer I needed a break, and it just kept buffering.",
category: "tech",
langCode: "en",
tags: ["computer", "break", "buffering"]
},
{
id: "music-002",
joke: "What do you call a musically talented insect? A bee-thoven.",
category: "music",
langCode: "en",
tags: ["insect", "composer", "pun"]
},
{
id: "music-003",
joke: "Why did the guitar get sent to jail? For fretting too much.",
category: "music",
langCode: "en",
tags: ["guitar", "jail", "pun"]
},
{
id: "financial-002",
joke: "Why did the stock market break up with the economy? It just wasn't feeling stable.",
category: "financial",
langCode: "en",
tags: ["stock-market", "economy", "breakup"]
},
{
id: "financial-003",
joke: "I just inherited a fortune from my late uncle. He died in a bank robbery. He was the teller.",
category: "financial",
langCode: "en",
tags: ["money", "bank", "dark-humor"]
},
{
id: "popculture-002",
joke: "Why did the superhero cross the road? To get to the other Marvel side.",
category: "popculture",
langCode: "en",
tags: ["superhero", "marvel", "road"]
},
{
id: "popculture-003",
joke: "What do you call a fake famous person? A 'cele-fakey.'",
category: "popculture",
langCode: "en",
tags: ["celebrity", "fake", "pun"]
},
{
id: "holiday-002",
joke: "What do you call Santa's little helpers? Subordinate Clauses.",
category: "holiday",
langCode: "en",
tags: ["christmas", "santa", "elves"]
},
{
id: "holiday-003",
joke: "Why did the ghost go to the bar on Halloween? For the boos.",
category: "holiday",
langCode: "en",
tags: ["halloween", "ghost", "bar"]
},
{
id: "family-002",
joke: "My family reunion was like a jigsaw puzzle. Everyone tried to fit in, but some pieces were just missing.",
category: "family",
langCode: "en",
tags: ["reunion", "jigsaw-puzzle", "relationships"]
},
{
id: "family-003",
joke: "My kids are like a permanent record player. They keep spinning the same old complaints.",
category: "family",
langCode: "en",
tags: ["kids", "parents", "complaints"]
},
{
id: "sarcasm-002",
joke: "I love group projects. Said no one ever.",
category: "sarcasm",
langCode: "en",
tags: ["school", "work", "projects"]
},
{
id: "sarcasm-003",
joke: "I'm not saying I'm lazy, but I wear a Fitbit just to track my naps.",
category: "sarcasm",
langCode: "en",
tags: ["lazy", "fitbit", "naps"]
}
];
// src/data/langcode.json
var langcode_default = [
{ code: "en", language: "English" },
{ code: "hi", language: "Hindi" },
{ code: "es", language: "Spanish" },
{ code: "fr", language: "French" },
{ code: "de", language: "German" },
{ code: "it", language: "Italian" },
{ code: "pt", language: "Portuguese" },
{ code: "ru", language: "Russian" },
{ code: "ja", language: "Japanese" },
{ code: "ko", language: "Korean" },
{ code: "bn", language: "Bengali" },
{ code: "ur", language: "Urdu" },
{ code: "zh", language: "Chinese (Simplified)" },
{ code: "ar", language: "Arabic" },
{ code: "ta", language: "Tamil" },
{ code: "te", language: "Telugu" },
{ code: "gu", language: "Gujarati" },
{ code: "ml", language: "Malayalam" },
{ code: "pa", language: "Punjabi" },
{ code: "mr", language: "Marathi" }
];
// src/data/categories.json
var categories_default = [
{
name: "programming",
description: "Jokes for developers, coders, and software engineers."
},
{
name: "general",
description: "Light-hearted and everyday jokes for everyone."
},
{
name: "dadjokes",
description: "Classic groan-worthy dad jokes and puns."
},
{
name: "puns",
description: "Wordplay and clever punchlines that twist language."
},
{
name: "science",
description: "Nerdy jokes about physics, chemistry, and biology."
},
{
name: "officelife",
description: "Humor about meetings, emails, and coworkers."
},
{
name: "animals",
description: "Funny jokes about pets, wildlife, and creatures."
},
{
name: "relationships",
description: "Funny takes on dating, marriage, and friendship."
},
{
name: "school",
description: "Classroom humor and student-life jokes."
},
{
name: "food",
description: "Jokes about cooking, eating, and all things culinary."
},
{
name: "sports",
description: "Humor related to athletes, games, and competitions."
},
{
name: "history",
description: "Witty jokes and puns based on historical events and figures."
},
{
name: "travel",
description: "Jokes about vacations, airlines, and exploring new places."
},
{
name: "medical",
description: "Humor from the world of doctors, nurses, and hospitals."
},
{
name: "tech",
description: "Jokes about gadgets, the internet, and modern technology (beyond just programming)."
},
{
name: "music",
description: "Funny observations and puns about musicians, instruments, and songs."
},
{
name: "financial",
description: "Jokes about money, banking, and economics."
},
{
name: "popculture",
description: "Humor referencing movies, TV shows, celebrities, and trends."
},
{
name: "holiday",
description: "Themed jokes for various holidays like Christmas, Halloween, etc."
},
{
name: "family",
description: "Jokes about parents, children, siblings, and extended family."
},
{
name: "sarcasm",
description: "Witty and often ironic humor, sometimes with a dry delivery."
}
];
// src/utils/filterSafeJokes.ts
var unsafeWords = [
"sex",
"sexual",
"porn",
"porno",
"nude",
"naked",
"violence",
"kill",
"murder",
"blood",
"racist",
"suicide",
"drug",
"drugs",
"alcohol",
"beer",
"bastard",
"asshole",
"damn",
"shit",
"fuck",
"fucking",
"bitch",
"dick",
"pussy",
"cock",
"boobs",
"nipples",
"slut",
"whore",
"gay",
"lesbian",
"rape",
"molest",
"abuse",
"terrorist",
"terrorism",
"bomb",
"gun",
"shoot",
"hitler",
"nazis"
];
var filterSafeJokes = (jokes2) => {
return jokes2.filter(
(joke) => !joke.joke.toLocaleLowerCase().split(/\s+/).some((word) => unsafeWords.includes(word))
);
};
var filterSafeJokes_default = filterSafeJokes;
// src/utils/randomCategoryProvider.ts
var categoryData = categories_default;
var provideRandomCategory = () => {
const categoryNameOnly = categoryData.map((cate) => cate.name);
const randomIndex = Math.floor(Math.random() * categoryNameOnly.length);
if (categoryNameOnly.length === 0) {
throw new Error("No categories available to choose from.");
}
return categoryNameOnly[randomIndex];
};
// src/index.ts
var jokes = jokes_default;
var langs = langcode_default;
var categories = categories_default;
var Joke = class {
/**
* Retrieves a joke by its unique ID.
*
* @param id - The ID of the joke to retrieve.
* @returns The matching joke object if found, otherwise `null`.
*/
getJokeById(id) {
const filtered = jokes.filter((joke) => joke.id === id);
return filtered.length > 0 ? filtered[0] : null;
}
/**
* Retrieves all jokes
* @returns A list of all available jokes
*/
getAllJokes() {
return jokes;
}
/**
* Retrieves a single joke based on the specified category and language.
*
* @param category - The category of the joke (defaults to `"programming"` if not provided).
* @param lang - The language code for the joke (defaults to `"en"` if not provided).
* @returns A matching joke object if found, otherwise `null`.
*/
getJoke({ category = provideRandomCategory(), lang = "en" }) {
const filtered = jokes.filter((joke) => joke.category === category && joke.langCode === lang);
return filtered.length > 0 ? filtered[Math.floor(Math.random() * filtered.length)] : null;
}
/**
* Retrieves multiple jokes based on the specified category, language, and range.
*
* @param category - The category of jokes to retrieve (defaults to `"programming"`).
* @param lang - The language code for the jokes (defaults to `"en"`).
* @param range - The maximum number of jokes to return (defaults to `10`).
* @returns An array of jokes matching the filters, limited by the given range, or `null` if no jokes are found.
*/
getManyJokes({
category = provideRandomCategory(),
lang = "en",
range = 10
}) {
const filtered = jokes.filter((joke) => joke.category === category && joke.langCode === lang);
return filtered.length > 0 ? filtered.slice(0, range) : null;
}
/**
* Retrieves jokes that contain at least one of the specified keyword tags.
*
* @param tags - An array of keyword tags to match against joke tags.
* @param range - The maximum number of jokes to return (defaults to `10`).
* @returns An array of jokes that match at least one tag, limited by the given range, or `null` if no matches are found.
*/
getJokeByKeyword(tags, range = 10) {
const filtered = jokes.filter((joke) => joke.tags.some((tag) => tags.includes(tag)));
return filtered.length > 0 ? filtered.slice(0, range) : null;
}
/**
* Retrieves a random joke in the specified language.
*
* @param lang - The language code of the joke (defaults to `"en"` for English).
* @returns A joke object in the given language if available, otherwise `null`.
*/
getRandomJoke(lang = "en") {
const filtered = jokes.filter((joke) => joke.langCode === lang);
return filtered.length > 0 ? filtered[Math.floor(Math.random() * filtered.length)] : null;
}
/**
* Retrieves a list of safe jokes based on the specified category, language, and range.
* Safe jokes are filtered using the `filterSafeJokes` utility.
*
* @param category - The category of jokes to retrieve (defaults to `"programming"`).
* @param lang - The language code for the jokes (defaults to `"en"`).
* @param range - The maximum number of safe jokes to return (defaults to `10`).
* @returns An array of safe jokes limited by the given range, or `null` if no safe jokes are found.
*/
getSafeJokes({
category = provideRandomCategory(),
lang = "en",
range = 10
}) {
const filtered = jokes.filter((joke) => joke.category === category && joke.langCode === lang);
const safeJokes = filterSafeJokes_default(filtered);
return safeJokes.length > 0 ? safeJokes.slice(0, range) : null;
}
/**
* Retrieves the list of supported languages.
*
* @returns An array of language objects, each containing a language code and its corresponding name.
*/
getLanguages() {
return langs;
}
/**
* Retrieves the list of available joke categories.
*
* @returns An array of category objects, each containing the category name.
*/
getCategories() {
return categories;
}
};
export {
Joke
};