source: trip-planner-front/node_modules/is-resolvable/README.md@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.2 KB
Line 
1# is-resolvable
2
3[![npm version](https://img.shields.io/npm/v/is-resolvable.svg)](https://www.npmjs.com/package/is-resolvable)
4[![Build Status](https://travis-ci.org/shinnn/is-resolvable.svg?branch=master)](https://travis-ci.org/shinnn/is-resolvable)
5[![Build status](https://ci.appveyor.com/api/projects/status/ww1cdpignehlasbs?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/is-resolvable)
6[![Coverage Status](https://img.shields.io/coveralls/shinnn/is-resolvable.svg)](https://coveralls.io/r/shinnn/is-resolvable)
7
8A [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)
9
10```javascript
11const isResolvable = require('is-resolvable');
12
13isResolvable('fs'); //=> true
14isResolvable('path'); //=> true
15
16// When ./index.js exists
17isResolvable('./index.js') //=> true
18isResolvable('./index') //=> true
19isResolvable('.') //=> true
20```
21
22## Installation
23
24[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/getting-started/what-is-npm).
25
26```
27npm install is-resolvable
28```
29
30## API
31
32```javascript
33const isResolvable = require('is-resolvable');
34```
35
36### isResolvable(*moduleId* [, *options*])
37
38*moduleId*: `string` (module ID)
39*options*: `Object` ([`require.resolve`](https://nodejs.org/api/modules.html#modules_require_resolve_request_options) options)
40Return: `boolean`
41
42It returns `true` if `require()` can load a file form a given module ID, otherwise `false`.
43
44```javascript
45const isResolvable = require('is-resolvable');
46
47// When ./foo.json exists
48isResolvable('./foo.json'); //=> true
49isResolvable('./foo'); //=> true
50
51isResolvable('./foo.js'); //=> false
52
53// When `eslint` module is installed but `jshint` isn't
54isResolvable('eslint'); //=> true
55isResolvable('jshint'); //=> false
56
57// When `lodash` module is installed
58isResolvable('lodash/isObject'); //=> true
59isResolvable('lodash/fp/reject.js'); //=> true
60```
61
62The second argument accepts an options object for `require.resolve()`.
63
64```javascript
65// When ./bar/baz.js exists
66
67isResolvable('./baz.js'); //=> false
68isResolvable('./baz.js', {paths: ['bar']}); //=> true
69```
70
71## License
72
73[ISC License](./LICENSE) © 2018 Shinnosuke Watanabe
Note: See TracBrowser for help on using the repository browser.