isrequirable

0.0.3 • Public • Published

isrequirable

NPM version Build Status Dependency Status

Node.JS utility function for returning a boolean if a module can be called via require().

Node has a function require.resolve() which returns the path of a module without loading it. However, it throws an error if the module is not found. There are cases when I don't want node to throw an error and this utility function is the solution. Just sharing it in case anyone finds it useful.

Installation

npm install isrequirable

Usage

var isrequirable = require('isrequirable');
 
if (isrequirable('async')) {
    var async = require('async');
} else {
    console.log('Cannot require async.');
}

License

Copyright (c) 2014, Hyubs Ursua hyubs.u@gmail.com

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Readme

Keywords

Package Sidebar

Install

npm i isrequirable

Weekly Downloads

1

Version

0.0.3

License

ISC

Last publish

Collaborators

  • hyubs