resolves

1.0.0 • Public • Published

resolves

Resolves is a small utility that will resolve the parent folder of the supplied root until the iterator function returns a given value.

Installation

npm install --save resolves

Usage

var resolves = require('resolves');
var path = require('path');
var fs = require('fs');
 
var gitignore = resolves(process.cwd(), function next(dir) {
  var ignore = path.join(dir, '.gitignore');
 
  if (fs.existsSync(ignore)) return fs.readFileSync(ignore, 'utf-8');
});

As seen in the snippet above, the resolve method requires 2 arguments:

  • dir The initial directory that we start resolving in.
  • iteractor A function that is called for every directory until it returns a value that can be returned. This includes the directory you initially provided.

If the iterator does not find anything, it will keep iterating until it reaches the root folder.

License

MIT

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i resolves

      Weekly Downloads

      50

      Version

      1.0.0

      License

      MIT

      Unpacked Size

      2.57 kB

      Total Files

      3

      Last publish

      Collaborators

      • 3rdeden