【发布时间】:2019-12-09 23:30:51
【问题描述】:
在给定以下文件夹结构的情况下,我希望能够通过将 startingPoint.txt 的路径传递给 Node JS 中的函数来找到 target.json:
- root
- sub1
- sub2
startingPoint.txt
target.json
我为它找到了一个名为 find-up 的节点包,但这种东西可能只需要 6 行代码。
export function findUp(start: Path, target: string): Path | undefined {
// this code here
}
const pathToTarget = findUp("root/sub1/sub2/startingPoint.txt", "target.json"/);
console.log(pathToTarget); // "root/target.json"
【问题讨论】: