UNPKG

@techmely/utils

Version:

Collection of helpful JavaScript / TypeScript utils

31 lines (27 loc) 723 B
/*! * @techmely/utils * Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com> * MIT Licensed */ import { getDataPath } from "./chunk-QUUMHGGA.mjs"; import "./chunk-YCYRHAJ6.mjs"; import "./chunk-NYLAFCGV.mjs"; // 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 };