walk-back

Walk up the directory tree until the specified path is found.

MIT 14 个版本
安装
npm install walk-back
yarn add walk-back
pnpm add walk-back
bun add walk-back
README

view on npm npm module downloads Gihub repo dependents Gihub package dependents Node.js CI

walk-back

Walk up the directory tree until the specified path is found. For example, starting from the current directory, you might want to walk up the directory tree until a specified config file is found.

Example

import walkBack from 'walk-back'

walkBack(startAt, lookingFor) ⇒ string

Returns an absolute file path (if found) else null.

Kind: Exported function

Param Type Description
startAt string the directory to start in
lookingFor string the path we're looking for

Example

> walkBack('/Users/lloyd/Documents/75lb/walk-back', 'package.json')
'/Users/lloyd/Documents/75lb/walk-back/package.json'

> walkBack('/Users/lloyd/Documents/75lb/walk-back', '75lb')
'/Users/lloyd/Documents/75lb'

> walkBack('/Users/lloyd/Documents/75lb/walk-back', '.bash_profile')
'/Users/lloyd/.bash_profile'

> walkBack('.', '.bash_profile')
'/Users/lloyd/.bash_profile'

> walkBack('/Users/lloyd/Documents/75lb/walk-back', 'non-existent.file')
null

© 2015-26 Lloyd Brookes <opensource@75lb.com>.

Tested by test-runner. Documented by jsdoc-to-markdown.

版本列表
5.1.2 2026-03-07
5.1.1 2024-08-23
5.1.0 2021-08-18
5.0.0 2021-02-26
4.0.0 2019-11-06
3.0.1 2018-12-24
3.0.0 2017-03-19
2.0.1 2016-05-25
2.0.0 2016-05-24
1.1.1 2016-02-26
1.1.0 2016-01-22
1.0.1 2015-11-11
1.0.0 2015-11-11
0.1.1 2015-09-20