npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hasbin

v1.2.3

Published

Check whether a binary exists in the PATH environment variable

Downloads

766,929

Readme

HasBin

Check whether a binary exists in the PATH environment variable.

NPM version Node.js version support Build status Dependencies MIT licensed

var hasbin = require('hasbin');

// Check if a binary exists
hasbin('node', function (result) {
    // result === true
});
hasbin('wtf', function (result) {
    // result === false
});

// Check if all binaries exist
hasbin.all(['node', 'npm'], function (result) {
    // result === true
});

// Check if at least one binary exists
hasbin.some(['node', 'wtf'], function (result) {
    // result === true
});

// Find the first available binary
hasbin.first(['node', 'npm'], function (result) {
    // result === 'node'
});

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.

// Arguments
binaryName = String
callback = Function(Boolean)
// Example
hasbin('node', function (result) {
    // result === true
});

hasbin.sync(binaryName)

Synchronous hasbin.

// Arguments
binaryName = String
return Boolean
// Example
result = hasbin.sync('node');

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.

// Arguments
binaryNames = Array(String)
callback = Function(Boolean)
// Example
hasbin.all(['node', 'npm'], function (result) {
    // result === true
});

hasbin.all.sync(binaryNames)

Synchronous hasbin.all. Aliased as hasbin.every.sync.

// Arguments
binaryNames = Array(String)
return Boolean
// Example
result = hasbin.all.sync(['node', 'npm']);

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.

// Arguments
binaryNames = Array(String)
callback = Function(Boolean)
// Example
hasbin.some(['node', 'npm'], function (result) {
    // result === true
});

hasbin.some.sync(binaryNames)

Synchronous hasbin.some. Aliased as hasbin.any.sync.

// Arguments
binaryNames = Array(String)
return Boolean
// Example
result = hasbin.some.sync(['node', 'npm']);

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.

// Arguments
binaryNames = Array(String)
callback = Function(String|false)
// Example
hasbin.first(['node', 'npm'], function (result) {
    // result === 'node'
});

hasbin.first.sync(binaryNames)

Synchronous hasbin.first.

// Arguments
binaryNames = Array(String)
return String|false
// Example
result = hasbin.first.sync(['node', 'npm']);

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