findout

2019-06-23 admin

findout是什么

什么是findout,Find out a module.

findout使用教程帮助文档

findout

<a name=“user-content-badges”></a>

Build Status Code Climate Code Coverage npm Version JS Standard

<a name=“user-content-description”></a>

Find out a module.

<a name=“user-content-sections”></a>

<a name=“user-content-section-doc-guides-01-installation-md”></a>

Installation

npm install findout --save

<a name=“user-content-section-doc-guides-02-usage-md”></a>

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.
})

<a name=“user-content-section-doc-guides-03-how-md”></a>

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.

<a name=“user-content-section-doc-guides-04-options-md”></a>

Options

Key Type Default Description
cwd string process.cwd() Working directory path.
safe boolean false No throw when not found.

<a name=“user-content-license”></a>

License

This software is released under the MIT License.

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-67952.html

文章标题:findout

回到顶部