UNPKG

3.6 kBMarkdownView Raw
1findout
2==========
3
4<!---
5This file is generated by ape-tmpl. Do not update manually.
6--->
7
8<!-- Badge Start -->
9<a name="badges"></a>
10
11[![Build Status][bd_travis_shield_url]][bd_travis_url]
12[![Code Climate][bd_codeclimate_shield_url]][bd_codeclimate_url]
13[![Code Coverage][bd_codeclimate_coverage_shield_url]][bd_codeclimate_url]
14[![npm Version][bd_npm_shield_url]][bd_npm_url]
15[![JS Standard][bd_standard_shield_url]][bd_standard_url]
16
17[bd_repo_url]: https://github.com/okunishinishi/node-findout
18[bd_travis_url]: http://travis-ci.org/okunishinishi/node-findout
19[bd_travis_shield_url]: http://img.shields.io/travis/okunishinishi/node-findout.svg?style=flat
20[bd_license_url]: https://github.com/okunishinishi/node-findout/blob/master/LICENSE
21[bd_codeclimate_url]: http://codeclimate.com/github/okunishinishi/node-findout
22[bd_codeclimate_shield_url]: http://img.shields.io/codeclimate/github/okunishinishi/node-findout.svg?style=flat
23[bd_codeclimate_coverage_shield_url]: http://img.shields.io/codeclimate/coverage/github/okunishinishi/node-findout.svg?style=flat
24[bd_gemnasium_url]: https://gemnasium.com/okunishinishi/node-findout
25[bd_gemnasium_shield_url]: https://gemnasium.com/okunishinishi/node-findout.svg
26[bd_npm_url]: http://www.npmjs.org/package/findout
27[bd_npm_shield_url]: http://img.shields.io/npm/v/findout.svg?style=flat
28[bd_standard_url]: http://standardjs.com/
29[bd_standard_shield_url]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg
30
31<!-- Badge End -->
32
33
34<!-- Description Start -->
35<a name="description"></a>
36
37Find out a module.
38
39<!-- Description End -->
40
41
42
43
44<!-- Sections Start -->
45<a name="sections"></a>
46
47<!-- Section from "doc/readme/01.Installation.md.hbs" Start -->
48
49<a name="section-doc-readme-01-installation-md"></a>
50Installation
51-----
52
53```bash
54npm install findout --save
55```
56
57
58<!-- Section from "doc/readme/01.Installation.md.hbs" End -->
59
60<!-- Section from "doc/readme/02.Usage.md.hbs" Start -->
61
62<a name="section-doc-readme-02-usage-md"></a>
63Usage
64----
65
66`findout(name)` works like `require()`, but has a lot more locations to search.
67
68
69```javascript
70'use strict'
71
72const findout = require('findout')
73
74// Resolve a module path.
75let pathOfFoo = findout.resolve('foo')
76
77// Find and require a module.
78let foo = findout('foo', {
79 cwd: __dirname // Lookup from current directory.
80})
81
82
83```
84
85
86<!-- Section from "doc/readme/02.Usage.md.hbs" End -->
87
88<!-- Section from "doc/readme/03.How.md.hbs" Start -->
89
90<a name="section-doc-readme-03-how-md"></a>
91How It Works
92------------
93
94When you call `findout` for "foo" with '/bar/baz' as current working directory:
95
96```javascript
97findout('foo', {
98cwd: '/bar/baz';
99});
100```
101
102and it will try the following ways,
103
1041. `require('foo')`
1052. `require('/bar/baz/foo')`
1063. `require('/bar/baz/node_modules/foo')`
1074. `require('/bar/foo')`
1085. `require('/bar/node_modules/foo')`
1096. `require('/foo')`
1107. `require('/node_modules/foo')`
111
112If it still can't find any, throws an error.
113
114
115<!-- Section from "doc/readme/03.How.md.hbs" End -->
116
117<!-- Section from "doc/readme/04.Options.md.hbs" Start -->
118
119<a name="section-doc-readme-04-options-md"></a>
120Options
121-------
122
123| Key | Type | Default | Description |
124| --- | --- | --- | --- |
125| cwd | string | process.cwd() | Working directory path. |
126| safe | boolean | false | No throw when not found. |
127
128<!-- Section from "doc/readme/04.Options.md.hbs" End -->
129
130
131<!-- Sections Start -->
132
133
134<!-- LICENSE Start -->
135<a name="license"></a>
136
137License
138-------
139This software is released under the [MIT License](https://github.com/okunishinishi/node-findout/blob/master/LICENSE).
140
141<!-- LICENSE End -->
142
143