UNPKG

@techmely/utils

Version:

Collection of helpful JavaScript / TypeScript utils

40 lines (33 loc) 728 B
/*! * @techmely/utils * Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com> * MIT Licensed */ // src/getDataPath.ts import path from "path"; // src/readFile.ts import fs from "fs"; function readFile(filePath) { return new Promise((resolve, reject) => { fs.readFile(filePath, "utf8", (error, result) => { if (error) { reject(error); } else { resolve(result); } }); }); } // src/getDataPath.ts async function getDataPath(directoryPath, fileName) { const filePath = path.join(directoryPath, fileName); const fileContent = await readFile(filePath); const data = JSON.parse(fileContent); return { path: filePath, data }; } export { getDataPath };