HasBin
Check whether a binary exists in the PATH
environment variable.
var hasbin = ; // Check if a binary exists;; // Check if all binaries existhasbinall'node' 'npm' { // result === true}; // Check if at least one binary existshasbin; // Find the first available binaryhasbin;
Table Of Contents
Install
Install HasBin with npm:
npm install hasbin
Usage
hasbin(binaryName, callback)
Check whether a binary exists on one of the paths in process.env.PATH
. Calls back with true
if it does.
// ArgumentsbinaryName = Stringcallback = FunctionBoolean
// Example;
hasbin.sync(binaryName)
Synchronous hasbin
.
// ArgumentsbinaryName = Stringreturn Boolean
// Exampleresult = hasbin;
hasbin.all(binaryNames, callback)
Check whether all of a set of binaries exist on one of the paths in process.env.PATH
. Calls back with true
if all of the binaries do. Aliased as hasbin.every
.
// ArgumentsbinaryNames = ArrayStringcallback = FunctionBoolean
// Examplehasbinall'node' 'npm' { // result === true};
hasbin.all.sync(binaryNames)
Synchronous hasbin.all
. Aliased as hasbin.every.sync
.
// ArgumentsbinaryNames = ArrayStringreturn Boolean
// Exampleresult = hasbinall;
hasbin.some(binaryNames, callback)
Check whether at least one of a set of binaries exists on one of the paths in process.env.PATH
. Calls back with true
if at least one of the binaries does. Aliased as hasbin.any
.
// ArgumentsbinaryNames = ArrayStringcallback = FunctionBoolean
// Examplehasbin;
hasbin.some.sync(binaryNames)
Synchronous hasbin.some
. Aliased as hasbin.any.sync
.
// ArgumentsbinaryNames = ArrayStringreturn Boolean
// Exampleresult = hasbinsome;
hasbin.first(binaryNames, callback)
Checks the list of binaryNames
to find the first binary that exists on one of the paths in process.env.PATH
. Calls back with the name of the first matched binary if one exists and false
otherwise.
// ArgumentsbinaryNames = ArrayStringcallback = FunctionString|false
// Examplehasbin;
hasbin.first.sync(binaryNames)
Synchronous hasbin.first
.
// ArgumentsbinaryNames = ArrayStringreturn String|false
// Exampleresult = hasbinfirst;
Contributing
To contribute to HasBin, clone this repo locally and commit your code on a separate branch.
Please write unit tests for your code, and check that everything works by running the following before opening a pull-request:
make ci
License
HasBin is licensed under the MIT license.
Copyright © 2015, Springer Nature