Name Last Update
..
LICENSE Loading commit data...
README.md Loading commit data...
index.js Loading commit data...
package.json Loading commit data...

is-resolvable

NPM version Build Status Build status Coverage Status Dependency Status devDependency Status

A Node module to check if a 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

Installation

Use npm.

npm install is-resolvable

API

const isResolvable = require('is-resolvable');

isResolvable(moduleId)

moduleId: String (module ID)
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 `lodash` module is installed but `underscore` isn't
isResolvable('lodash'); //=> true
isResolvable('underscore'); //=> false

// When `readable-stream` module is installed
isResolvable('readable-stream/readable'); //=> true
isResolvable('readable-stream/writable'); //=> true

License

Copyright (c) 2014 - 2015 Shinnosuke Watanabe

Licensed under the MIT License.