UNPKG

word-vault

Version:

A lightweight JavaScript package for English word definitions and collections.

20 lines (19 loc) 578 B
Object.defineProperty(exports, "__esModule", { value: true }); exports.findWord = findWord; const fs = require("node:fs"); const path = require("node:path"); const const_1 = require("../const"); function findWord(id) { const filePath = path.join(const_1.baseWordPath, `${id}.json`); if (!fs.existsSync(filePath)) { console.error(`Word with slug "${id}" does not exist.`); return null; } try { const data = fs.readFileSync(filePath, "utf-8"); return JSON.parse(data); } catch (error) { console.error(`Error reading file for ID: ${id}`, error); return null; } }