UNPKG

@techmely/utils

Version:

Collection of helpful JavaScript / TypeScript utils

29 lines (25 loc) 660 B
/*! * @techmely/utils * Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com> * MIT Licensed */ import { getDataPath } from "./chunk-TLUUQXZW.js"; // src/findNearestFile.ts import path from "path"; async function findNearestFile(fileName, directoryPath = path.resolve()) { try { const data = await getDataPath(directoryPath, fileName); return data; } catch (error) { const parentDirectoryPath = path.dirname(directoryPath); if (parentDirectoryPath === directoryPath) { throw new Error(`No ${fileName} files found`); } return findNearestFile(parentDirectoryPath, fileName); } } export { findNearestFile };