lhl 6ff0e96ad3 8-4-1 | 1 rok temu | |
---|---|---|
.. | ||
LICENSE | 1 rok temu | |
README.md | 1 rok temu | |
index.js | 1 rok temu | |
package.json | 1 rok temu |
A Node.js module to check if a given module ID is resolvable with require()
const isResolvable = require('is-resolvable');
isResolvable('fs'); //=> true
isResolvable('path'); //=> true
// When ./index.js exists
isResolvable('./index.js') //=> true
isResolvable('./index') //=> true
isResolvable('.') //=> true
npm install is-resolvable
const isResolvable = require('is-resolvable');
moduleId: string
(module ID)
options: Object
(require.resolve
options)
Return: boolean
It returns true
if require()
can load a file form a given module ID, otherwise false
.
const isResolvable = require('is-resolvable');
// When ./foo.json exists
isResolvable('./foo.json'); //=> true
isResolvable('./foo'); //=> true
isResolvable('./foo.js'); //=> false
// When `eslint` module is installed but `jshint` isn't
isResolvable('eslint'); //=> true
isResolvable('jshint'); //=> false
// When `lodash` module is installed
isResolvable('lodash/isObject'); //=> true
isResolvable('lodash/fp/reject.js'); //=> true
The second argument accepts an options object for require.resolve()
.
// When ./bar/baz.js exists
isResolvable('./baz.js'); //=> false
isResolvable('./baz.js', {paths: ['bar']}); //=> true
ISC License © 2018 Shinnosuke Watanabe