What is is-resolvable?
The is-resolvable npm package is a utility that checks if a module ID (a string) can be resolved to a valid module using Node.js' resolution algorithm. This can be useful for determining if a module is available for use without actually requiring it.
What are is-resolvable's main functionalities?
Check if a module is resolvable
This feature allows you to check if a given module ID can be resolved to a valid module. It returns true if the module can be resolved and false otherwise.
const isResolvable = require('is-resolvable');
console.log(isResolvable('express')); // true if 'express' is installed
console.log(isResolvable('./local-module')); // true if './local-module' exists
Other packages similar to is-resolvable
resolve
The resolve package provides a synchronous and asynchronous method to resolve a module path as Node.js does. It offers more detailed control over the resolution process compared to is-resolvable, including custom module directories and file extensions.
require-resolve
The require-resolve package is similar to is-resolvable but also provides the full path to the resolved module. It can be used to check if a module is resolvable and to get the path to the module if it is.
module-exists
The module-exists package checks if a module exists and can be required. It is similar to is-resolvable but focuses on the existence check rather than the resolution process.
is-resolvable
A Node.js module to check if a given module ID is resolvable with require()
const isResolvable = require('is-resolvable');
isResolvable('fs');
isResolvable('path');
isResolvable('./index.js')
isResolvable('./index')
isResolvable('.')
Installation
Use npm.
npm install is-resolvable
API
const isResolvable = require('is-resolvable');
isResolvable(moduleId [, options])
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');
isResolvable('./foo.json');
isResolvable('./foo');
isResolvable('./foo.js');
isResolvable('eslint');
isResolvable('jshint');
isResolvable('lodash/isObject');
isResolvable('lodash/fp/reject.js');
The second argument accepts an options object for require.resolve()
.
isResolvable('./baz.js');
isResolvable('./baz.js', {paths: ['bar']});
License
ISC License © 2018 Shinnosuke Watanabe