recursive-path-finder

1.0.4 • Public • Published

recursive-path-finder

Build Status

Search for files or folders in the directory where Node was started.

Install

Install locally:

npm install recursive-path-finder

Install globally:

npm install -g recursive-path-finder

Usage

Simply import the package and use it as a function:

var find = require('recursive-path-finder');
var path = find('login.js');

find(filename, [options])

Find a file or folder using the filename parameter with an optional options object. It starts on the directory where Node was started and search recursively for the file or folder. It will return a string with the full path of the file in the file system or undefined if it didn't find anything.

This method runs synchronously.

Avaliable properties for options:

  • basePath: Adds a path to the main path to search for files or folders.
  • isFolder: Change the kind of source to find. The default is false.
  • exclude: A list of folders to exclude from the search.
var find = require('recursive-path-finder');
 
console.log(find('login.test.js'))
// /Users/name/projects/awesome_project/tests/login.test.js
 
console.log(find('login.js', { basePath: 'source/v1' })
// /Users/name/projects/awesome_project/source/v1/login.js
console.log(find('login.js', { basePath: 'source/v2' })
// /Users/name/projects/awesome_project/source/v2/login.js
 
console.log(find('v2', { isFolder: true })
// /Users/name/projects/awesome_project/source/v2
 
console.log(find('login.js', { exclude: ['source/v1'] })
// /Users/name/projects/awesome_project/source/v2/login.js

License

MIT License

Copyright (c) 2019 Ricardo Rauber Pereira

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package Sidebar

Install

npm i recursive-path-finder

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

11.4 kB

Total Files

9

Last publish

Collaborators

  • ricardorauber