UNPKG

614 BJavaScriptView Raw
1/**
2 * Findout a module
3 * @function findout
4 * @param {string} name - Module name.
5 * @param {object} [options] - Optional settings.
6 * @param {string} [options.cwd=process.cwd()] - Current working directory.
7 * @param {boolean} [options.safe=false] - No throw when not found.
8 * @returns {*} - Resolved module
9 * @throws - Module not found error.
10 */
11
12'use strict'
13
14const resolve = require('./resolve')
15
16/** @lends findout */
17function findout (name, options = {}) {
18 let resolved = resolve(name, options)
19 if (resolved) {
20 return require(resolved)
21 } else {
22 return null
23 }
24}
25
26module.exports = findout