Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/is-resolvable
Check if a given module ID is resolvable with require()
https://github.com/shinnn/is-resolvable
check javascript module nodejs path require
Last synced: 26 days ago
JSON representation
Check if a given module ID is resolvable with require()
- Host: GitHub
- URL: https://github.com/shinnn/is-resolvable
- Owner: shinnn
- License: isc
- Created: 2015-08-12T09:59:24.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-11-30T18:59:39.000Z (almost 6 years ago)
- Last Synced: 2024-09-20T05:18:27.838Z (about 2 months ago)
- Topics: check, javascript, module, nodejs, path, require
- Language: JavaScript
- Homepage:
- Size: 67.4 KB
- Stars: 16
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# is-resolvable
[![npm version](https://img.shields.io/npm/v/is-resolvable.svg)](https://www.npmjs.com/package/is-resolvable)
[![Build Status](https://travis-ci.org/shinnn/is-resolvable.svg?branch=master)](https://travis-ci.org/shinnn/is-resolvable)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/is-resolvable.svg)](https://coveralls.io/r/shinnn/is-resolvable)A [Node.js](https://nodejs.org/) module to check if a given module ID is resolvable with [`require()`](https://nodejs.org/api/globals.html#globals_require)
```javascript
const isResolvable = require('is-resolvable');isResolvable('fs'); //=> true
isResolvable('path'); //=> true// When ./index.js exists
isResolvable('./index.js') //=> true
isResolvable('./index') //=> true
isResolvable('.') //=> true
```## Installation
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/getting-started/what-is-npm).
```
npm install is-resolvable
```## API
```javascript
const isResolvable = require('is-resolvable');
```### isResolvable(*moduleId* [, *options*])
*moduleId*: `string` (module ID)
*options*: `Object` ([`require.resolve`](https://nodejs.org/api/modules.html#modules_require_resolve_request_options) options)
Return: `boolean`It returns `true` if `require()` can load a file form a given module ID, otherwise `false`.
```javascript
const isResolvable = require('is-resolvable');// When ./foo.json exists
isResolvable('./foo.json'); //=> true
isResolvable('./foo'); //=> trueisResolvable('./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()`.
```javascript
// When ./bar/baz.js existsisResolvable('./baz.js'); //=> false
isResolvable('./baz.js', {paths: ['bar']}); //=> true
```## License
[ISC License](./LICENSE) © 2018 Shinnosuke Watanabe