3.0.2 • Published 5 years ago

findout v3.0.2

Weekly downloads
4,151
License
MIT
Repository
github
Last release
5 years ago

findout

Build Status Code Climate Code Coverage npm Version JS Standard

Find out a module.

Installation

npm install findout --save

Usage

findout(name) works like require(), but has a lot more locations to search.

'use strict'

const findout = require('findout')

// Resolve a module path.
let pathOfFoo = findout.resolve('foo')

// Find and require a module.
let foo = findout('foo', {
  cwd: __dirname // Lookup from current directory.
})

How It Works

When you call findout for "foo" with '/bar/baz' as current working directory:

findout('foo', {
  cwd: '/bar/baz'
})

and it will try the following ways,

  1. require('foo')
  2. require('/bar/baz/foo')
  3. require('/bar/baz/node_modules/foo')
  4. require('/bar/foo')
  5. require('/bar/node_modules/foo')
  6. require('/foo')
  7. require('/node_modules/foo')

If it still can't find any, throws an error.

Options

KeyTypeDefaultDescription
cwdstringprocess.cwd()Working directory path.
safebooleanfalseNo throw when not found.

License

This software is released under the MIT License.