UNPKG

word-vault

Version:

A lightweight JavaScript package for English word definitions and collections.

22 lines (21 loc) 660 B
import { getAllCollections } from "./getAllCollections.js"; /** * Search for a word across all collections. * * @param word - The word to search for * @returns Array of collection slugs where the word appears */ export function searchWordInCollections(word) { const allCollections = getAllCollections(); if (!allCollections) { return null; } const results = []; for (const collection of allCollections) { const found = collection.categories.some((category) => category.cards.some((lesson) => lesson.includes(word))); if (found) { results.push(collection.slug); } } return results; }